Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions src/Particle.js
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,149 @@ 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
});
}

/**
* 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
Expand Down
105 changes: 104 additions & 1 deletion test/Particle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -2313,6 +2316,106 @@ 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('.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 => {
Expand Down