-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
36 lines (32 loc) · 1.1 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
var http = require('http');
module.exports = function(zenvia) {
var host = 'api-rest.zenvia.com';
var headers = {
"Authorization": "Basic " + new Buffer(zenvia.username + ":" + zenvia.password, "utf8").toString("base64"),
"Accept": "application/json",
"Content-type": "application/json"
};
return {
sendSms: function(body) {
return new Promise(function(resolve, reject) {
http.request({
host: host,
path: "/services/send-sms",
method: "POST",
headers: headers
}, function(response) {
var body = '';
response.on('data', function(d) {
body += d;
});
response.on('end', function() {
resolve(body);
});
response.on('error', function(err) {
reject(err);
});
}).end(JSON.stringify(body));
});
}
};
};