google-translate-api-nodejs-client
Advanced tools
Comparing version 1.0.2 to 1.0.3
var request = require('request'), | ||
Logger = require('logb').getLogger(module.filename), | ||
Entities = require('html-entities').AllHtmlEntities, | ||
entities = new Entities(); | ||
entities = new Entities(), | ||
RateLimiter = require('limiter').RateLimiter; | ||
@@ -11,6 +12,19 @@ | ||
var GoogleTranslateApi = module.exports = function GoogleTranslateApi(options) { | ||
// credentials | ||
this.API_KEY = options.API_KEY; | ||
this.URL = 'https://www.googleapis.com/language/translate/v2'; | ||
// throttling | ||
this.limiter = new RateLimiter(100, 'second'); | ||
Logger.info('Using API_KEY', this.API_KEY); | ||
}; | ||
GoogleTranslateApi.prototype.translate = function(opts, cb) { | ||
var self = this; | ||
self.limiter.removeTokens(1, function() { | ||
self._translate(opts, cb); | ||
}); | ||
} | ||
GoogleTranslateApi.prototype.translate = function translate(opts, cb) { | ||
GoogleTranslateApi.prototype._translate = function translate(opts, cb) { | ||
var self = this; | ||
@@ -41,2 +55,7 @@ | ||
if (!body.data || !body.data.translations) { | ||
Logger.warn('response from Google Translate API returned weird body', body); | ||
return cb(new Error('Weird response from Google Translate API')); | ||
} | ||
translation = body.data.translations[0].translatedText; | ||
@@ -43,0 +62,0 @@ translation = entities.decode(translation); |
{ | ||
"name": "google-translate-api-nodejs-client", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "", | ||
@@ -13,2 +13,3 @@ "main": "google-translate-api-nodejs-client.js", | ||
"html-entities": "^1.1.2", | ||
"limiter": "^1.0.5", | ||
"logb": "0.0.2", | ||
@@ -20,6 +21,6 @@ "request": "^2.53.0" | ||
}, | ||
"repository":{ | ||
"type":"git", | ||
"url":"git@github.com:bitliner/google-translate-api-nodejs-client.git" | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:bitliner/google-translate-api-nodejs-client.git" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5307
96
4
+ Addedlimiter@^1.0.5
+ Addedlimiter@1.1.5(transitive)