-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (34 loc) · 1.16 KB
/
index.js
File metadata and controls
44 lines (34 loc) · 1.16 KB
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
require('request').debug = true;
const request = require('request-promise-native');
const baseUrl = 'https://api.sharedcount.com/v1.0';
const addHttpToUrl = url => (url.includes('http') ? url : `http://${url}`);
const makeRequest = apikey => ({
path = '', queryParams = {}, body, method = 'GET',
}) => request({
url: `${baseUrl}${path}`,
method,
json: true,
qs: { apikey, ...queryParams },
body,
});
const Sharedcount = function Sharedcount(options = {}) {
this.apikey = options.apikey || process.env.SHAREDCOUNT_API_KEY;
this.makeRequest = makeRequest(this.apikey);
return this;
};
Sharedcount.prototype.url = function urlInfo(url) {
return this.makeRequest({ queryParams: { url: addHttpToUrl(url) } });
};
Sharedcount.prototype.domainWhitelist = function status() {
return this.makeRequest({ path: '/domain_whitelist' });
};
Sharedcount.prototype.usage = function usage() {
return this.makeRequest({ path: '/usage' });
};
Sharedcount.prototype.quota = function usage() {
return this.makeRequest({ path: '/quota' });
};
Sharedcount.prototype.status = function status() {
return this.makeRequest({ path: '/status' });
};
module.exports = Sharedcount;