Coverage

77%
314
242
72

/Users/florian/Development/Projects/node_playground/node-kayako/lib/client.js

87%
103
90
13
LineHitsSource
1/**
2 * client.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241var xml2js = require('xml2js');
251var crypto = require('crypto');
261var querystring = require('querystring');
27
281var client = function (config) {
291 var protocol = (undefined === config.secure || config.secure) ?
30 'https' : 'http';
31
321 return {
33 generate_signature: function (salt) {
3422 var mac = crypto.createHmac('sha256', config.secret);
3522 mac.update(salt);
3622 return mac.digest('base64');
37 },
38 get_apikey: function () {
392 return config.apikey;
40 },
41 request: function (options, data, cb) {
4222 var callback = typeof data === 'function' ? data : cb;
4322 var postdata = typeof data === 'string' ? data : null;
44
4522 options.rejectUnauthorized = false;
4622 options.host = config.host;
47
4822 var req = require(protocol).request(options, function (res) {
4922 var data = '';
5022 res.on('data', function (chunk) {
5147 data += chunk;
52 });
5322 res.on('end', function () {
5422 if (res.statusCode >= 400 && res.statusCode < 600 ||
55 res.statusCode < 10) {
560 callback(res.statusCode);
57 } else {
5822 res.data = data;
5922 callback(null, res);
60 }
61 });
62 });
6322 req.on('error', function (e) {
640 callback(e.message);
65 });
6622 req.end(postdata);
67 },
68 send: function (method, command, options, xmlbody, cb) {
6920 var callback = typeof xmlbody === 'function' ? xmlbody : cb;
7020 var postdata = typeof xmlbody === 'string' ? xmlbody : null;
71
7220 var salt = crypto.randomBytes(20).toString('base64');
7320 options = options || { };
7420 options.e = command;
7520 options.apikey = config.apikey;
7620 options.salt = salt;
7720 options.signature = this.generate_signature(salt);
78
7920 var opts = {
80 path: '/api/index.php?' + querystring.stringify(options),
81 method: method
82 };
83
8420 if (postdata) {
850 opts.headers['Content-Length'] = postdata.length;
860 opts.headers['Content-Type'] = 'application/xml';
87 }
88
8920 this.request(opts, postdata, callback);
90 },
91 get_items: function (command, item_factory, callback) {
9210 var client = this;
93
9410 this.send('GET', command, null, function (err, res) {
9510 if (err) {
960 callback(err);
97 } else {
9810 client.parse_items(res.data, client,
99 item_factory, callback);
100 }
101 });
102 },
103 create_item: function (command, data, item_factory, callback) {
1040 var client = this;
105
1060 this.send('POST', command, null, data, function (err, res) {
1070 if (err) {
1080 callback(err);
109 } else {
1100 client.parse_item(res.data, client, item_factory, callback);
111 }
112 });
113 },
114 get_item: function (command, item_factory, callback) {
11510 var client = this;
116
11710 this.send('GET', command, null, function (err, res) {
11810 if (err) {
1190 callback(err);
120 } else {
12110 client.parse_item(res.data, client, item_factory, callback);
122 }
123 });
124 },
125 parse_item: function (data, client, item_factory, callback) {
12610 xml2js.parseString(data, function (err, res) {
12710 if (err) {
1280 callback(err);
129 } else {
13010 var data = null;
131
13210 for (var k1 in res) {
13310 if (typeof res[k1] === 'object') {
1349 for (var k2 in res[k1]) {
1359 if (typeof res[k1][k2] === 'object' &&
136 res[k1][k2].length === 1) {
1379 data = res[k1][k2][0];
138 }
1399 break;
140 }
141 }
14210 break;
143 }
144
14510 if (data) {
1469 callback(null, new item_factory(client, data));
147 } else {
1481 callback('invalid data', null);
149 }
150 }
151 });
152 },
153 parse_items: function (data, client, item_factory, callback) {
15412 xml2js.parseString(data, function (err, res) {
15512 if (err) {
1560 callback(err);
157 } else {
15812 var items = [];
159
16012 for (var k1 in res) {
16112 if (typeof res[k1] === 'object') {
16212 for (var k2 in res[k1]) {
16312 if (typeof res[k1][k2] === 'object') {
16412 for (var i = 0; i < res[k1][k2].length;
165 ++i) {
166776 var p = new item_factory(client,
167 res[k1][k2][i]);
168776 items.push(p);
169 }
170 }
17112 break;
172 }
173 }
17412 break;
175 }
176
17712 callback(null, items);
178 }
179 });
180 }
181 };
182};
183
1841var kayako = function (config) {
1851 this.client = new client(config);
1861 this.department = new (require('./department'))(this.client);
1871 this.departments = new (require('./departments'))(this.client);
1881 this.newscategory = new (require('./newscategory'))(this.client);
1891 this.newscategories = new (require('./newscategories'))(this.client);
1901 this.newsitem = new (require('./newsitem'))(this.client);
1911 this.newsitems = new (require('./newsitems'))(this.client);
1921 this.newssubscriber = new (require('./newssubscriber'))(this.client);
1931 this.newssubscribers = new (require('./newssubscribers'))(this.client);
1941 this.staff = new (require('./staff'))(this.client);
1951 this.staffgroup = new (require('./staffgroup'))(this.client);
1961 this.staffgroups = new (require('./staffgroups'))(this.client);
1971 this.staffusers = new (require('./staffusers'))(this.client);
1981 this.user = new (require('./user'))(this.client);
1991 this.users = new (require('./users'))(this.client);
2001 this.usergroup = new (require('./usergroup'))(this.client);
2011 this.usergroups = new (require('./usergroups'))(this.client);
2021 this.userorganization = new (require('./userorganization'))(this.client);
2031 this.userorganizations = new (require('./userorganizations'))(this.client);
204};
205
2061module.exports = kayako;
207

/Users/florian/Development/Projects/node_playground/node-kayako/lib/department.js

100%
8
8
0
LineHitsSource
1/**
2 * department.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241var utils = require('./utils');
25
261var department = function (client, xml) {
2712 this.client = client;
2812 if (xml) {
2911 utils.parse_xml(this, xml);
30 }
31};
321department.prototype.get = function (id, callback) {
331 this.client.get_item('/Base/Department/' + id, department, callback);
34};
35
361module.exports = department;
37

/Users/florian/Development/Projects/node_playground/node-kayako/lib/departments.js

100%
5
5
0
LineHitsSource
1/**
2 * departments.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241var departments = function (client) {
251 this.client = client;
26};
271departments.prototype.get = function (callback) {
281 this.client.get_items('/Base/Department',
29 require('./department'), callback);
30};
31
321module.exports = departments;
33

/Users/florian/Development/Projects/node_playground/node-kayako/lib/index.js

100%
1
1
0
LineHitsSource
1/**
2 * index.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241module.exports = require('./client');
25

/Users/florian/Development/Projects/node_playground/node-kayako/lib/newscategories.js

100%
5
5
0
LineHitsSource
1/**
2 * newscategories.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241var newscategories = function (client) {
251 this.client = client;
26};
271newscategories.prototype.get = function (callback) {
281 this.client.get_items('/News/Category', require('./newscategory'),
29 callback);
30};
31
321module.exports = newscategories;
33

/Users/florian/Development/Projects/node_playground/node-kayako/lib/newscategory.js

100%
8
8
0
LineHitsSource
1/**
2 * newscategory.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241var utils = require('./utils');
25
261var newscategory = function (client, xml) {
276 this.client = client;
286 if (xml) {
295 utils.parse_xml(this, xml);
30 }
31};
321newscategory.prototype.get = function (id, callback) {
331 this.client.get_item('/News/Category/' + id, newscategory, callback);
34};
35
361module.exports = newscategory;
37

/Users/florian/Development/Projects/node_playground/node-kayako/lib/newsitem.js

100%
8
8
0
LineHitsSource
1/**
2 * newsitem.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241var utils = require('./utils');
25
261var newsitem = function (client, xml) {
279 this.client = client;
289 if (xml) {
298 utils.parse_xml(this, xml);
30 }
31};
321newsitem.prototype.get = function (id, callback) {
331 this.client.get_item('/News/NewsItem/' + id, newsitem, callback);
34};
35
361module.exports = newsitem;
37

/Users/florian/Development/Projects/node_playground/node-kayako/lib/newsitems.js

100%
7
7
0
LineHitsSource
1/**
2 * newsitems.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241var newsitems = function (client) {
251 this.client = client;
26};
271newsitems.prototype.get = function (categoryId, callback) {
282 if (callback) {
291 this.client.get_items('/News/NewsItem/ListAll/' + categoryId,
30 require('./newsitem'), callback);
31 } else {
321 this.client.get_items('/News/NewsItem', require('./newsitem'),
33 categoryId);
34 }
35};
36
371module.exports = newsitems;
38

/Users/florian/Development/Projects/node_playground/node-kayako/lib/newssubscriber.js

100%
8
8
0
LineHitsSource
1/**
2 * newssubscriber.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241var utils = require('./utils');
25
261var newssubscriber = function (client, xml) {
273 this.client = client;
283 if (xml) {
292 utils.parse_xml(this, xml);
30 }
31};
321newssubscriber.prototype.get = function (id, callback) {
332 this.client.get_item('/News/Subscriber/' + id, newssubscriber, callback);
34};
35
361module.exports = newssubscriber;
37

/Users/florian/Development/Projects/node_playground/node-kayako/lib/newssubscribers.js

100%
5
5
0
LineHitsSource
1/**
2 * newssubscribers.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241var newssubscribers = function (client) {
251 this.client = client;
26};
271newssubscribers.prototype.get = function (callback) {
281 this.client.get_items('/News/Subscriber', require('./newssubscriber'),
29 callback);
30};
31
321module.exports = newssubscribers;
33

/Users/florian/Development/Projects/node_playground/node-kayako/lib/staff.js

100%
8
8
0
LineHitsSource
1/**
2 * staff.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241var utils = require('./utils');
25
261var staff = function (client, xml) {
2721 this.client = client;
2821 if (xml) {
2920 utils.parse_xml(this, xml);
30 }
31};
321staff.prototype.get = function (id, callback) {
331 this.client.get_item('/Base/Staff/' + id, staff, callback);
34};
35
361module.exports = staff;
37

/Users/florian/Development/Projects/node_playground/node-kayako/lib/staffgroup.js

100%
8
8
0
LineHitsSource
1/**
2 * staffgroup.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241var utils = require('./utils');
25
261var staffgroup = function (client, xml) {
277 this.client = client;
287 if (xml) {
296 utils.parse_xml(this, xml);
30 }
31};
321staffgroup.prototype.get = function (id, callback) {
331 this.client.get_item('/Base/StaffGroup/' + id, staffgroup, callback);
34};
35
361module.exports = staffgroup;
37

/Users/florian/Development/Projects/node_playground/node-kayako/lib/staffgroups.js

100%
5
5
0
LineHitsSource
1/**
2 * staffgroups.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241var staffgroups = function (client) {
251 this.client = client;
26};
271staffgroups.prototype.get = function (callback) {
281 this.client.get_items('/Base/StaffGroup',
29 require('./staffgroup'), callback);
30};
31
321module.exports = staffgroups;
33

/Users/florian/Development/Projects/node_playground/node-kayako/lib/staffusers.js

100%
5
5
0
LineHitsSource
1/**
2 * staffusers.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241var staffusers = function (client) {
251 this.client = client;
26};
271staffusers.prototype.get = function (callback) {
281 this.client.get_items('/Base/Staff', require('./staff'), callback);
29};
30
311module.exports = staffusers;
32

/Users/florian/Development/Projects/node_playground/node-kayako/lib/user.js

100%
8
8
0
LineHitsSource
1/**
2 * user.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241var utils = require('./utils');
25
261var user = function (client, xml) {
27676 this.client = client;
28676 if (xml) {
29675 utils.parse_xml(this, xml);
30 }
31};
321user.prototype.get = function (id, callback) {
331 this.client.get_item('/Base/UserOrganization/' + id, user, callback);
34};
35
361module.exports = user;
37

/Users/florian/Development/Projects/node_playground/node-kayako/lib/usergroup.js

100%
8
8
0
LineHitsSource
1/**
2 * usergroup.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241var utils = require('./utils');
25
261var usergroup = function (client, xml) {
2729 this.client = client;
2829 if (xml) {
2928 utils.parse_xml(this, xml);
30 }
31};
321usergroup.prototype.get = function (id, callback) {
331 this.client.get_item('/Base/UserGroup/' + id, usergroup, callback);
34};
35
361module.exports = usergroup;
37

/Users/florian/Development/Projects/node_playground/node-kayako/lib/usergroups.js

100%
5
5
0
LineHitsSource
1/**
2 * usergroups.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241var usergroups = function (client) {
251 this.client = client;
26};
271usergroups.prototype.get = function (callback) {
281 this.client.get_items('/Base/UserGroup', require('./usergroup'), callback);
29};
30
311module.exports = usergroups;
32

/Users/florian/Development/Projects/node_playground/node-kayako/lib/userorganization.js

100%
8
8
0
LineHitsSource
1/**
2 * userorganization.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241var utils = require('./utils');
25
261var userorganization = function (client, xml) {
2731 this.client = client;
2831 if (xml) {
2930 utils.parse_xml(this, xml);
30 }
31};
321userorganization.prototype.get = function (id, callback) {
331 this.client.get_item('/Base/UserOrganization/' + id, userorganization,
34 callback);
35};
36
371module.exports = userorganization;
38

/Users/florian/Development/Projects/node_playground/node-kayako/lib/userorganizations.js

100%
5
5
0
LineHitsSource
1/**
2 * userorganizations.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241var userorganizations = function (client) {
251 this.client = client;
26};
271userorganizations.prototype.get = function (callback) {
281 this.client.get_items('/Base/UserOrganization',
29 require('./userorganization'), callback);
30};
31
321module.exports = userorganizations;
33

/Users/florian/Development/Projects/node_playground/node-kayako/lib/users.js

95%
20
19
1
LineHitsSource
1/**
2 * users.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241var querystring = require('querystring');
251var crypto = require('crypto');
26
271var users = function (client) {
281 this.client = client;
29};
301users.prototype.get = function (callback) {
311 this.client.get_items('/Base/User/Filter', require('./user'), callback);
32};
331users.prototype.search = function (query, callback) {
342 var client = this.client;
352 var salt = crypto.randomBytes(20).toString('base64');
362 var options = {
37 e: '/Base/UserSearch',
38 apikey: this.client.get_apikey(),
39 salt: salt,
40 signature: this.client.generate_signature(salt)
41 };
42
432 for (var k in query) {
442 options.query = query[k];
452 options[k] = 1;
46 }
47
482 var postdata = querystring.stringify(options);
492 var opts = {
50 path: '/api/index.php',
51 method: 'POST',
52 headers: {
53 'Content-Type': 'application/x-www-form-urlencoded',
54 'Content-Length': postdata.length
55 }
56 };
57
582 this.client.request(opts, postdata, function (err, res) {
592 if (err) {
600 callback(err);
61 } else {
622 client.parse_items(res.data, client, require('./user'), callback);
63 }
64 });
65};
66
671module.exports = users;
68

/Users/florian/Development/Projects/node_playground/node-kayako/lib/utils.js

23%
76
18
58
LineHitsSource
1/**
2 * utils.js
3 *
4 * Copyright (C) 2014 by Florian Holzapfel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23**/
241var util = require('util');
25
261function get_arr_key(object) {
270 for (var key in object) {
280 if (key !== '$') {
290 return key;
30 }
31 }
320 return null;
33}
34
351var parse_xml = function (object, xml_object) {
36808 var get_name = function (name) {
370 return name;
38 };
39
40808 for (var key in xml_object) {
4112639 var o = xml_object[key][0];
4212639 key = key.replace('-', '_');
43
4412639 if (typeof(o) === 'string') {
4512616 if (o === 'true') {
460 object[key] = true;
4712616 } else if (o === 'false') {
480 object[key] = false;
49 } else {
5012616 object[key] = o;
51 }
5223 } else if (typeof(o) === 'object') {
5323 if (typeof(o.$) === 'object') {
540 if (o.$.nil === 'true') {
550 object[key] = null;
560 } else if (o.$.type === 'array') {
570 var arr_key = get_arr_key(o);
58
590 object[key] = [];
60
610 if (arr_key) {
620 object[key].get_name = get_name.bind(null, arr_key);
63
640 for (var i = 0; i < o[arr_key].length; ++i) {
650 object[key].push({});
660 parse_xml(object[key][i], o[arr_key][i]);
67 }
68 }
690 } else if (o.$.type === 'datetime') {
700 object[key] = new Date(o._);
710 } else if (o.$.type === 'integer') {
720 object[key] = parseInt(o._);
73 }
74 } else {
7523 object[key] = { };
7623 parse_xml(object[key], o);
77 }
78 }
79 }
80};
811var to_xml = function (object, name, excluded_keys) {
820 if (excluded_keys) {
830 excluded_keys.push('client');
84 } else {
850 excluded_keys = [ 'client' ];
86 }
87
880 function isKeyExcluded(key) {
890 for (var i = 0; i < excluded_keys.length; ++i) {
900 if (key === excluded_keys[i]) {
910 return true;
92 }
93 }
940 return false;
95 }
96
970 var res = util.format('<%s>', name);
98
990 for (var key in object) {
1000 if (isKeyExcluded(key)) {
1010 continue;
102 }
103
1040 var value = object[key];
1050 key = key.replace('_', '-');
106
1070 if (typeof(value) === 'function') {
1080 continue;
1090 } else if (typeof(value) === 'object') {
1100 if (value === null) {
1110 res += util.format('<%s></%s>', key, key);
1120 } else if (util.isDate(value)) {
1130 res += util.format('<%s type="datetime">%s</%s>', key,
114 value.toISOString(), key);
1150 } else if (util.isArray(value)) {
1160 if (value.length) {
1170 res += util.format('<%s type="array">', key);
1180 for (var i = 0; i < value.length; ++i) {
1190 res += to_xml(value[i], value.get_name());
120 }
1210 res += util.format('</%s>', key);
122 } else {
1230 res += util.format('<%s type="array"/>', key);
124 }
125 } else {
1260 res += to_xml(value, key);
127 }
1280 } else if (typeof(value) === 'string') {
1290 res += util.format('<%s>%s</%s>', key, value, key);
1300 } else if (typeof(value) === 'number') {
1310 res += util.format('<%s type="integer">%d</%s>', key, value, key);
1320 } else if (typeof(value) === 'boolean') {
1330 res += util.format('<%s>%s</%s>', key,
134 value ? 'true' : 'false', key);
135 }
136 }
137
1380 res += util.format('</%s>', name);
1390 return res;
140};
141
1421module.exports.parse_xml = parse_xml;
1431module.exports.to_xml = to_xml;
144