Commit 2ea3b0bdafac7470752c87c96d415a9c7fdb7706
Committed by
GitHub
1 parent
f8a31818
Add service methods to claim a device (#2391)
Showing
1 changed file
with
27 additions
and
1 deletions
... | ... | @@ -43,7 +43,9 @@ function DeviceService($http, $q, $window, userService, attributeService, custom |
43 | 43 | sendTwoWayRpcCommand: sendTwoWayRpcCommand, |
44 | 44 | findByQuery: findByQuery, |
45 | 45 | getDeviceTypes: getDeviceTypes, |
46 | - findByName: findByName | |
46 | + findByName: findByName, | |
47 | + claimDevice: claimDevice, | |
48 | + unclaimDevice: unclaimDevice | |
47 | 49 | }; |
48 | 50 | |
49 | 51 | return service; |
... | ... | @@ -332,4 +334,28 @@ function DeviceService($http, $q, $window, userService, attributeService, custom |
332 | 334 | }); |
333 | 335 | return deferred.promise; |
334 | 336 | } |
337 | + | |
338 | + function claimDevice(deviceName, deviceSecret, config) { | |
339 | + deviceSecret = deviceSecret || {}; | |
340 | + config = config || {}; | |
341 | + const deferred = $q.defer(); | |
342 | + const url = '/api/customer/device/' + deviceName + '/claim'; | |
343 | + $http.post(url, deviceSecret, config).then(function success(response) { | |
344 | + deferred.resolve(response.data); | |
345 | + }, function fail(rejection) { | |
346 | + deferred.reject(rejection); | |
347 | + }); | |
348 | + return deferred.promise; | |
349 | + } | |
350 | + | |
351 | + function unclaimDevice(deviceName) { | |
352 | + const deferred = $q.defer(); | |
353 | + const url = '/api/customer/device/' + deviceName + '/claim'; | |
354 | + $http.delete(url).then(function success(response) { | |
355 | + deferred.resolve(response.data); | |
356 | + }, function fail(rejection) { | |
357 | + deferred.reject(rejection); | |
358 | + }); | |
359 | + return deferred.promise; | |
360 | + } | |
335 | 361 | } | ... | ... |