-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgoogle-plus.js
75 lines (61 loc) · 1.69 KB
/
google-plus.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
'use strict';
var _ = require('lodash');
var moment = require('moment');
var Manager = require('../manager.js');
/**
* Quota Preset for Google+
*
* Quota rules based on: https://developers.google.com/+/web/api/rest/#quota
* Google+ API docs: https://developers.google.com/+/api/
*
* In a cluster environment a local Server can be used if all requests on
* behalf a particular user are only made by a single node.js instance and the
* overall daily limits are unlikely to be reached.
*
* @param options
* @returns {Manager}
*/
module.exports = function (options) {
// Note: Daily quotas refresh at midnight PST.
function getStartOfNextWindow() {
return moment.utc().startOf('day').add(1, 'day').add(8, 'hours').valueOf();
}
var manager = new Manager({
backoff: 'timeout'
});
// Google+ API (Sign-in)
manager.addRule({
limit: 20000000,
throttling: {
type: 'window-fixed',
getStartOfNextWindow: getStartOfNextWindow
},
resource: 'signInRequests'
});
manager.addRule({
limit: 5,
window: 1000,
throttling: 'window-sliding',
queueing: 'fifo',
scope: 'userId',
resource: 'signInRequests'
});
// Google+ API - For all other methods.
manager.addRule({
limit: 10000,
throttling: {
type: 'window-fixed',
getStartOfNextWindow: getStartOfNextWindow
},
resource: 'requests'
});
manager.addRule({
limit: 5,
window: 1000,
throttling: 'window-sliding',
queueing: 'fifo',
scope: 'userId',
resource: 'requests'
});
return manager;
};