-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (46 loc) · 1.19 KB
/
index.js
File metadata and controls
59 lines (46 loc) · 1.19 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var request = require('request');
function Semaphore(apikey) {
if (!(this instanceof Semaphore)) {
return new Semaphore();
}
// Set the headers
var headers = {
'User-Agent' : 'Semaphore SMS/1.0.0.',
'Content-Type' : 'application/x-www-form-urlencoded'
}
this.headers = headers;
this.apikey = apikey;
this.endpoint = "http://www.semaphore.co";
};
Semaphore.prototype.sendsms = function sendsms(sms, callback) {
var data = {
sendername: sms.sendername,
apikey: this.apikey,
number: sms.number,
message: sms.message
}
var options = {
url: this.endpoint + '/api/v4/messages',
method: 'POST',
headers: this.headers,
form: data
}
sendRequest(options, callback);
};
Semaphore.prototype.account = function account(callback) {
var options = {
url: this.endpoint + '/api/v4/account?apikey=' + this.apikey,
method: 'GET'
}
sendRequest(options, callback);
};
function sendRequest(options, callback) {
function handleResponse(error, response, body) {
if (!error && response.statusCode == 200) {
return callback(null, body);
}
return callback(error);
}
request(options, handleResponse);
}
module.exports = Semaphore;