ResourceLinks.js
1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'use strict';
const resourceLinksApi = require('./http/endpoints/resourcelinks')
, ResourceLink = require('@peter-murray/hue-bridge-model').model.ResourceLink
, ApiDefinition = require('./http/ApiDefinition.js')
;
/**
* @tpedef {import('@peter-murray/hue-bridge-model').model.ResourceLink} ResourceLink
* @type {ResourceLinks}
*/
module.exports = class ResourceLinks extends ApiDefinition {
constructor(hueApi) {
super(hueApi);
}
/**
* @returns {Promise<ResourceLink[]>}
*/
getAll() {
return this.execute(resourceLinksApi.getAll);
}
/**
* @param id {string | ResourceLink} The resource link id or resource link to retrieve from the bridge.
* @returns {Promise<ResourceLink>}
*/
getResourceLink(id) {
return this.execute(resourceLinksApi.getResourceLink, {id: id});
}
/**
* @param name {string}
* @returns {Promise<ResourceLink[]>}
*/
getResourceLinkByName(name) {
return this.getAll()
.then(resourceLinks => {
return resourceLinks.filter(resourceLink => resourceLink.name === name);
});
}
/**
* @param resourceLink {ResourceLink}
* @returns {Promise<ResourceLink>}
*/
createResourceLink(resourceLink) {
const self = this;
return self.execute(resourceLinksApi.createResourceLink, {resourceLink: resourceLink})
.then(result => {
return self.getResourceLink(result.id);
});
}
/**
* @param {string | ResourceLink} id
* @returns {Promise<boolean>}
*/
deleteResourceLink(id) {
let resourceLinkId = id;
if (id instanceof ResourceLink) {
resourceLinkId = id.id;
}
return this.execute(resourceLinksApi.deleteResourceLink, {id: resourceLinkId});
}
/**
* @param {ResourceLink} resourceLink
* @returns {Promise<Object>}
*/
updateResourceLink(resourceLink) {
return this.execute(resourceLinksApi.updateResourceLink, {id: resourceLink.id, resourceLink: resourceLink});
}
};