This repository has been archived by the owner on Oct 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnodefreshdesk.js
105 lines (93 loc) · 3.03 KB
/
nodefreshdesk.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
module.exports = function(url, apikey) {
var request = require('request');
var auth = 'Basic ' + new Buffer(apikey + ':X').toString('base64')
var fresh = {
get: function(link, callback) {
request(
{
url: url + link,
headers: {
'Authorization' : auth
}
},
callback
);
},
post: function(link, data, callback) {
request.post(
{
url: url + link,
json: data,
headers: {
'Authorization' : auth
}
},
callback
);
},
put: function(link, data, callback) {
request.put(
{
url: url + link,
json: data,
headers: {
'Authorization' : auth
}
},
callback
);
}
};
return {
postTicket: function(ticket, callback) {
fresh.post('/helpdesk/tickets.json', ticket, callback);
},
putTicket: function(id, ticket, callback) {
fresh.put(
'/helpdesk/tickets/' + id +'.json',
ticket,
callback
);
},
getTickets: function(callback) {
fresh.get('/helpdesk/tickets.json', callback);
},
getTicket: function(id, callback){
fresh.get('/helpdesk/tickets/' + id + '.json', callback);
},
postNoteToTicket: function(id, note, is_private, callback){
var data = {
'helpdesk_note':
{
'body': note,
'private': is_private
}
};
fresh.post('/helpdesk/tickets/' + id + '/conversations/note.json',
data, callback);
},
postContact: function(contact, callback) {
fresh.post('/contacts.json', contact, callback);
},
putContact: function(id, contact, callback) {
fresh.put('/contacts/' + id + '.json', contact, callback);
},
getContacts: function(callback) {
fresh.get('/contacts.json?state=all', callback);
},
getContactByEmail: function(email, callback) {
fresh.get(
'/contacts.json?state=all&query=email%20is%20' + email,
function(err, response, body) {
if (err || response.statusCode !== 200)
return callback(new Error('there was a problem getting Freshdesk contact by email'));
var users = JSON.parse(body);
if (users && users.length !== 0) {
return callback(users[0]);
}
return callback(null);
}
);
}
};
};