Skip to content

Commit 75c9b7c

Browse files
authored
Merge pull request #122 from particle-iot/feature/get-product-device-config
Expose getProductDeviceConfiguration and getProductDeviceConfigurationSchema
2 parents 6012bdb + e05e5e9 commit 75c9b7c

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ node_modules
1111
lib/
1212
/.idea
1313
*.tgz
14+
.vscode

src/Particle.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,45 @@ class Particle {
19221922
});
19231923
}
19241924

1925+
/**
1926+
* Get product device's 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 {String} options.deviceId Device ID to access
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+
getProductDeviceConfiguration({ auth, product, deviceId, headers, context }){
1936+
return this.get({
1937+
uri: `/v1/products/${product}/config/${deviceId}`,
1938+
auth,
1939+
headers,
1940+
context
1941+
});
1942+
}
1943+
1944+
/**
1945+
* Get product device's configuration schema
1946+
* @param {Object} options Options for this API call
1947+
* @param {String} options.product Config for this product ID or slug
1948+
* @param {String} options.auth Access Token
1949+
* @param {String} options.deviceId Device ID to access
1950+
* @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1951+
* @param {Object} [options.context] Request context
1952+
* @returns {Promise} A promise
1953+
*/
1954+
getProductDeviceConfigurationSchema({ auth, product, deviceId, headers, context }){
1955+
headers.accept = 'application/schema+json';
1956+
return this.get({
1957+
uri: `/v1/products/${product}/config/${deviceId}`,
1958+
auth,
1959+
headers,
1960+
context
1961+
});
1962+
}
1963+
19251964
/**
19261965
* Set product configuration
19271966
* @param {Object} options Options for this API call

test/Particle.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,6 +2341,31 @@ describe('ParticleAPI', () => {
23412341
});
23422342
});
23432343

2344+
describe('.getProductDeviceConfiguration', () => {
2345+
it('generates request', () => {
2346+
return api.getProductDeviceConfiguration(propsWithProduct).then((results) => {
2347+
results.should.match({
2348+
method: 'get',
2349+
uri: `/v1/products/${product}/config/${props.deviceId}`,
2350+
auth: props.auth
2351+
});
2352+
});
2353+
});
2354+
});
2355+
2356+
describe('.getProductDeviceConfigurationSchema', () => {
2357+
it('generates request', () => {
2358+
return api.getProductDeviceConfigurationSchema(propsWithProduct).then((results) => {
2359+
results.should.match({
2360+
method: 'get',
2361+
uri: `/v1/products/${product}/config/${props.deviceId}`,
2362+
auth: props.auth,
2363+
headers: { 'accept': 'application/schema+json' }
2364+
});
2365+
});
2366+
});
2367+
});
2368+
23442369
describe('.setProductConfiguration', () => {
23452370
it('generates request', () => {
23462371
const p = Object.assign({ config: {

0 commit comments

Comments
 (0)