Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
itTkm committed Aug 3, 2021
1 parent f9608f7 commit 86ce83e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
5 changes: 3 additions & 2 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface IRetailPrice {
meterId?: string;
type?: "DevTestConsumption" | "Consumption" | "Reservation";
reservationTerm?: string;
currencyCode?: "USD";
currencyCode?: string;
tierMinimumUnits?: number;
retailPrice?: number;
unitPrice?: number;
Expand All @@ -42,7 +42,8 @@ export interface IRetailPriceFilter extends IStringKeyObject {
/**
* Get retail prices from the Azure Retail Prices API
* @param filterObject Filter object
* @param currencyCode Currency code string
* @return Array of retail price object
*/
declare function getRetailPrices(filterObject: IRetailPriceFilter): Promise<IRetailPrice[]>;
declare function getRetailPrices(filterObject: IRetailPriceFilter, currencyCode?: string): Promise<IRetailPrice[]>;
export default getRetailPrices;
13 changes: 8 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ const PRICE_TYPES = [
"Consumption",
"Reservation",
];
const DEFAULT_CURRENCY_CODE = "USD";
/**
* Get retail prices from the Azure Retail Prices API
* @param filterObject Filter object
* @param currencyCode Currency code string
* @return Array of retail price object
*/
async function getRetailPrices(filterObject) {
async function getRetailPrices(filterObject, currencyCode = DEFAULT_CURRENCY_CODE) {
let retailPrices = [];
if (_validateFilterObject(filterObject)) {
const filterString = _generateFilter(filterObject);
retailPrices = await _getRetailPrices(filterString);
retailPrices = await _getRetailPrices(filterString, currencyCode);
}
return retailPrices;
}
Expand Down Expand Up @@ -68,12 +70,13 @@ function _generateFilter(filterObject) {
/**
* Get retail prices from the Azure Retail Prices API with filter
* @param filterString Filter string
* @param currencyCode Currency code string
* @return Array of retail price object
*/
async function _getRetailPrices(filterString) {
let url = API_ENDPOINT;
async function _getRetailPrices(filterString, currencyCode) {
let url = API_ENDPOINT + `?currencyCode='${currencyCode}'`;
if (filterString !== "")
url += `?$filter=${filterString}`;
url += `&$filter=${filterString}`;
let retailPrices = [];
// eslint-disable-next-line no-constant-condition
while (true) {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azure-retail-prices",
"version": "1.0.1",
"version": "1.1.0",
"description": "Wrapper of Azure Retail Prices API. You can easily get the retail price of Azure without authenticating.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit 86ce83e

Please sign in to comment.