Skip to content

Commit

Permalink
Add parameters for pagination and filtering by device type
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeuz committed Feb 22, 2019
1 parent 767b099 commit 4ada7d4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
17 changes: 11 additions & 6 deletions src/Particle.js
Original file line number Diff line number Diff line change
Expand Up @@ -1359,12 +1359,14 @@ class Particle {
* List all mesh networks
* @param {Object} options Options for this API call
* @param {String} options.auth Access token
* @param {Number} [options.page] Current page of results
* @param {Number} [options.perPage] Records per page
* @param {Object} [options.context] Request context
* @return {Promise<Object>}
*/
listMeshNetworks({ auth, context }) {
// TODO: Pagination
return this.get('/v1/networks', auth, undefined, context);
listMeshNetworks({ auth, context, page, perPage }) {
const query = page ? { page, per_page: perPage } : undefined;
return this.get('/v1/networks', auth, query, context);
}

/**
Expand Down Expand Up @@ -1424,12 +1426,15 @@ class Particle {
* @param {Object} options Options for this API call
* @param {String} options.networkId Network ID or name
* @param {String} options.auth Access token
* @param {Number} [options.role] Device role: 'gateway' or 'node'
* @param {Number} [options.page] Current page of results
* @param {Number} [options.perPage] Records per page
* @param {Object} [options.context] Request context
* @return {Promise<Object>}
*/
listMeshNetworkDevices({ networkId, auth, context }) {
// TODO: Pagination and filtering
return this.get(`/v1/networks/${networkId}/devices`, auth, undefined, context);
listMeshNetworkDevices({ networkId, auth, role, page, perPage, context }) {
const query = (role || page) ? { role, page, per_page: perPage } : undefined;
return this.get(`/v1/networks/${networkId}/devices`, auth, query, context);
}


Expand Down
16 changes: 13 additions & 3 deletions test/Particle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1864,7 +1864,11 @@ describe('ParticleAPI', () => {
results.should.match({
method: 'get',
uri: '/v1/networks',
auth: props.auth
auth: props.auth,
query: {
page: props.page,
per_page: props.perPage
}
});
});
});
Expand Down Expand Up @@ -1933,11 +1937,17 @@ describe('ParticleAPI', () => {

describe('.listMeshNetworkDevices', () => {
it('generates request', () => {
return api.listMeshNetworkDevices(props).then((results) => {
const p = Object.assign({ role: 'node' }, props);
return api.listMeshNetworkDevices(p).then((results) => {
results.should.match({
method: 'get',
uri: `/v1/networks/${props.networkId}/devices`,
auth: props.auth
auth: p.auth,
query: {
role: p.role,
page: p.page,
per_page: p.perPage
}
});
});
});
Expand Down

0 comments on commit 4ada7d4

Please sign in to comment.