-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
51 lines (41 loc) · 1.32 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
var _ = require('lodash');
var Controller = require('./lib/Controller.js');
var HttpClient = require('./lib/HttpClient.js');
function TMRestClient(userName, apiKey, options) {
var defaults = {
host: 'rest.textmagic.com',
version: 'v2',
agent: 'textmagic-rest-nodejs/0.02',
language: 'en;q=1',
webpack:false
};
if (!userName || !apiKey) {
throw ('No username or token supplied.');
}
this.options = _.assign(defaults, options);
var httpOptions = {
hostname: this.options.host,
port: 443,
path: '/api/' + this.options.version + '/',
method: 'GET',
headers : {
'user-agent': this.options.agent,
'accept-language': this.options.language,
'x-tm-key': apiKey,
'x-tm-username': userName
}
};
var http = new HttpClient(httpOptions);
if (this.options.webpack) {
var a = new Controller(http, require('./resources/webpack.js'), this, true);
} else {
var a = new Controller(http, require('./resources/index.js'), this, false);
}
}
TMRestClient.prototype.host = function () {
return 'https://' + this.options.host ;
};
module.exports = TMRestClient;
module.exports.auth = function(userName, apiKey) {
return new TMRestClient(userName, apiKey);
};