| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * REST API for host-list management. | 7 * REST API for host-list management. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 /** @suppress {duplicate} */ | 10 /** @suppress {duplicate} */ |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 * Update the information for a host. | 46 * Update the information for a host. |
| 47 * | 47 * |
| 48 * @param {function():void} onDone | 48 * @param {function():void} onDone |
| 49 * @param {function(!remoting.Error):void} onError | 49 * @param {function(!remoting.Error):void} onError |
| 50 * @param {string} hostId | 50 * @param {string} hostId |
| 51 * @param {string} hostName | 51 * @param {string} hostName |
| 52 * @param {string} hostPublicKey | 52 * @param {string} hostPublicKey |
| 53 */ | 53 */ |
| 54 remoting.HostListApiImpl.prototype.put = | 54 remoting.HostListApiImpl.prototype.put = |
| 55 function(hostId, hostName, hostPublicKey, onDone, onError) { | 55 function(hostId, hostName, hostPublicKey, onDone, onError) { |
| 56 /** @param {string} token */ | 56 new remoting.Xhr({ |
| 57 var onToken = function(token) { | 57 method: 'PUT', |
| 58 var newHostDetails = { | 58 url: remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts/' + hostId, |
| 59 jsonContent: { |
| 59 'data': { | 60 'data': { |
| 60 'hostId': hostId, | 61 'hostId': hostId, |
| 61 'hostName': hostName, | 62 'hostName': hostName, |
| 62 'publicKey': hostPublicKey | 63 'publicKey': hostPublicKey |
| 63 } | 64 } |
| 64 }; | 65 }, |
| 65 new remoting.Xhr({ | 66 useIdentity: true, |
| 66 method: 'PUT', | 67 ignoreErrors: [] |
| 67 url: remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts/' + hostId, | 68 }).start().then(onDone, remoting.Error.handler(onError)); |
| 68 jsonContent: newHostDetails, | |
| 69 oauthToken: token | |
| 70 }).start().then(remoting.Xhr.defaultResponse(onDone, onError)); | |
| 71 }; | |
| 72 remoting.identity.getToken().then(onToken, remoting.Error.handler(onError)); | |
| 73 }; | 69 }; |
| 74 | 70 |
| 75 /** | 71 /** |
| 76 * Delete a host. | 72 * Delete a host. |
| 77 * | 73 * |
| 78 * @param {function():void} onDone | 74 * @param {function():void} onDone |
| 79 * @param {function(!remoting.Error):void} onError | 75 * @param {function(!remoting.Error):void} onError |
| 80 * @param {string} hostId | 76 * @param {string} hostId |
| 81 */ | 77 */ |
| 82 remoting.HostListApiImpl.prototype.remove = function(hostId, onDone, onError) { | 78 remoting.HostListApiImpl.prototype.remove = function(hostId, onDone, onError) { |
| 83 /** @param {string} token */ | 79 new remoting.Xhr({ |
| 84 var onToken = function(token) { | 80 method: 'DELETE', |
| 85 new remoting.Xhr({ | 81 url: remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts/' + hostId, |
| 86 method: 'DELETE', | 82 useIdentity: true, |
| 87 url: remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts/' + hostId, | 83 ignoreErrors: [remoting.Error.Tag.NOT_FOUND] |
| 88 oauthToken: token | 84 }).start().then(onDone, remoting.Error.handler(onError)); |
| 89 }).start().then(remoting.Xhr.defaultResponse( | |
| 90 onDone, onError, [remoting.Error.Tag.NOT_FOUND])); | |
| 91 }; | |
| 92 remoting.identity.getToken().then(onToken, remoting.Error.handler(onError)); | |
| 93 }; | 85 }; |
| 94 | 86 |
| 95 /** | 87 /** |
| 96 * Handle the results of the host list request. A success response will | 88 * Handle the results of the host list request. A success response will |
| 97 * include a JSON-encoded list of host descriptions, which is parsed and | 89 * include a JSON-encoded list of host descriptions, which is parsed and |
| 98 * passed to the callback. | 90 * passed to the callback. |
| 99 * | 91 * |
| 100 * @param {function(Array<remoting.Host>):void} onDone | 92 * @param {function(Array<remoting.Host>):void} onDone |
| 101 * @param {function(!remoting.Error):void} onError | 93 * @param {function(!remoting.Error):void} onError |
| 102 * @param {!remoting.Xhr.Response} response | 94 * @param {!remoting.Xhr.Response} response |
| (...skipping 29 matching lines...) Expand all Loading... |
| 132 } | 124 } |
| 133 } else { | 125 } else { |
| 134 onError(remoting.Error.fromHttpStatus(response.status)); | 126 onError(remoting.Error.fromHttpStatus(response.status)); |
| 135 } | 127 } |
| 136 }; | 128 }; |
| 137 | 129 |
| 138 /** @type {remoting.HostListApi} */ | 130 /** @type {remoting.HostListApi} */ |
| 139 remoting.hostListApi = new remoting.HostListApiImpl(); | 131 remoting.hostListApi = new remoting.HostListApiImpl(); |
| 140 | 132 |
| 141 })(); | 133 })(); |
| OLD | NEW |