From 1221e078365336b905402bdd10d0c1d72977b289 Mon Sep 17 00:00:00 2001 From: Wojtek Siudzinski Date: Mon, 1 Jun 2020 16:12:25 +0200 Subject: [PATCH 1/2] Expose getProductDeviceConfiguration and getProductDeviceConfigurationSchema --- .gitignore | 1 + src/Particle.js | 39 +++++++++++++++++++++++++++++++++++++++ test/Particle.spec.js | 25 +++++++++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/.gitignore b/.gitignore index 0619f62e..fbfb4da8 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ node_modules lib/ /.idea *.tgz +.vscode \ No newline at end of file diff --git a/src/Particle.js b/src/Particle.js index 90ff5039..933866d3 100644 --- a/src/Particle.js +++ b/src/Particle.js @@ -1922,6 +1922,45 @@ class Particle { }); } + /** + * Get product device's 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 {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 + */ + getProductDeviceConfiguration({ auth, product, deviceId, headers, context }){ + return this.get({ + uri: `/v1/products/${product}/config/${deviceId}`, + auth, + headers, + context + }); + } + + /** + * Get product device's 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 {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 + */ + getProductDeviceConfigurationSchema({ auth, product, deviceId, headers = {}, context }){ + headers.accept = 'application/schema+json'; + return this.get({ + uri: `/v1/products/${product}/config/${deviceId}`, + auth, + headers, + context + }); + } + /** * Set product configuration * @param {Object} options Options for this API call diff --git a/test/Particle.spec.js b/test/Particle.spec.js index b7bde351..3c105818 100644 --- a/test/Particle.spec.js +++ b/test/Particle.spec.js @@ -2341,6 +2341,31 @@ describe('ParticleAPI', () => { }); }); + describe('.getProductDeviceConfiguration', () => { + it('generates request', () => { + return api.getProductDeviceConfiguration(propsWithProduct).then((results) => { + results.should.match({ + method: 'get', + uri: `/v1/products/${product}/config/${props.deviceId}`, + auth: props.auth + }); + }); + }); + }); + + describe('.getProductDeviceConfigurationSchema', () => { + it('generates request', () => { + return api.getProductDeviceConfigurationSchema(propsWithProduct).then((results) => { + results.should.match({ + method: 'get', + uri: `/v1/products/${product}/config/${props.deviceId}`, + auth: props.auth, + headers: { 'accept': 'application/schema+json' } + }); + }); + }); + }); + describe('.setProductConfiguration', () => { it('generates request', () => { const p = Object.assign({ config: { From e05e5e9a3537e3e8901308f00c8a8883ec282a78 Mon Sep 17 00:00:00 2001 From: Wojtek Siudzinski Date: Mon, 1 Jun 2020 19:18:55 +0200 Subject: [PATCH 2/2] Update src/Particle.js Co-authored-by: Matthew Mirande --- src/Particle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Particle.js b/src/Particle.js index 933866d3..3e664a28 100644 --- a/src/Particle.js +++ b/src/Particle.js @@ -1951,7 +1951,7 @@ class Particle { * @param {Object} [options.context] Request context * @returns {Promise} A promise */ - getProductDeviceConfigurationSchema({ auth, product, deviceId, headers = {}, context }){ + getProductDeviceConfigurationSchema({ auth, product, deviceId, headers, context }){ headers.accept = 'application/schema+json'; return this.get({ uri: `/v1/products/${product}/config/${deviceId}`,