From 4163074de43dfa620a3842dba967f96a4e4a298f Mon Sep 17 00:00:00 2001 From: busticated Date: Tue, 19 May 2020 20:03:28 -0700 Subject: [PATCH 1/2] add configuration service endpoints --- src/Particle.js | 78 +++++++++++++++++++++++++++++++++++++++++++ test/Particle.spec.js | 61 +++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) diff --git a/src/Particle.js b/src/Particle.js index 78dab093..14bfc53e 100644 --- a/src/Particle.js +++ b/src/Particle.js @@ -1885,6 +1885,84 @@ class Particle { }); } + /** + * Get product configuration + * @param {Object} options Options for this API call + * @param {String} options.product Config for this product ID or slug + * @param {String} options.auth Access Token + * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers. + * @param {Object} [options.context] Request context + * @returns {Promise} A promise + */ + getProductConfiguration({ auth, product, headers, context }){ + return this.get({ + uri: `/v1/products/${product}/config`, + auth, + headers, + context + }); + } + + /** + * Get product configuration schema + * @param {Object} options Options for this API call + * @param {String} options.product Config for this product ID or slug + * @param {String} options.auth Access Token + * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers. + * @param {Object} [options.context] Request context + * @returns {Promise} A promise + */ + getProductConfigurationSchema({ auth, product, headers = {}, context }){ + headers.accept = 'application/schema+json'; + return this.get({ + uri: `/v1/products/${product}/config`, + auth, + headers, + context + }); + } + + /** + * Set product configuration + * @param {Object} options Options for this API call + * @param {String} options.product Config for this product ID or slug + * @param {String} options.auth Access Token + * @param {Object} opitons.config Product configuration to update + * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers. + * @param {Object} [options.context] Request context + * @returns {Promise} A promise + */ + setProductConfiguration({ auth, product, config, headers, context }){ + return this.put({ + uri: `/v1/products/${product}/config`, + auth, + data: config, + headers, + context + }); + } + + /** + * Set product configuration for a specific device within the product + * @param {Object} options Options for this API call + * @param {String} options.product Config for this product ID or slug + * @param {String} options.auth Access Token + * @param {Object} opitons.config Product configuration to update + * @param {String} options.deviceId Device ID to access + * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers. + * @param {Object} [options.context] Request context + * @returns {Promise} A promise + */ + setProductDeviceConfiguration({ auth, product, deviceId, config, headers, context }){ + return this.put({ + uri: `/v1/products/${product}/config/${deviceId}`, + data: config, + auth, + headers, + context + }); + } + /** * API URI to access a device * @param {Object} options Options for this API call diff --git a/test/Particle.spec.js b/test/Particle.spec.js index 58911a9c..141c5135 100644 --- a/test/Particle.spec.js +++ b/test/Particle.spec.js @@ -2313,6 +2313,67 @@ describe('ParticleAPI', () => { }); }); + describe('.getProductConfiguration', () => { + it('generates request', () => { + return api.getProductConfiguration(propsWithProduct).then((results) => { + results.should.match({ + method: 'get', + uri: `/v1/products/${product}/config`, + auth: props.auth + }); + }); + }); + }); + + describe('.getProductConfigurationSchema', () => { + it('generates request', () => { + return api.getProductConfigurationSchema(propsWithProduct).then((results) => { + results.should.match({ + method: 'get', + uri: `/v1/products/${product}/config`, + auth: props.auth, + headers: { 'accept': 'application/schema+json' } + }); + }); + }); + }); + + describe('.setProductConfiguration', () => { + it('generates request', () => { + const p = Object.assign({ config: { + foo: 'bar' + } }, propsWithProduct); + return api.setProductConfiguration(p).then((results) => { + results.should.match({ + method: 'put', + uri: `/v1/products/${product}/config`, + auth: props.auth, + data: { + foo: 'bar' + } + }); + }); + }); + }); + + describe('.setProductDeviceConfiguration', () => { + it('generates request', () => { + const p = Object.assign({ config: { + foo: 'bar' + } }, propsWithProduct); + return api.setProductDeviceConfiguration(p).then((results) => { + results.should.match({ + method: 'put', + uri: `/v1/products/${product}/config/${props.deviceId}`, + auth: props.auth, + data: { + foo: 'bar' + } + }); + }); + }); + }); + describe('.deleteUser', () => { it('sends request to delete the current user', () => { return api.deleteUser(props).then(result => { From 37dd03fdc1d16b1544d8233f5a1c242392e2b35c Mon Sep 17 00:00:00 2001 From: busticated Date: Tue, 19 May 2020 20:08:19 -0700 Subject: [PATCH 2/2] add location service endpoint --- src/Particle.js | 65 +++++++++++++++++++++++++++++++++++++++++++ test/Particle.spec.js | 44 ++++++++++++++++++++++++++++- 2 files changed, 108 insertions(+), 1 deletion(-) diff --git a/src/Particle.js b/src/Particle.js index 14bfc53e..90ff5039 100644 --- a/src/Particle.js +++ b/src/Particle.js @@ -1963,6 +1963,71 @@ class Particle { }); } + /** + * Query location for devices within a product + * @param {Object} options Options for this API call + * @param {String} options.product Locations for this product ID or slug + * @param {String} options.auth Access Token + * @param {String} options.dateRange Start and end date in ISO8601 format, separated by comma, to query + * @param {String} options.rectBl Bottom left of the rectangular bounding box to query. Latitude and longitude separated by comma + * @param {String} options.rectTr Top right of the rectangular bounding box to query. Latitude and longitude separated by comma + * @param {String} options.deviceId Device ID prefix to include in the query + * @param {String} options.deviceName Device name prefix to include in the query + * @param {String} options.groups Array of group names to include in the query + * @param {String} options.page Page of results to display. Defaults to 1 + * @param {String} options.perPage Number of results per page. Defaults to 20. Maximum of 100 + * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers. + * @param {Object} [options.context] Request context + * @returns {Promise} A promise + */ + getProductLocations({ auth, product, dateRange, rectBl, rectTr, deviceId, deviceName, groups, page, perPage, headers, context }){ + return this.get({ + uri: `/v1/products/${product}/locations`, + query: { + date_range: dateRange, + rect_bl: rectBl, + rect_tr: rectTr, + device_id: deviceId, + device_name: deviceName, + groups, + page, + per_page: perPage + }, + auth, + headers, + context + }); + } + + /** + * Query location for one device within a product + * @param {Object} options Options for this API call + * @param {String} options.product Locations for this product ID or slug + * @param {String} options.auth Access Token + * @param {String} options.dateRange Start and end date in ISO8601 format, separated by comma, to query + * @param {String} options.rectBl Bottom left of the rectangular bounding box to query. Latitude and longitude separated by comma + * @param {String} options.rectTr Top right of the rectangular bounding box to query. Latitude and longitude separated by comma + * @param {String} options.deviceId Device ID to query + * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers. + * @param {Object} [options.context] Request context + * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers. + * @param {Object} [options.context] Request context + * @returns {Promise} A promise + */ + getProductDeviceLocations({ auth, product, dateRange, rectBl, rectTr, deviceId, headers, context }){ + return this.get({ + uri: `/v1/products/${product}/locations/${deviceId}`, + query: { + date_range: dateRange, + rect_bl: rectBl, + rect_tr: rectTr + }, + auth, + headers, + context + }); + } + /** * API URI to access a device * @param {Object} options Options for this API call diff --git a/test/Particle.spec.js b/test/Particle.spec.js index 141c5135..b7bde351 100644 --- a/test/Particle.spec.js +++ b/test/Particle.spec.js @@ -92,7 +92,10 @@ const props = { otp: '123456', mfaToken: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', networkId: '65535', - groups: ['foo', 'bar'] + groups: ['foo', 'bar'], + dateRange: '2020-05-15T18:29:45.000Z,2020-05-19T18:29:45.000Z', + rectBl: '56.185412,-4.049868', + rectTr: '56.571537,-5.385920' }; const product = 'ze-product-v1'; @@ -2374,6 +2377,45 @@ describe('ParticleAPI', () => { }); }); + describe('.getProductLocations', () => { + it('generates request', () => { + return api.getProductLocations(propsWithProduct).then((results) => { + results.should.match({ + method: 'get', + uri: `/v1/products/${product}/locations`, + auth: props.auth, + query: { + date_range: props.dateRange, + rect_bl: props.rectBl, + rect_tr: props.rectTr, + device_id: props.deviceId, + device_name: props.deviceName, + groups: props.groups, + page: props.page, + per_page: props.perPage + } + }); + }); + }); + }); + + describe('.getProductDeviceLocations', () => { + it('generates request', () => { + return api.getProductDeviceLocations(propsWithProduct).then((results) => { + results.should.match({ + method: 'get', + uri: `/v1/products/${product}/locations/${props.deviceId}`, + auth: props.auth, + query: { + date_range: props.dateRange, + rect_bl: props.rectBl, + rect_tr: props.rectTr + } + }); + }); + }); + }); + describe('.deleteUser', () => { it('sends request to delete the current user', () => { return api.deleteUser(props).then(result => {