OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * Client for the GCD REST API. | 7 * Client for the GCD REST API. |
8 * TODO: Add link to GCD docs. | 8 * TODO: Add link to GCD docs. |
9 */ | 9 */ |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... | |
25 * deviceDraft: { | 25 * deviceDraft: { |
26 * id: string | 26 * id: string |
27 * } | 27 * } |
28 * }} | 28 * }} |
29 */ | 29 */ |
30 remoting.gcd.RegistrationTicket; | 30 remoting.gcd.RegistrationTicket; |
31 | 31 |
32 /** | 32 /** |
33 * TODO: Flesh out with typical fields. | 33 * TODO: Flesh out with typical fields. |
34 * @typedef {{ | 34 * @typedef {{ |
35 * id:string | 35 * id:string, |
36 * name:string | |
36 * }} | 37 * }} |
37 */ | 38 */ |
38 remoting.gcd.Device; | 39 remoting.gcd.Device; |
39 | 40 |
40 /** | 41 /** |
41 * @typedef {!Object} | 42 * @typedef {!Object} |
42 */ | 43 */ |
43 remoting.gcd.DevicePatch; | 44 remoting.gcd.DevicePatch; |
44 | 45 |
45 /** | 46 /** |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 console.error('error finalizing registration ticket'); | 200 console.error('error finalizing registration ticket'); |
200 throw remoting.Error.unexpected(); | 201 throw remoting.Error.unexpected(); |
201 } | 202 } |
202 return responseAsGcdRegistrationTicket(response); | 203 return responseAsGcdRegistrationTicket(response); |
203 }); | 204 }); |
204 }; | 205 }; |
205 | 206 |
206 /** | 207 /** |
207 * Lists devices user has access to. | 208 * Lists devices user has access to. |
208 * TODO: Add link to GCD docs. | 209 * TODO: Add link to GCD docs. |
210 * @param {string=} opt_nameSubstring | |
Jamie
2015/04/27 22:44:06
Please document this parameter.
John Williams
2015/04/27 23:05:42
Done.
| |
209 * @return {!Promise<!Array<remoting.gcd.Device>>} | 211 * @return {!Promise<!Array<remoting.gcd.Device>>} |
210 */ | 212 */ |
211 remoting.gcd.Client.prototype.listDevices = function() { | 213 remoting.gcd.Client.prototype.listDevices = function(opt_nameSubstring) { |
212 return new remoting.Xhr({ | 214 return new remoting.Xhr({ |
213 method: 'GET', | 215 method: 'GET', |
214 url: this.apiBaseUrl_ + '/devices', | 216 url: this.apiBaseUrl_ + '/devices', |
217 urlParams: { | |
218 nameSubstring: opt_nameSubstring || null | |
219 }, | |
215 useIdentity: true, | 220 useIdentity: true, |
216 acceptJson: true | 221 acceptJson: true |
217 }).start().then(function(response) { | 222 }).start().then(function(response) { |
218 if (response.isError()) { | 223 if (response.isError()) { |
219 console.error('error getting device list'); | 224 console.error('error getting device list'); |
220 throw remoting.Error.unexpected(); | 225 throw remoting.Error.unexpected(); |
221 } | 226 } |
222 var hosts = responseAsGcdDeviceListResponse(response); | 227 var hosts = responseAsGcdDeviceListResponse(response); |
223 return hosts.devices || []; | 228 return hosts.devices || []; |
224 }); | 229 }); |
225 }; | 230 }; |
226 | 231 |
227 /** | 232 /** |
228 * Deletes a device from the system. | 233 * Deletes a device from the system. |
229 * TODO: Add link to GCD docs. | 234 * TODO: Add link to GCD docs. |
230 * @param {string} deviceId | 235 * @param {string} deviceId |
231 * @return {!Promise<boolean>} Promise that resolves to true if the | 236 * @return {!Promise<boolean>} Promise that resolves to true if the |
232 * device was deleted, false if there was no such device ID. | 237 * device was deleted, false if there was no such device ID. |
233 */ | 238 */ |
234 remoting.gcd.Client.prototype.deleteDevice = function(deviceId) { | 239 remoting.gcd.Client.prototype.deleteDevice = function(deviceId) { |
235 return new remoting.Xhr({ | 240 return new remoting.Xhr({ |
236 method: 'DELETE', | 241 method: 'DELETE', |
237 url: this.apiBaseUrl_ + '/devices/' + deviceId, | 242 url: this.apiBaseUrl_ + '/devices/' + deviceId, |
238 useIdentity: true | 243 useIdentity: true |
239 }).start().then(function(response) { | 244 }).start().then(function(response) { |
240 if (response.status == 404) { | 245 if (response.status == 404) { |
241 return false; | 246 return false; |
242 } | 247 } |
243 if (response.isError()) { | 248 if (response.isError()) { |
244 console.warn('error deleting device'); | 249 console.error('error deleting device'); |
245 throw remoting.Error.unexpected(); | 250 throw remoting.Error.unexpected(); |
246 } | 251 } |
247 return true; | 252 return true; |
248 }); | 253 }); |
249 }; | 254 }; |
250 | 255 |
251 /** | 256 /** |
252 * Updates a device data using patch semantics. | 257 * Updates a device data using patch semantics. |
253 * TODO: Add link to GCD docs. | 258 * TODO: Add link to GCD docs. |
254 * @param {string} deviceId | 259 * @param {string} deviceId |
(...skipping 10 matching lines...) Expand all Loading... | |
265 }).start().then(function(response) { | 270 }).start().then(function(response) { |
266 if (response.isError()) { | 271 if (response.isError()) { |
267 console.error('error patching device'); | 272 console.error('error patching device'); |
268 throw remoting.Error.unexpected(); | 273 throw remoting.Error.unexpected(); |
269 } | 274 } |
270 return responseAsGcdDevice(response); | 275 return responseAsGcdDevice(response); |
271 }); | 276 }); |
272 }; | 277 }; |
273 | 278 |
274 })(); | 279 })(); |
OLD | NEW |