Skip to content

Commit

Permalink
Merge pull request #34 from cloudblue/LITE-16977-Create-Usage-functio…
Browse files Browse the repository at this point in the history
…nality-in-Javascript-SDK

LITE-16977 Create Usage Functionality
  • Loading branch information
marcserrat committed Mar 8, 2021
2 parents f2ddbd9 + 2f44913 commit 7e2177d
Show file tree
Hide file tree
Showing 15 changed files with 828 additions and 3 deletions.
25 changes: 25 additions & 0 deletions lib/connect/api/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,20 @@
* @copyright (c) 2020. Ingram Micro. All Rights Reserved.
*/

/* eslint-disable max-classes-per-file */

const { memoizeWith, identity } = require('ramda');
const GenericResource = require('./base');

/**
* The *AssetUsageAgregatesResource* class provides methods to access the
* *AssetUsageAgregates* objects for a asset.
*
* @extends GenericResource
* @category Resources
*/
class AssetUsageAgregatesResource extends GenericResource {}

/**
* The *AssetResource* class provides methods to access the assets
* endpoint of the Cloud Blue Connect API.
Expand All @@ -23,6 +35,19 @@ class AssetResource extends GenericResource {
*/
constructor(client) {
super(client, '/assets');
this.usageAgregates = memoizeWith(identity, this.usageAgregates);
}

/**
* Returns an instance of the *AssetUsageAgregatesResource* for a *Asset*.
*
* @param {string} id The unique identifier of the *Product*.
*
* @returns {AssetUsageAgregatesResource} An instance of the *AssetUsageAgregatesResource*
* for the asset.
*/
usageAgregates(id) {
return new AssetUsageAgregatesResource(this._client, `${this.baseUri}/${id}/usage/agregates`);
}
}

Expand Down
9 changes: 9 additions & 0 deletions lib/connect/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ const TierConfigRequestResource = require('./tierConfigRequests');
const WebhookResource = require('./webhooks');
const ListingRequestResource = require('./listingRequests');
const CaseResource = require('./cases');
const UsageFileResource = require('./usageFiles');
const UsageChunkResource = require('./usageChunks');
const UsageRecordResource = require('./usageRecords');
const UsageReconciliationResource = require('./usageReconciliations');


module.exports = {
GenericResource,
Expand All @@ -38,4 +43,8 @@ module.exports = {
WebhookResource,
ListingRequestResource,
CaseResource,
UsageFileResource,
UsageChunkResource,
UsageRecordResource,
UsageReconciliationResource,
};
25 changes: 22 additions & 3 deletions lib/connect/api/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ class ProductParameterResource extends GenericResource {}
*/
class ProductConnectionsResource extends GenericResource {}

/**
* The *ProductUsageRulesResource* class provides methods to access the
* *ProductUsageRule* objects for a product.
*
* @extends GenericResource
* @category Resources
*/
class ProductUsageRuleResource extends GenericResource {}

/**
* The *ProductResource* class provides methods to access the products
* endpoint of the Cloud Blue Connect API.
Expand All @@ -119,6 +128,7 @@ class ProductResource extends GenericResource {
this.configurations = memoizeWith(identity, this.configurations);
this.parameters = memoizeWith(identity, this.parameters);
this.connections = memoizeWith(identity, this.connections);
this.usageRules = memoizeWith(identity, this.usageRules);
}

/**
Expand Down Expand Up @@ -183,6 +193,18 @@ class ProductResource extends GenericResource {
return new ProductConnectionsResource(this._client, `${this.baseUri}/${id}/connections`);
}

/**
* Returns an instance of the *ProductUsageRulesResource* for a *Product*.
*
* @param {string} id The unique identifier of the *Product*.
*
* @returns {ProductUsageRuleResource} An instance of the *ProductUsageRuleResource*
* for the product.
*/
usageRules(id) {
return new ProductUsageRuleResource(this._client, `${this.baseUri}/${id}/usage/rules`);
}

/**
* Returns the list of *Template* objects configured for the *Product*.
*
Expand Down Expand Up @@ -236,9 +258,6 @@ class ProductResource extends GenericResource {
const response = await this.fetch(url);
return response.json();
}



}

module.exports = ProductResource;
30 changes: 30 additions & 0 deletions lib/connect/api/usageAggregates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This file is part of the Ingram Micro Cloud Blue Connect SDK.
*
* @copyright (c) 2020. Ingram Micro. All Rights Reserved.
*/

/* eslint-disable max-classes-per-file */

const GenericResource = require('./base');

/**
* The *UsageFileResource* class provides methods to access the usage file
* endpoint of the Cloud Blue Connect API.
*
* @extends GenericResource
* @category Resources
*/
class UsageAggregateResource extends GenericResource {
/**
* Creates a new instance of the *UsageAggregateResource* class.
*
* @param {ConnectClient} client An instance of the ConnectClient class.
*
* @returns {UsageAggregateResource} An instance of the *UsageAggregateResource* class.
*/
constructor(client) {
super(client, '/usage/aggregates');
}
}
module.exports = UsageAggregateResource;
84 changes: 84 additions & 0 deletions lib/connect/api/usageChunks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* This file is part of the Ingram Micro Cloud Blue Connect SDK.
*
* @copyright (c) 2020. Ingram Micro. All Rights Reserved.
*/

/* eslint-disable max-classes-per-file */

const GenericResource = require('./base');

/**
* The *UsageFileResource* class provides methods to access the usage file
* endpoint of the Cloud Blue Connect API.
*
* @extends GenericResource
* @category Resources
*/
class UsageChunkResource extends GenericResource {
/**
* Creates a new instance of the *UsageChunkResource* class.
*
* @param {ConnectClient} client An instance of the ConnectClient class.
*
* @returns {UsageChunkResource} An instance of the *UsageFileResource* class.
*/
constructor(client) {
super(client, '/usage/chunks');
}

/**
* Close *Chunk File*.
*
* @param {string} id The unique identifier of the *Usage File*.
* @param {string} externalBillingId Id of the billing to close chunk
* @param {string} externalBillingNote Note of the billing to close chunk
* @returns {UsageChunkResource} An instance of the *UsageChunkResource*.
*
*/
async close(id, externalBillingId, externalBillingNote) {
const url = `${this.baseUri}/${id}/close`;
const options = {
method: 'POST',
body: {
external_billing_id: externalBillingId,
external_billing_note: externalBillingNote,
},
};
const response = await this.fetch(url, options);
return response.json();
}

/**
* Download *Chunk File*.
*
* @param {string} id The unique identifier of the *Usage File*.
* @returns {UsageChunckResource} An instance of the *UsageChunkResource*
*
*/
async download(id) {
const url = `${this.baseUri}/${id}/download`;
const options = {
method: 'GET',
};
const response = await this.fetch(url, options);
return response.json();
}

/**
* Regenerate *Chunk File*.
*
* @param {string} id The unique identifier of the *Usage File*.
* @returns {UsageChunckResource} An instance of the *UsageChunkResource*
*
*/
async regenerate(id) {
const url = `${this.baseUri}/${id}/regenerate`;
const options = {
method: 'POST',
};
const response = await this.fetch(url, options);
return response.json();
}
}
module.exports = UsageChunkResource;

0 comments on commit 7e2177d

Please sign in to comment.