-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (54 loc) · 1.67 KB
/
index.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
/**
* Spray API Client Utility for Node.JS v6+
*
* Licensed under GPLv3.0
*/
const API_VERSION = '2.0.0';
const Promise = require('bluebird');
const SprayLib = require('./lib');
class SprayClient {
constructor(options) {
this.options = options || {};
if(!this.options.apiKey) {
throw "SecurityError: You must specify an API key to use this API !";
}
this.options.apiVersion = this.options.apiVersion || API_VERSION;
this.options.promised = (this.options.promised === undefined ? true : this.options.promised);
}
login(callback) {
let request = new SprayLib.SprayRequest('post', 'user/login', {
'Application-Key': this.options.apiKey,
'API-Version': this.options.apiVersion
});
return request.run().then(data => {
if (!this.options.promised) {
callback(null, data);
}
return data;
}).catch(err => {
if (!this.options.promised) {
callback(err);
}
throw err;
});
}
info(token, callback) {
let request = new SprayLib.SprayRequest('get', 'user/get', {
'Application-Key': this.options.apiKey,
'API-Version': this.options.apiVersion,
'Authentication-Token': token
});
return request.run().then(data => {
if (!this.options.promised) {
callback(null, data);
}
return data;
}).catch(err => {
if (!this.options.promised) {
callback(err);
}
throw err;
});
}
}
module.exports = SprayClient;