Skip to content

Commit 250de2f

Browse files
Merge pull request #178 from particle-iot/feature/sc-124018/particle-api-js-add-versions-api
feat: [sc-124018] Add Ledger Instance Versions Functions
2 parents 3d09990 + fd61ed5 commit 250de2f

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

src/Particle.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,6 +2550,57 @@ class Particle {
25502550
});
25512551
}
25522552

2553+
/**
2554+
* List ledger instance versions
2555+
*
2556+
* @param {Object} options The options for the ledger instance.
2557+
* @param {Auth} [options.auth] The access token or basic auth object. Can be ignored if provided in constructor
2558+
* @param {string} [options.org] The Organization ID or slug. If not provided, the request will go to your sandbox account.
2559+
* @param {string} options.ledgerName Ledger name.
2560+
* @param {string} options.scopeValue Scope value.
2561+
* @param {string} [options.replacedBefore] ISO date string to filter to instances replaced before this time
2562+
* @param {string} [options.replacedAfter] ISO date string to filter to instances replaced after this time
2563+
* @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2564+
* @param {Object} [options.context] Request context
2565+
*
2566+
* @returns {Promise<RequestResponse>} A promise that resolves to an array of ledger instance data.
2567+
*/
2568+
listLedgerInstanceVersions({ auth, org, ledgerName, scopeValue, replacedBefore, replacedAfter, headers, context }) {
2569+
return this.get({
2570+
uri: this._namespacedPath(org, `ledgers/${ledgerName}/instances/${scopeValue}/versions`),
2571+
query: {
2572+
replaced_before: replacedBefore,
2573+
replaced_after: replacedAfter
2574+
},
2575+
auth,
2576+
headers,
2577+
context
2578+
});
2579+
}
2580+
2581+
/**
2582+
* Get specific ledger instance version
2583+
*
2584+
* @param {Object} options The options for the ledger instance.
2585+
* @param {Auth} [options.auth] The access token or basic auth object. Can be ignored if provided in constructor
2586+
* @param {string} [options.org] The Organization ID or slug. If not provided, the request will go to your sandbox account.
2587+
* @param {string} options.ledgerName Ledger name.
2588+
* @param {string} options.scopeValue Scope value.
2589+
* @param {string} options.version Version of the ledger instance
2590+
* @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2591+
* @param {Object} [options.context] Request context
2592+
*
2593+
* @returns {Promise<RequestResponse>} A promise that resolves to the specified ledger instance data.
2594+
*/
2595+
getLedgerInstanceVersion({ auth, org, ledgerName, scopeValue, version, headers, context }) {
2596+
return this.get({
2597+
uri: this._namespacedPath(org, `ledgers/${ledgerName}/instances/${scopeValue}/versions/${version}`),
2598+
auth,
2599+
headers,
2600+
context
2601+
});
2602+
}
2603+
25532604
/**
25542605
* Set default auth token that will be used in each method if `auth` is not provided
25552606
* @param {Auth} auth The access token or basic auth object

test/Particle.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2901,6 +2901,30 @@ describe('ParticleAPI', () => {
29012901
});
29022902
});
29032903
});
2904+
2905+
describe('listLedgerInstanceVersions', () => {
2906+
it('generates request', () => {
2907+
return api.listLedgerInstanceVersions(propsWithOrg).then((results) => {
2908+
results.should.match({
2909+
method: 'get',
2910+
uri: `/v1/orgs/${org}/ledgers/${props.ledgerName}/instances/${props.scopeValue}/versions`,
2911+
auth: props.auth
2912+
});
2913+
});
2914+
});
2915+
});
2916+
2917+
describe('.getLedgerInstanceVersion', () => {
2918+
it('generates request', () => {
2919+
return api.getLedgerInstanceVersion(propsWithOrg).then((results) => {
2920+
results.should.match({
2921+
method: 'get',
2922+
uri: `/v1/orgs/${org}/ledgers/${props.ledgerName}/instances/${props.scopeValue}/versions/${props.version}`,
2923+
auth: props.auth
2924+
});
2925+
});
2926+
});
2927+
});
29042928
});
29052929

29062930
describe('backwards-compatibility function aliases', () => {

0 commit comments

Comments
 (0)