Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | var xml2js = require('xml2js'); |
25 | 1 | var crypto = require('crypto'); |
26 | 1 | var querystring = require('querystring'); |
27 | ||
28 | 1 | var client = function (config) { |
29 | 1 | var protocol = (undefined === config.secure || config.secure) ? |
30 | 'https' : 'http'; | |
31 | ||
32 | 1 | return { |
33 | generate_signature: function (salt) { | |
34 | 22 | var mac = crypto.createHmac('sha256', config.secret); |
35 | 22 | mac.update(salt); |
36 | 22 | return mac.digest('base64'); |
37 | }, | |
38 | get_apikey: function () { | |
39 | 2 | return config.apikey; |
40 | }, | |
41 | request: function (options, data, cb) { | |
42 | 22 | var callback = typeof data === 'function' ? data : cb; |
43 | 22 | var postdata = typeof data === 'string' ? data : null; |
44 | ||
45 | 22 | options.rejectUnauthorized = false; |
46 | 22 | options.host = config.host; |
47 | ||
48 | 22 | var req = require(protocol).request(options, function (res) { |
49 | 22 | var data = ''; |
50 | 22 | res.on('data', function (chunk) { |
51 | 47 | data += chunk; |
52 | }); | |
53 | 22 | res.on('end', function () { |
54 | 22 | if (res.statusCode >= 400 && res.statusCode < 600 || |
55 | res.statusCode < 10) { | |
56 | 0 | callback(res.statusCode); |
57 | } else { | |
58 | 22 | res.data = data; |
59 | 22 | callback(null, res); |
60 | } | |
61 | }); | |
62 | }); | |
63 | 22 | req.on('error', function (e) { |
64 | 0 | callback(e.message); |
65 | }); | |
66 | 22 | req.end(postdata); |
67 | }, | |
68 | send: function (method, command, options, xmlbody, cb) { | |
69 | 20 | var callback = typeof xmlbody === 'function' ? xmlbody : cb; |
70 | 20 | var postdata = typeof xmlbody === 'string' ? xmlbody : null; |
71 | ||
72 | 20 | var salt = crypto.randomBytes(20).toString('base64'); |
73 | 20 | options = options || { }; |
74 | 20 | options.e = command; |
75 | 20 | options.apikey = config.apikey; |
76 | 20 | options.salt = salt; |
77 | 20 | options.signature = this.generate_signature(salt); |
78 | ||
79 | 20 | var opts = { |
80 | path: '/api/index.php?' + querystring.stringify(options), | |
81 | method: method | |
82 | }; | |
83 | ||
84 | 20 | if (postdata) { |
85 | 0 | opts.headers['Content-Length'] = postdata.length; |
86 | 0 | opts.headers['Content-Type'] = 'application/xml'; |
87 | } | |
88 | ||
89 | 20 | this.request(opts, postdata, callback); |
90 | }, | |
91 | get_items: function (command, item_factory, callback) { | |
92 | 10 | var client = this; |
93 | ||
94 | 10 | this.send('GET', command, null, function (err, res) { |
95 | 10 | if (err) { |
96 | 0 | callback(err); |
97 | } else { | |
98 | 10 | client.parse_items(res.data, client, |
99 | item_factory, callback); | |
100 | } | |
101 | }); | |
102 | }, | |
103 | create_item: function (command, data, item_factory, callback) { | |
104 | 0 | var client = this; |
105 | ||
106 | 0 | this.send('POST', command, null, data, function (err, res) { |
107 | 0 | if (err) { |
108 | 0 | callback(err); |
109 | } else { | |
110 | 0 | client.parse_item(res.data, client, item_factory, callback); |
111 | } | |
112 | }); | |
113 | }, | |
114 | get_item: function (command, item_factory, callback) { | |
115 | 10 | var client = this; |
116 | ||
117 | 10 | this.send('GET', command, null, function (err, res) { |
118 | 10 | if (err) { |
119 | 0 | callback(err); |
120 | } else { | |
121 | 10 | client.parse_item(res.data, client, item_factory, callback); |
122 | } | |
123 | }); | |
124 | }, | |
125 | parse_item: function (data, client, item_factory, callback) { | |
126 | 10 | xml2js.parseString(data, function (err, res) { |
127 | 10 | if (err) { |
128 | 0 | callback(err); |
129 | } else { | |
130 | 10 | var data = null; |
131 | ||
132 | 10 | for (var k1 in res) { |
133 | 10 | if (typeof res[k1] === 'object') { |
134 | 9 | for (var k2 in res[k1]) { |
135 | 9 | if (typeof res[k1][k2] === 'object' && |
136 | res[k1][k2].length === 1) { | |
137 | 9 | data = res[k1][k2][0]; |
138 | } | |
139 | 9 | break; |
140 | } | |
141 | } | |
142 | 10 | break; |
143 | } | |
144 | ||
145 | 10 | if (data) { |
146 | 9 | callback(null, new item_factory(client, data)); |
147 | } else { | |
148 | 1 | callback('invalid data', null); |
149 | } | |
150 | } | |
151 | }); | |
152 | }, | |
153 | parse_items: function (data, client, item_factory, callback) { | |
154 | 12 | xml2js.parseString(data, function (err, res) { |
155 | 12 | if (err) { |
156 | 0 | callback(err); |
157 | } else { | |
158 | 12 | var items = []; |
159 | ||
160 | 12 | for (var k1 in res) { |
161 | 12 | if (typeof res[k1] === 'object') { |
162 | 12 | for (var k2 in res[k1]) { |
163 | 12 | if (typeof res[k1][k2] === 'object') { |
164 | 12 | for (var i = 0; i < res[k1][k2].length; |
165 | ++i) { | |
166 | 776 | var p = new item_factory(client, |
167 | res[k1][k2][i]); | |
168 | 776 | items.push(p); |
169 | } | |
170 | } | |
171 | 12 | break; |
172 | } | |
173 | } | |
174 | 12 | break; |
175 | } | |
176 | ||
177 | 12 | callback(null, items); |
178 | } | |
179 | }); | |
180 | } | |
181 | }; | |
182 | }; | |
183 | ||
184 | 1 | var kayako = function (config) { |
185 | 1 | this.client = new client(config); |
186 | 1 | this.department = new (require('./department'))(this.client); |
187 | 1 | this.departments = new (require('./departments'))(this.client); |
188 | 1 | this.newscategory = new (require('./newscategory'))(this.client); |
189 | 1 | this.newscategories = new (require('./newscategories'))(this.client); |
190 | 1 | this.newsitem = new (require('./newsitem'))(this.client); |
191 | 1 | this.newsitems = new (require('./newsitems'))(this.client); |
192 | 1 | this.newssubscriber = new (require('./newssubscriber'))(this.client); |
193 | 1 | this.newssubscribers = new (require('./newssubscribers'))(this.client); |
194 | 1 | this.staff = new (require('./staff'))(this.client); |
195 | 1 | this.staffgroup = new (require('./staffgroup'))(this.client); |
196 | 1 | this.staffgroups = new (require('./staffgroups'))(this.client); |
197 | 1 | this.staffusers = new (require('./staffusers'))(this.client); |
198 | 1 | this.user = new (require('./user'))(this.client); |
199 | 1 | this.users = new (require('./users'))(this.client); |
200 | 1 | this.usergroup = new (require('./usergroup'))(this.client); |
201 | 1 | this.usergroups = new (require('./usergroups'))(this.client); |
202 | 1 | this.userorganization = new (require('./userorganization'))(this.client); |
203 | 1 | this.userorganizations = new (require('./userorganizations'))(this.client); |
204 | }; | |
205 | ||
206 | 1 | module.exports = kayako; |
207 |
Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | var utils = require('./utils'); |
25 | ||
26 | 1 | var department = function (client, xml) { |
27 | 12 | this.client = client; |
28 | 12 | if (xml) { |
29 | 11 | utils.parse_xml(this, xml); |
30 | } | |
31 | }; | |
32 | 1 | department.prototype.get = function (id, callback) { |
33 | 1 | this.client.get_item('/Base/Department/' + id, department, callback); |
34 | }; | |
35 | ||
36 | 1 | module.exports = department; |
37 |
Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | var departments = function (client) { |
25 | 1 | this.client = client; |
26 | }; | |
27 | 1 | departments.prototype.get = function (callback) { |
28 | 1 | this.client.get_items('/Base/Department', |
29 | require('./department'), callback); | |
30 | }; | |
31 | ||
32 | 1 | module.exports = departments; |
33 |
Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | module.exports = require('./client'); |
25 |
Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | var newscategories = function (client) { |
25 | 1 | this.client = client; |
26 | }; | |
27 | 1 | newscategories.prototype.get = function (callback) { |
28 | 1 | this.client.get_items('/News/Category', require('./newscategory'), |
29 | callback); | |
30 | }; | |
31 | ||
32 | 1 | module.exports = newscategories; |
33 |
Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | var utils = require('./utils'); |
25 | ||
26 | 1 | var newscategory = function (client, xml) { |
27 | 6 | this.client = client; |
28 | 6 | if (xml) { |
29 | 5 | utils.parse_xml(this, xml); |
30 | } | |
31 | }; | |
32 | 1 | newscategory.prototype.get = function (id, callback) { |
33 | 1 | this.client.get_item('/News/Category/' + id, newscategory, callback); |
34 | }; | |
35 | ||
36 | 1 | module.exports = newscategory; |
37 |
Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | var utils = require('./utils'); |
25 | ||
26 | 1 | var newsitem = function (client, xml) { |
27 | 9 | this.client = client; |
28 | 9 | if (xml) { |
29 | 8 | utils.parse_xml(this, xml); |
30 | } | |
31 | }; | |
32 | 1 | newsitem.prototype.get = function (id, callback) { |
33 | 1 | this.client.get_item('/News/NewsItem/' + id, newsitem, callback); |
34 | }; | |
35 | ||
36 | 1 | module.exports = newsitem; |
37 |
Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | var newsitems = function (client) { |
25 | 1 | this.client = client; |
26 | }; | |
27 | 1 | newsitems.prototype.get = function (categoryId, callback) { |
28 | 2 | if (callback) { |
29 | 1 | this.client.get_items('/News/NewsItem/ListAll/' + categoryId, |
30 | require('./newsitem'), callback); | |
31 | } else { | |
32 | 1 | this.client.get_items('/News/NewsItem', require('./newsitem'), |
33 | categoryId); | |
34 | } | |
35 | }; | |
36 | ||
37 | 1 | module.exports = newsitems; |
38 |
Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | var utils = require('./utils'); |
25 | ||
26 | 1 | var newssubscriber = function (client, xml) { |
27 | 3 | this.client = client; |
28 | 3 | if (xml) { |
29 | 2 | utils.parse_xml(this, xml); |
30 | } | |
31 | }; | |
32 | 1 | newssubscriber.prototype.get = function (id, callback) { |
33 | 2 | this.client.get_item('/News/Subscriber/' + id, newssubscriber, callback); |
34 | }; | |
35 | ||
36 | 1 | module.exports = newssubscriber; |
37 |
Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | var newssubscribers = function (client) { |
25 | 1 | this.client = client; |
26 | }; | |
27 | 1 | newssubscribers.prototype.get = function (callback) { |
28 | 1 | this.client.get_items('/News/Subscriber', require('./newssubscriber'), |
29 | callback); | |
30 | }; | |
31 | ||
32 | 1 | module.exports = newssubscribers; |
33 |
Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | var utils = require('./utils'); |
25 | ||
26 | 1 | var staff = function (client, xml) { |
27 | 21 | this.client = client; |
28 | 21 | if (xml) { |
29 | 20 | utils.parse_xml(this, xml); |
30 | } | |
31 | }; | |
32 | 1 | staff.prototype.get = function (id, callback) { |
33 | 1 | this.client.get_item('/Base/Staff/' + id, staff, callback); |
34 | }; | |
35 | ||
36 | 1 | module.exports = staff; |
37 |
Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | var utils = require('./utils'); |
25 | ||
26 | 1 | var staffgroup = function (client, xml) { |
27 | 7 | this.client = client; |
28 | 7 | if (xml) { |
29 | 6 | utils.parse_xml(this, xml); |
30 | } | |
31 | }; | |
32 | 1 | staffgroup.prototype.get = function (id, callback) { |
33 | 1 | this.client.get_item('/Base/StaffGroup/' + id, staffgroup, callback); |
34 | }; | |
35 | ||
36 | 1 | module.exports = staffgroup; |
37 |
Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | var staffgroups = function (client) { |
25 | 1 | this.client = client; |
26 | }; | |
27 | 1 | staffgroups.prototype.get = function (callback) { |
28 | 1 | this.client.get_items('/Base/StaffGroup', |
29 | require('./staffgroup'), callback); | |
30 | }; | |
31 | ||
32 | 1 | module.exports = staffgroups; |
33 |
Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | var staffusers = function (client) { |
25 | 1 | this.client = client; |
26 | }; | |
27 | 1 | staffusers.prototype.get = function (callback) { |
28 | 1 | this.client.get_items('/Base/Staff', require('./staff'), callback); |
29 | }; | |
30 | ||
31 | 1 | module.exports = staffusers; |
32 |
Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | var utils = require('./utils'); |
25 | ||
26 | 1 | var user = function (client, xml) { |
27 | 676 | this.client = client; |
28 | 676 | if (xml) { |
29 | 675 | utils.parse_xml(this, xml); |
30 | } | |
31 | }; | |
32 | 1 | user.prototype.get = function (id, callback) { |
33 | 1 | this.client.get_item('/Base/UserOrganization/' + id, user, callback); |
34 | }; | |
35 | ||
36 | 1 | module.exports = user; |
37 |
Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | var utils = require('./utils'); |
25 | ||
26 | 1 | var usergroup = function (client, xml) { |
27 | 29 | this.client = client; |
28 | 29 | if (xml) { |
29 | 28 | utils.parse_xml(this, xml); |
30 | } | |
31 | }; | |
32 | 1 | usergroup.prototype.get = function (id, callback) { |
33 | 1 | this.client.get_item('/Base/UserGroup/' + id, usergroup, callback); |
34 | }; | |
35 | ||
36 | 1 | module.exports = usergroup; |
37 |
Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | var usergroups = function (client) { |
25 | 1 | this.client = client; |
26 | }; | |
27 | 1 | usergroups.prototype.get = function (callback) { |
28 | 1 | this.client.get_items('/Base/UserGroup', require('./usergroup'), callback); |
29 | }; | |
30 | ||
31 | 1 | module.exports = usergroups; |
32 |
Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | var utils = require('./utils'); |
25 | ||
26 | 1 | var userorganization = function (client, xml) { |
27 | 31 | this.client = client; |
28 | 31 | if (xml) { |
29 | 30 | utils.parse_xml(this, xml); |
30 | } | |
31 | }; | |
32 | 1 | userorganization.prototype.get = function (id, callback) { |
33 | 1 | this.client.get_item('/Base/UserOrganization/' + id, userorganization, |
34 | callback); | |
35 | }; | |
36 | ||
37 | 1 | module.exports = userorganization; |
38 |
Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | var userorganizations = function (client) { |
25 | 1 | this.client = client; |
26 | }; | |
27 | 1 | userorganizations.prototype.get = function (callback) { |
28 | 1 | this.client.get_items('/Base/UserOrganization', |
29 | require('./userorganization'), callback); | |
30 | }; | |
31 | ||
32 | 1 | module.exports = userorganizations; |
33 |
Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | var querystring = require('querystring'); |
25 | 1 | var crypto = require('crypto'); |
26 | ||
27 | 1 | var users = function (client) { |
28 | 1 | this.client = client; |
29 | }; | |
30 | 1 | users.prototype.get = function (callback) { |
31 | 1 | this.client.get_items('/Base/User/Filter', require('./user'), callback); |
32 | }; | |
33 | 1 | users.prototype.search = function (query, callback) { |
34 | 2 | var client = this.client; |
35 | 2 | var salt = crypto.randomBytes(20).toString('base64'); |
36 | 2 | var options = { |
37 | e: '/Base/UserSearch', | |
38 | apikey: this.client.get_apikey(), | |
39 | salt: salt, | |
40 | signature: this.client.generate_signature(salt) | |
41 | }; | |
42 | ||
43 | 2 | for (var k in query) { |
44 | 2 | options.query = query[k]; |
45 | 2 | options[k] = 1; |
46 | } | |
47 | ||
48 | 2 | var postdata = querystring.stringify(options); |
49 | 2 | 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 | ||
58 | 2 | this.client.request(opts, postdata, function (err, res) { |
59 | 2 | if (err) { |
60 | 0 | callback(err); |
61 | } else { | |
62 | 2 | client.parse_items(res.data, client, require('./user'), callback); |
63 | } | |
64 | }); | |
65 | }; | |
66 | ||
67 | 1 | module.exports = users; |
68 |
Line | Hits | Source |
---|---|---|
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 | **/ | |
24 | 1 | var util = require('util'); |
25 | ||
26 | 1 | function get_arr_key(object) { |
27 | 0 | for (var key in object) { |
28 | 0 | if (key !== '$') { |
29 | 0 | return key; |
30 | } | |
31 | } | |
32 | 0 | return null; |
33 | } | |
34 | ||
35 | 1 | var parse_xml = function (object, xml_object) { |
36 | 808 | var get_name = function (name) { |
37 | 0 | return name; |
38 | }; | |
39 | ||
40 | 808 | for (var key in xml_object) { |
41 | 12639 | var o = xml_object[key][0]; |
42 | 12639 | key = key.replace('-', '_'); |
43 | ||
44 | 12639 | if (typeof(o) === 'string') { |
45 | 12616 | if (o === 'true') { |
46 | 0 | object[key] = true; |
47 | 12616 | } else if (o === 'false') { |
48 | 0 | object[key] = false; |
49 | } else { | |
50 | 12616 | object[key] = o; |
51 | } | |
52 | 23 | } else if (typeof(o) === 'object') { |
53 | 23 | if (typeof(o.$) === 'object') { |
54 | 0 | if (o.$.nil === 'true') { |
55 | 0 | object[key] = null; |
56 | 0 | } else if (o.$.type === 'array') { |
57 | 0 | var arr_key = get_arr_key(o); |
58 | ||
59 | 0 | object[key] = []; |
60 | ||
61 | 0 | if (arr_key) { |
62 | 0 | object[key].get_name = get_name.bind(null, arr_key); |
63 | ||
64 | 0 | for (var i = 0; i < o[arr_key].length; ++i) { |
65 | 0 | object[key].push({}); |
66 | 0 | parse_xml(object[key][i], o[arr_key][i]); |
67 | } | |
68 | } | |
69 | 0 | } else if (o.$.type === 'datetime') { |
70 | 0 | object[key] = new Date(o._); |
71 | 0 | } else if (o.$.type === 'integer') { |
72 | 0 | object[key] = parseInt(o._); |
73 | } | |
74 | } else { | |
75 | 23 | object[key] = { }; |
76 | 23 | parse_xml(object[key], o); |
77 | } | |
78 | } | |
79 | } | |
80 | }; | |
81 | 1 | var to_xml = function (object, name, excluded_keys) { |
82 | 0 | if (excluded_keys) { |
83 | 0 | excluded_keys.push('client'); |
84 | } else { | |
85 | 0 | excluded_keys = [ 'client' ]; |
86 | } | |
87 | ||
88 | 0 | function isKeyExcluded(key) { |
89 | 0 | for (var i = 0; i < excluded_keys.length; ++i) { |
90 | 0 | if (key === excluded_keys[i]) { |
91 | 0 | return true; |
92 | } | |
93 | } | |
94 | 0 | return false; |
95 | } | |
96 | ||
97 | 0 | var res = util.format('<%s>', name); |
98 | ||
99 | 0 | for (var key in object) { |
100 | 0 | if (isKeyExcluded(key)) { |
101 | 0 | continue; |
102 | } | |
103 | ||
104 | 0 | var value = object[key]; |
105 | 0 | key = key.replace('_', '-'); |
106 | ||
107 | 0 | if (typeof(value) === 'function') { |
108 | 0 | continue; |
109 | 0 | } else if (typeof(value) === 'object') { |
110 | 0 | if (value === null) { |
111 | 0 | res += util.format('<%s></%s>', key, key); |
112 | 0 | } else if (util.isDate(value)) { |
113 | 0 | res += util.format('<%s type="datetime">%s</%s>', key, |
114 | value.toISOString(), key); | |
115 | 0 | } else if (util.isArray(value)) { |
116 | 0 | if (value.length) { |
117 | 0 | res += util.format('<%s type="array">', key); |
118 | 0 | for (var i = 0; i < value.length; ++i) { |
119 | 0 | res += to_xml(value[i], value.get_name()); |
120 | } | |
121 | 0 | res += util.format('</%s>', key); |
122 | } else { | |
123 | 0 | res += util.format('<%s type="array"/>', key); |
124 | } | |
125 | } else { | |
126 | 0 | res += to_xml(value, key); |
127 | } | |
128 | 0 | } else if (typeof(value) === 'string') { |
129 | 0 | res += util.format('<%s>%s</%s>', key, value, key); |
130 | 0 | } else if (typeof(value) === 'number') { |
131 | 0 | res += util.format('<%s type="integer">%d</%s>', key, value, key); |
132 | 0 | } else if (typeof(value) === 'boolean') { |
133 | 0 | res += util.format('<%s>%s</%s>', key, |
134 | value ? 'true' : 'false', key); | |
135 | } | |
136 | } | |
137 | ||
138 | 0 | res += util.format('</%s>', name); |
139 | 0 | return res; |
140 | }; | |
141 | ||
142 | 1 | module.exports.parse_xml = parse_xml; |
143 | 1 | module.exports.to_xml = to_xml; |
144 |