-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlocations.js
116 lines (109 loc) · 3.85 KB
/
locations.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
/*
* 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 the locations or a particular location identified by `identifier`
* @param {String|Integer|undefined} identifier A location identifier
* @param {Object} params A querystring object
* @return {Function} A promise
*/
get: function (identifier, params) {
var path = this.constructPath(constants.LOCATIONS, identifier);
return this.Core.GET(path, params);
},
/**
* [update description]
* @param {[type]} identifier [description]
* @param {[type]} data [description]
* @return {[type]} [description]
*/
update: function (identifier, data) {
var path;
if (identifier && data) {
path = this.constructPath(constants.LOCATIONS, identifier);
return this.Core.PATCH(path, data);
} else {
return this.rejectRequest('Bad Request. A location identifier and a data object are required');
}
},
/**
* Delete a location
* @param {String|Integer} identifier A Robin location identifier
* @return {Function} A Promise
*/
delete: function (identifier) {
var path;
if (identifier) {
path = this.constructPath(constants.LOCATIONS, identifier);
return this.Core.DELETE(path);
} else {
return this.rejectRequest('Bad Request: A location identifier is required.');
}
},
/**
* Location Spaces
* @type {Object}
*/
spaces: {
/**
* Get all the spaces in a location or a particular space in a location identified by `spaceIdentifier`
* @param {String|Integer} locationIdentifier A Robin channel identifier
* @param {String|Integer|undefined} spaceIdentifier A Robin channel data point identifier
* @param {Object|undefined} params A querystring object
* @return {Function} A Promise
*/
get: function (locationIdentifier, spaceIdentifier, params) {
var path;
if (locationIdentifier) {
path = this.constructPath(constants.LOCATIONS, locationIdentifier, constants.SPACES, spaceIdentifier);
return this.Core.GET(path, params);
} else {
return this.rejectRequest('Bad Request: A location identifier is required.');
}
},
/**
* Add space to a location
* @param {String|Integer} locationIdentifier A Robin location identifier
* @param {Object} data A querystring object
* @return {Function} A Promise
*/
add: function (locationIdentifier, data) {
var path;
if (locationIdentifier) {
path = this.constructPath(constants.LOCATIONS, locationIdentifier, constants.SPACES);
return this.Core.POST(path, data);
} else {
return this.rejectRequest('Bad Request: A location identifier is required.');
}
}
},
/**
* Location Presence
* @type {Object}
*/
presence: {
/**
* Get all the current presence for all the spaces in a location
* @param {String|Integer} locationIdentifier A Robin channel identifier
* @param {Object|undefined} params A querystring object
* @return {Function} A Promise
*/
get: function (locationIdentifier, params) {
var path;
if (locationIdentifier) {
path = this.constructPath(constants.LOCATIONS, locationIdentifier, constants.PRESENCE);
return this.Core.GET(path, params);
} else {
return this.rejectRequest('Bad Request: A location identifier is required.');
}
}
}
};