-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathspaces.js
180 lines (169 loc) · 6.21 KB
/
spaces.js
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
* robin-js-sdk
* http://getrobin.com/
*
* Copyright (c) 2014 Robin Powered Inc.
* Licensed under the Apache v2 license.
* https://github.com/robinpowered/robin-js-sdk/blob/master/LICENSE
*
*/
var constants = require('../../util').constants;
module.exports = {
/**
* Get all spaces or a particular space identified by `spaceIdentifier`
* @param {String|Integer} spaceIdentifier A Robin space identifier
* @param {Object|undefined} params A querystring object
* @return {Function} A promise
*/
get: function (spaceIdentifier, params) {
var path = this.constructPath(constants.SPACES, spaceIdentifier);
return this.Core.GET(path, params);
},
/**
* Update a space
* @param {String|Integer} spaceIdentifier A Robin space identifier
* @param {Object} data A data object
* @return {Function} A promise
*/
update: function (spaceIdentifier, data) {
var path;
if (data) {
path = this.constructPath(constants.SPACES, spaceIdentifier);
return this.Core.PATCH(path, data);
} else {
return this.rejectRequest('Bad Request: Space data is required');
}
},
/**
* Delete a space
* @param {String|Integer} spaceIdentifier A Robin space identifier
* @return {Function} A promise
*/
delete: function (spaceIdentifier) {
var path;
if (spaceIdentifier) {
path = this.constructPath(constants.SPACES, spaceIdentifier);
return this.Core.DELETE(path);
} else {
return this.rejectRequest('Bad Request: A space identifier is required');
}
},
/**
* Space Devices
* @type {Object}
*/
devices: {
/**
* Get all the devices for a space or a particular device identified by `deviceIdentifier`
* @param {String|Integer} spaceIdentifier A Robin space identifier
* @param {String|Integer|undefined} deviceIdentifier A Robin device identifier
* @param {Object|undefined} params A querystring object
* @return {Function} A Promise
*/
get: function (spaceIdentifier, deviceIdentifier, params) {
var path;
if (spaceIdentifier) {
path = this.constructPath(constants.SPACES, spaceIdentifier, constants.DEVICES, deviceIdentifier);
return this.Core.GET(path, params);
} else {
return this.rejectRequest('Bad Request: A space identifier is required.');
}
},
/**
* Create a device in a space
* @param {String|Integer} spaceIdentifier A Robin space identifier
* @param {Object} data A data object
* @return {Function} A Promise
*/
create: function (spaceIdentifier, data) {
var path;
if (spaceIdentifier && data) {
path = this.constructPath(constants.SPACES, spaceIdentifier, constants.DEVICES);
return this.Core.POST(path, data);
} else {
return this.rejectRequest('Bad Request: A space identifier and device data are required');
}
},
/**
* Add a device to a space
* @param {String|Integer} spaceIdentifier A Robin space identifier
* @param {String|Integer} deviceIdentifier A Robin device identifier
* @return {Function} A Promise
*/
add: function (spaceIdentifier, deviceIdentifier) {
var path;
if (spaceIdentifier && deviceIdentifier) {
path = this.constructPath(constants.SPACES, spaceIdentifier, constants.DEVICES, deviceIdentifier);
return this.Core.PUT(path);
} else {
return this.rejectRequest('Bad Request: A space identifier and device identifier are required');
}
},
/**
* Delete a device from a space
* @param {String|Integer} spaceIdentifier A Robin space identifier
* @param {String|Integer} deviceIdentifier A Robin device identifier
* @return {Function} A Promise
*/
delete: function (spaceIdentifier, deviceIdentifier) {
var path;
if (spaceIdentifier && deviceIdentifier) {
path = this.constructPath(constants.SPACES, spaceIdentifier, constants.DEVICES, deviceIdentifier);
return this.Core.DELETE(path);
} else {
return this.rejectRequest('Bad Request: A space identifier and device identifier are required');
}
}
},
/**
* Space presence
* @type {Object}
*/
presence: {
/**
* Get all the presence for a space
* @param {String|Integer} spaceIdentifier A Robin space identifier
* @param {Object|undefined} params A querystring object
* @return {Function} A Promise
*/
get: function (spaceIdentifier, params) {
var path;
if (spaceIdentifier) {
path = this.constructPath(constants.SPACES, spaceIdentifier, constants.PRESENCE);
return this.Core.GET(path, params);
} else {
return this.rejectRequest('Bad Request: A space identifier is required.');
}
},
/**
* Add presence to a space
* @param {String|Integer} spaceIdentifier A Robin space identifier
* @param {Object} data A data payload
* @return {Function} A Promise
*/
add: function (spaceIdentifier, data) {
var path;
if (spaceIdentifier && data) {
path = this.constructPath(constants.SPACES, spaceIdentifier, constants.PRESENCE);
return this.Core.POST(path, data);
} else {
return this.rejectRequest('Bad Request: A space identifier and data object are required');
}
},
/**
* Delete a device from a space
* @param {String|Integer} spaceIdentifier A Robin space identifier
* @param {Object} data A data payload
* @return {Function} A Promise
*/
delete: function (spaceIdentifier, data) {
var path;
if (spaceIdentifier && data) {
path = this.constructPath(constants.SPACES, spaceIdentifier, constants.PRESENCE);
return this.Core.DELETE(path, data);
} else {
return this.rejectRequest('Bad Request: A space identifier and data object are required');
}
}
}
};