Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: remoting/webapp/crd/js/gcd_client.js

Issue 1104383002: Added ability to list and delete hosts with GCD. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for review Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | remoting/webapp/crd/js/host_list_api_gcd_impl.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 If present, the list of devices
211 * is filtered by GCD such that every device returned contains
212 * this string as as a substring of its |name| or |displayName|.
209 * @return {!Promise<!Array<remoting.gcd.Device>>} 213 * @return {!Promise<!Array<remoting.gcd.Device>>}
210 */ 214 */
211 remoting.gcd.Client.prototype.listDevices = function() { 215 remoting.gcd.Client.prototype.listDevices = function(opt_nameSubstring) {
212 return new remoting.Xhr({ 216 return new remoting.Xhr({
213 method: 'GET', 217 method: 'GET',
214 url: this.apiBaseUrl_ + '/devices', 218 url: this.apiBaseUrl_ + '/devices',
219 urlParams: {
220 nameSubstring: opt_nameSubstring || null
221 },
215 useIdentity: true, 222 useIdentity: true,
216 acceptJson: true 223 acceptJson: true
217 }).start().then(function(response) { 224 }).start().then(function(response) {
218 if (response.isError()) { 225 if (response.isError()) {
219 console.error('error getting device list'); 226 console.error('error getting device list');
220 throw remoting.Error.unexpected(); 227 throw remoting.Error.unexpected();
221 } 228 }
222 var hosts = responseAsGcdDeviceListResponse(response); 229 var hosts = responseAsGcdDeviceListResponse(response);
223 return hosts.devices || []; 230 return hosts.devices || [];
224 }); 231 });
225 }; 232 };
226 233
227 /** 234 /**
228 * Deletes a device from the system. 235 * Deletes a device from the system.
229 * TODO: Add link to GCD docs. 236 * TODO: Add link to GCD docs.
230 * @param {string} deviceId 237 * @param {string} deviceId
231 * @return {!Promise<boolean>} Promise that resolves to true if the 238 * @return {!Promise<boolean>} Promise that resolves to true if the
232 * device was deleted, false if there was no such device ID. 239 * device was deleted, false if there was no such device ID.
233 */ 240 */
234 remoting.gcd.Client.prototype.deleteDevice = function(deviceId) { 241 remoting.gcd.Client.prototype.deleteDevice = function(deviceId) {
235 return new remoting.Xhr({ 242 return new remoting.Xhr({
236 method: 'DELETE', 243 method: 'DELETE',
237 url: this.apiBaseUrl_ + '/devices/' + deviceId, 244 url: this.apiBaseUrl_ + '/devices/' + deviceId,
238 useIdentity: true 245 useIdentity: true
239 }).start().then(function(response) { 246 }).start().then(function(response) {
240 if (response.status == 404) { 247 if (response.status == 404) {
241 return false; 248 return false;
242 } 249 }
243 if (response.isError()) { 250 if (response.isError()) {
244 console.warn('error deleting device'); 251 console.error('error deleting device');
245 throw remoting.Error.unexpected(); 252 throw remoting.Error.unexpected();
246 } 253 }
247 return true; 254 return true;
248 }); 255 });
249 }; 256 };
250 257
251 /** 258 /**
252 * Updates a device data using patch semantics. 259 * Updates a device data using patch semantics.
253 * TODO: Add link to GCD docs. 260 * TODO: Add link to GCD docs.
254 * @param {string} deviceId 261 * @param {string} deviceId
(...skipping 10 matching lines...) Expand all
265 }).start().then(function(response) { 272 }).start().then(function(response) {
266 if (response.isError()) { 273 if (response.isError()) {
267 console.error('error patching device'); 274 console.error('error patching device');
268 throw remoting.Error.unexpected(); 275 throw remoting.Error.unexpected();
269 } 276 }
270 return responseAsGcdDevice(response); 277 return responseAsGcdDevice(response);
271 }); 278 });
272 }; 279 };
273 280
274 })(); 281 })();
OLDNEW
« no previous file with comments | « no previous file | remoting/webapp/crd/js/host_list_api_gcd_impl.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698