Skip to content

Commit 4163074

Browse files
busticatedsuda
authored andcommitted
add configuration service endpoints
1 parent aab878b commit 4163074

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-0
lines changed

src/Particle.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,84 @@ 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+
18881966
/**
18891967
* API URI to access a device
18901968
* @param {Object} options Options for this API call

test/Particle.spec.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,6 +2313,67 @@ describe('ParticleAPI', () => {
23132313
});
23142314
});
23152315

2316+
describe('.getProductConfiguration', () => {
2317+
it('generates request', () => {
2318+
return api.getProductConfiguration(propsWithProduct).then((results) => {
2319+
results.should.match({
2320+
method: 'get',
2321+
uri: `/v1/products/${product}/config`,
2322+
auth: props.auth
2323+
});
2324+
});
2325+
});
2326+
});
2327+
2328+
describe('.getProductConfigurationSchema', () => {
2329+
it('generates request', () => {
2330+
return api.getProductConfigurationSchema(propsWithProduct).then((results) => {
2331+
results.should.match({
2332+
method: 'get',
2333+
uri: `/v1/products/${product}/config`,
2334+
auth: props.auth,
2335+
headers: { 'accept': 'application/schema+json' }
2336+
});
2337+
});
2338+
});
2339+
});
2340+
2341+
describe('.setProductConfiguration', () => {
2342+
it('generates request', () => {
2343+
const p = Object.assign({ config: {
2344+
foo: 'bar'
2345+
} }, propsWithProduct);
2346+
return api.setProductConfiguration(p).then((results) => {
2347+
results.should.match({
2348+
method: 'put',
2349+
uri: `/v1/products/${product}/config`,
2350+
auth: props.auth,
2351+
data: {
2352+
foo: 'bar'
2353+
}
2354+
});
2355+
});
2356+
});
2357+
});
2358+
2359+
describe('.setProductDeviceConfiguration', () => {
2360+
it('generates request', () => {
2361+
const p = Object.assign({ config: {
2362+
foo: 'bar'
2363+
} }, propsWithProduct);
2364+
return api.setProductDeviceConfiguration(p).then((results) => {
2365+
results.should.match({
2366+
method: 'put',
2367+
uri: `/v1/products/${product}/config/${props.deviceId}`,
2368+
auth: props.auth,
2369+
data: {
2370+
foo: 'bar'
2371+
}
2372+
});
2373+
});
2374+
});
2375+
});
2376+
23162377
describe('.deleteUser', () => {
23172378
it('sends request to delete the current user', () => {
23182379
return api.deleteUser(props).then(result => {

0 commit comments

Comments
 (0)