Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
15 changes: 15 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ Here are some examples *hint* replace xxxxxxxxxxx with real key::
});
});

new embedly({key: EMBEDLY_KEY, rateLimits: { extract: 10 }}, function(err, api) {
var url = ('http://www.guardian.co.uk/media/2011/jan' +
'/21/andy-coulson-phone-hacking-statement');
api.extract({url: url}, function(err, objs) {
if (!!err) {
console.error('request #3 failed');
console.error(err.stack, objs);
return;
}
console.log('---------------------------------------------------------');
console.log('4. ');
console.log(util.inspect(objs[0]));
});
});

Authentication
^^^^^^^^^^^^^^

Expand Down
19 changes: 18 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var bb = require('batbelt'),
hashish = require('hashish'),
querystring = require('querystring');

var TimeQueue = require('timequeue');

function defaultLogger() {
try {
var winston = require('winston')
Expand Down Expand Up @@ -36,6 +38,10 @@ function defaultLogger() {
//
// **secure** _Boolean_ Enables ssl
//
// **rateLimits** _Object_ An object that is used to provide rate limits for
// each api call. Possible keys are objectify, oembed, preview,
// and extract. By default they are set to _Infinity_.
//
// **logger** _Object_ An object that has debug, warn and error functions that
// except a single _String_ parameter. The `log` module is used by
// default.
Expand All @@ -53,6 +59,7 @@ function embedly(opts, callback) {
preview: 1,
extract: 1
},
rateLimits: {},
timeout: 200000,
protocol: false,
logger: null,
Expand All @@ -65,11 +72,21 @@ function embedly(opts, callback) {

var self = this;
hashish(this.config.apiVersion).forEach(function(version, action) {
var rateLimit = self.config.rateLimits[action];

var q = new TimeQueue(function () {
embedly.prototype.apiCall.apply(self, arguments);
}, {
concurrency: rateLimit || Infinity,
every: 1000
});

self[action] = function() {
var args = Array.prototype.slice.call(arguments, 0);
args.unshift(version);
args.unshift(action);
return embedly.prototype.apiCall.apply(self, args);

return q.push.apply(q, args);
};
});

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
},
"dependencies": {
"batbelt": "0.0.2",
"superagent": "0.21.0",
"hashish": "0.0.4",
"sprintf": "0.1.1",
"hashish": "0.0.4"
"superagent": "0.21.0",
"timequeue": "^0.2.2"
},
"devDependencies": {
"mocha": "1.8.2",
Expand Down