-
Notifications
You must be signed in to change notification settings - Fork 7
/
bitly.js
45 lines (36 loc) · 1.07 KB
/
bitly.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict';
var Manager = require('../manager.js');
var _ = require('lodash');
/**
* Quota Preset for Bitly
*
* Quota rules based on: http://dev.bitly.com/rate_limiting.html
* Bitly API docs: http://dev.bitly.com/api.html
*
* In a cluster environment a local Server can be used if each node.js instance
* is reached via a different IP address from the internet.
*
* @param options
* @returns {Manager}
*/
module.exports = function (options) {
_.defaults(options, {
concurrentRequests: 5,
sharedIPAddress: false
});
var manager = new Manager({
backoff: 'timeout' // If you are experiencing rate limiting errors, please wait 60 minutes to resume making API calls.
});
// five concurrent connections from a single IP address
var ruleOptions = {
limit: options.concurrentRequests,
throttling: 'limit-concurrency',
queueing: 'fifo',
resource: 'requests'
};
if (options.sharedIPAddress) {
ruleOptions.scope = 'ipAddress';
}
manager.addRule(ruleOptions);
return manager;
};