-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
34 lines (28 loc) · 1.18 KB
/
test.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
var PooledTokenInterceptor = require("./index");
var Q = require("q");
var options = {
url: 'https://api.github.com/search/repositories?q=Material+language:Java&sort=stars&order=desc',
headers: {
'User-Agent': 'request'
}
}
var tokenConfig = {
tokenLocation : 'header', //or 'query'
tokenIdentifier : 'Token', // or whatever the API requires.
tokens : ['9a2b71d92c9053e913030f0b2bd92e83fcd439f5'],
failureResponseCode : 403, // Default to 403. This is used by the module to check if the request failed. Check what the API being used with send back.
headerLimitResetVar : 'x-ratelimit-reset' // Paramter name in the response header that holds then time when the limit will be reset
};
var request = new PooledTokenInterceptor(tokenConfig);
var promisesArray = [];
// Collect promised for each of the requests to the API
for(var i = 0; i < 35; i++){
promisesArray.push(request.authenticatedRequest(options, 'FOK'));
}
// Wait for the promised to resolve and print out the statusCode for each of them
Q.all(promisesArray).then(function(responses){
console.log("Number of responses: " + responses.length);
for(var i = 0; i < responses.length; i++){
console.log(responses[i].statusCode);
}
})