Skip to content

Commit b59def1

Browse files
authored
Merge pull request #121 from particle-iot/feature/ch55034/configuration-and-location-service-methods
feature/ch55034/configuration-and-location-service-methods
2 parents aab878b + 37dd03f commit b59def1

File tree

2 files changed

+247
-1
lines changed

2 files changed

+247
-1
lines changed

src/Particle.js

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,149 @@ class Particle {
18851885
});
18861886
}
18871887

1888+
/**
1889+
* Get product configuration
1890+
* @param {Object} options Options for this API call
1891+
* @param {String} options.product Config for this product ID or slug
1892+
* @param {String} options.auth Access Token
1893+
* @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1894+
* @param {Object} [options.context] Request context
1895+
* @returns {Promise} A promise
1896+
*/
1897+
getProductConfiguration({ auth, product, headers, context }){
1898+
return this.get({
1899+
uri: `/v1/products/${product}/config`,
1900+
auth,
1901+
headers,
1902+
context
1903+
});
1904+
}
1905+
1906+
/**
1907+
* Get product configuration schema
1908+
* @param {Object} options Options for this API call
1909+
* @param {String} options.product Config for this product ID or slug
1910+
* @param {String} options.auth Access Token
1911+
* @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1912+
* @param {Object} [options.context] Request context
1913+
* @returns {Promise} A promise
1914+
*/
1915+
getProductConfigurationSchema({ auth, product, headers = {}, context }){
1916+
headers.accept = 'application/schema+json';
1917+
return this.get({
1918+
uri: `/v1/products/${product}/config`,
1919+
auth,
1920+
headers,
1921+
context
1922+
});
1923+
}
1924+
1925+
/**
1926+
* Set product configuration
1927+
* @param {Object} options Options for this API call
1928+
* @param {String} options.product Config for this product ID or slug
1929+
* @param {String} options.auth Access Token
1930+
* @param {Object} opitons.config Product configuration to update
1931+
* @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1932+
* @param {Object} [options.context] Request context
1933+
* @returns {Promise} A promise
1934+
*/
1935+
setProductConfiguration({ auth, product, config, headers, context }){
1936+
return this.put({
1937+
uri: `/v1/products/${product}/config`,
1938+
auth,
1939+
data: config,
1940+
headers,
1941+
context
1942+
});
1943+
}
1944+
1945+
/**
1946+
* Set product configuration for a specific device within the product
1947+
* @param {Object} options Options for this API call
1948+
* @param {String} options.product Config for this product ID or slug
1949+
* @param {String} options.auth Access Token
1950+
* @param {Object} opitons.config Product configuration to update
1951+
* @param {String} options.deviceId Device ID to access
1952+
* @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1953+
* @param {Object} [options.context] Request context
1954+
* @returns {Promise} A promise
1955+
*/
1956+
setProductDeviceConfiguration({ auth, product, deviceId, config, headers, context }){
1957+
return this.put({
1958+
uri: `/v1/products/${product}/config/${deviceId}`,
1959+
data: config,
1960+
auth,
1961+
headers,
1962+
context
1963+
});
1964+
}
1965+
1966+
/**
1967+
* Query location for devices within a product
1968+
* @param {Object} options Options for this API call
1969+
* @param {String} options.product Locations for this product ID or slug
1970+
* @param {String} options.auth Access Token
1971+
* @param {String} options.dateRange Start and end date in ISO8601 format, separated by comma, to query
1972+
* @param {String} options.rectBl Bottom left of the rectangular bounding box to query. Latitude and longitude separated by comma
1973+
* @param {String} options.rectTr Top right of the rectangular bounding box to query. Latitude and longitude separated by comma
1974+
* @param {String} options.deviceId Device ID prefix to include in the query
1975+
* @param {String} options.deviceName Device name prefix to include in the query
1976+
* @param {String} options.groups Array of group names to include in the query
1977+
* @param {String} options.page Page of results to display. Defaults to 1
1978+
* @param {String} options.perPage Number of results per page. Defaults to 20. Maximum of 100
1979+
* @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1980+
* @param {Object} [options.context] Request context
1981+
* @returns {Promise} A promise
1982+
*/
1983+
getProductLocations({ auth, product, dateRange, rectBl, rectTr, deviceId, deviceName, groups, page, perPage, headers, context }){
1984+
return this.get({
1985+
uri: `/v1/products/${product}/locations`,
1986+
query: {
1987+
date_range: dateRange,
1988+
rect_bl: rectBl,
1989+
rect_tr: rectTr,
1990+
device_id: deviceId,
1991+
device_name: deviceName,
1992+
groups,
1993+
page,
1994+
per_page: perPage
1995+
},
1996+
auth,
1997+
headers,
1998+
context
1999+
});
2000+
}
2001+
2002+
/**
2003+
* Query location for one device within a product
2004+
* @param {Object} options Options for this API call
2005+
* @param {String} options.product Locations for this product ID or slug
2006+
* @param {String} options.auth Access Token
2007+
* @param {String} options.dateRange Start and end date in ISO8601 format, separated by comma, to query
2008+
* @param {String} options.rectBl Bottom left of the rectangular bounding box to query. Latitude and longitude separated by comma
2009+
* @param {String} options.rectTr Top right of the rectangular bounding box to query. Latitude and longitude separated by comma
2010+
* @param {String} options.deviceId Device ID to query
2011+
* @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2012+
* @param {Object} [options.context] Request context
2013+
* @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2014+
* @param {Object} [options.context] Request context
2015+
* @returns {Promise} A promise
2016+
*/
2017+
getProductDeviceLocations({ auth, product, dateRange, rectBl, rectTr, deviceId, headers, context }){
2018+
return this.get({
2019+
uri: `/v1/products/${product}/locations/${deviceId}`,
2020+
query: {
2021+
date_range: dateRange,
2022+
rect_bl: rectBl,
2023+
rect_tr: rectTr
2024+
},
2025+
auth,
2026+
headers,
2027+
context
2028+
});
2029+
}
2030+
18882031
/**
18892032
* API URI to access a device
18902033
* @param {Object} options Options for this API call

test/Particle.spec.js

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ const props = {
9292
otp: '123456',
9393
mfaToken: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
9494
networkId: '65535',
95-
groups: ['foo', 'bar']
95+
groups: ['foo', 'bar'],
96+
dateRange: '2020-05-15T18:29:45.000Z,2020-05-19T18:29:45.000Z',
97+
rectBl: '56.185412,-4.049868',
98+
rectTr: '56.571537,-5.385920'
9699
};
97100

98101
const product = 'ze-product-v1';
@@ -2313,6 +2316,106 @@ describe('ParticleAPI', () => {
23132316
});
23142317
});
23152318

2319+
describe('.getProductConfiguration', () => {
2320+
it('generates request', () => {
2321+
return api.getProductConfiguration(propsWithProduct).then((results) => {
2322+
results.should.match({
2323+
method: 'get',
2324+
uri: `/v1/products/${product}/config`,
2325+
auth: props.auth
2326+
});
2327+
});
2328+
});
2329+
});
2330+
2331+
describe('.getProductConfigurationSchema', () => {
2332+
it('generates request', () => {
2333+
return api.getProductConfigurationSchema(propsWithProduct).then((results) => {
2334+
results.should.match({
2335+
method: 'get',
2336+
uri: `/v1/products/${product}/config`,
2337+
auth: props.auth,
2338+
headers: { 'accept': 'application/schema+json' }
2339+
});
2340+
});
2341+
});
2342+
});
2343+
2344+
describe('.setProductConfiguration', () => {
2345+
it('generates request', () => {
2346+
const p = Object.assign({ config: {
2347+
foo: 'bar'
2348+
} }, propsWithProduct);
2349+
return api.setProductConfiguration(p).then((results) => {
2350+
results.should.match({
2351+
method: 'put',
2352+
uri: `/v1/products/${product}/config`,
2353+
auth: props.auth,
2354+
data: {
2355+
foo: 'bar'
2356+
}
2357+
});
2358+
});
2359+
});
2360+
});
2361+
2362+
describe('.setProductDeviceConfiguration', () => {
2363+
it('generates request', () => {
2364+
const p = Object.assign({ config: {
2365+
foo: 'bar'
2366+
} }, propsWithProduct);
2367+
return api.setProductDeviceConfiguration(p).then((results) => {
2368+
results.should.match({
2369+
method: 'put',
2370+
uri: `/v1/products/${product}/config/${props.deviceId}`,
2371+
auth: props.auth,
2372+
data: {
2373+
foo: 'bar'
2374+
}
2375+
});
2376+
});
2377+
});
2378+
});
2379+
2380+
describe('.getProductLocations', () => {
2381+
it('generates request', () => {
2382+
return api.getProductLocations(propsWithProduct).then((results) => {
2383+
results.should.match({
2384+
method: 'get',
2385+
uri: `/v1/products/${product}/locations`,
2386+
auth: props.auth,
2387+
query: {
2388+
date_range: props.dateRange,
2389+
rect_bl: props.rectBl,
2390+
rect_tr: props.rectTr,
2391+
device_id: props.deviceId,
2392+
device_name: props.deviceName,
2393+
groups: props.groups,
2394+
page: props.page,
2395+
per_page: props.perPage
2396+
}
2397+
});
2398+
});
2399+
});
2400+
});
2401+
2402+
describe('.getProductDeviceLocations', () => {
2403+
it('generates request', () => {
2404+
return api.getProductDeviceLocations(propsWithProduct).then((results) => {
2405+
results.should.match({
2406+
method: 'get',
2407+
uri: `/v1/products/${product}/locations/${props.deviceId}`,
2408+
auth: props.auth,
2409+
query: {
2410+
date_range: props.dateRange,
2411+
rect_bl: props.rectBl,
2412+
rect_tr: props.rectTr
2413+
}
2414+
});
2415+
});
2416+
});
2417+
});
2418+
23162419
describe('.deleteUser', () => {
23172420
it('sends request to delete the current user', () => {
23182421
return api.deleteUser(props).then(result => {

0 commit comments

Comments
 (0)