-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbusiness.js
62 lines (57 loc) · 1.96 KB
/
business.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
60
61
62
var request = require('request');
var config = require('./config');
function manageOrder(userID, order, callback) {
console.log('User with ' + userID + ', ordered : ' + JSON.stringify(order));
callback(204, null);
}
function sendOffer(offer, callback) {
var scheduleTime = new Date("2013-10-13 17:30:00").getTime();
var shapedOffer = {
"foodList" : [
{ "id" : "1", "name" : offer.name, "price" : offer.price}
],
"offerID" : "fwdcd123"
};
var messageBody = {
sentType : "channels",
mimeType : "text/plain",
OSTypes : ["Android"],
channelNames : ['Kod Ruže'],
androidData : {title : offer.restaurantName},
expiryOffset : 6 * 60 * 60,
scheduleTime : scheduleTime,
notificationMessage : JSON.stringify(shapedOffer)
};
var options = {
url : 'https://pushapi.infobip.com/3/application/' + config.applicationID + '/scheduleMessage',
method : 'POST',
json : true,
headers : {Authorization : config.pushAuthorization},
body : messageBody
};
request(options, function (error, response, body) {
if (error || response.statusCode !== 200 || !body) {
callback(500, body);
return;
}
callback(200, body);
});
}
function getAllAvailableChannels(callback) {
var options = {
url : 'https://pushapi.infobip.com/1/application/' + config.applicationID + '/channels',
method : 'GET',
json : true,
headers : {Authorization : config.pushAuthorization}
};
request(options, function (error, response, body) {
if (error || response.statusCode !== 200) {
callback(500, body);
return;
}
callback(200, body);
});
}
exports.manageOrder = manageOrder;
exports.sendOffer = sendOffer;
exports.getAllAvailableChannels = getAllAvailableChannels;