Skip to content

Commit

Permalink
Merge f764ded into e9e603b
Browse files Browse the repository at this point in the history
  • Loading branch information
itTkm committed Aug 3, 2021
2 parents e9e603b + f764ded commit 91bb23c
Show file tree
Hide file tree
Showing 9 changed files with 5,096 additions and 766 deletions.
33 changes: 22 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
language: node_js
node_js:
- "14"
- "12"
- "11"
- "10"
- "9"
- "8"
- "7"
- "6"
script:
- npm run build

stages:
- test
- build

jobs:
include:
- name: Test with Node.js lts/*
stage: test
node_js: "lts/*"
script:
- npm test && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
- name: Build with Node.js lts/*
stage: build
node_js: "lts/*"
script:
- npm run build
- name: Build with Node.js stable
stage: build
node_js: "stable"
script:
- npm run build
52 changes: 50 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

[![npm version](https://img.shields.io/npm/v/azure-retail-prices.svg)](https://www.npmjs.com/package/azure-retail-prices)
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](./LICENSE)
[![Build Status](https://travis-ci.org/itTkm/azure-retail-prices.svg?branch=main)](https://travis-ci.org/itTkm/azure-retail-prices)
[![Build Status](https://travis-ci.com/itTkm/azure-retail-prices.svg?branch=main)](https://travis-ci.com/itTkm/azure-retail-prices)
[![Coverage Status](https://coveralls.io/repos/github/itTkm/azure-retail-prices/badge.svg?branch=main)](https://coveralls.io/github/itTkm/azure-retail-prices?branch=main)

This is wrapper of [Azure Retail Prices API](https://docs.microsoft.com/rest/api/cost-management/retail-prices/azure-retail-prices).
You can easily get the retail price of Azure without authenticating.
Expand Down Expand Up @@ -37,12 +38,24 @@ import arp from "azure-retail-prices";
// const arp = require("azure-retail-prices").default;

async function getRetailPrices() {
const retailPrices = await arp({
// without currencyCode option (It will return USD)
let retailPrices = await arp({
serviceName: "Virtual Machines",
location: "EU West",
priceType: "Reservation",
});
console.dir(retailPrices);

// with currencyCode option
retailPrices = await arp(
{
serviceName: "Virtual Machines",
location: "EU West",
priceType: "Reservation",
},
"JPY"
);
console.dir(retailPrices);
}
```

Expand Down Expand Up @@ -73,6 +86,17 @@ const retailPrices = await arp({
location: "EU West",
});

// Virtual machines located "EU West" with currency in EUR
// - Response count: 4K+
// - Response time: 40 seconds
const retailPrices = await arp(
{
serviceName: "Virtual Machines",
location: "EU West",
},
"EUR"
);

// Reserved virtual machines located "EU West"
// - Response count: 700+
// - Response time: 8 seconds
Expand Down Expand Up @@ -173,6 +197,30 @@ Filters are supported for the following fields:
| priceType | DevTestConsumption | Meter consumption type. Other types are `Reservation`, `Consumption`. |
| armSkuName | Standard_F16s | SKU name registered in Azure |

## Supported currencies

You append the currency code to the API endpoint, as shown in the API [sample call](#sample-calls).

| Currency code | Detail |
| ------------- | ------------------ |
| USD | US dollar |
| AUD | Australian dollar |
| BRL | Brazilian real |
| CAD | Canadian dollar |
| CHF | Swiss franc |
| CNY | Chinese yuan |
| DKK | Danish krone |
| EUR | Euro |
| GBP | British pound |
| INR | Indian rupee |
| JPY | Japanese yen |
| KRW | Korean won |
| NOK | Norwegian krone |
| NZD | New Zealand dollar |
| RUB | Russian ruble |
| SEK | Swedish krona |
| TWD | Taiwan dollar |

## License

This library is licensed under the [MIT License](./LICENSE).
17 changes: 13 additions & 4 deletions example/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@ const filter: IRetailPriceFilter = {
getRetailPrices(filter);

async function getRetailPrices(filter: IRetailPriceFilter) {
const startTime = performance.now();
const retailPrices = await arp(filter);
const endTime = performance.now();
console.log("##### without currencyCode option (USD)");
let startTime = performance.now();
let retailPrices = await arp(filter);
let endTime = performance.now();
console.dir(retailPrices);
console.log(`Response conut: ${retailPrices.length}`);
console.log(`Response time: ${Math.round(endTime - startTime) / 1000} s`);
console.log(`Response time: ${Math.round(endTime - startTime) / 1000} s\n`);

console.log("##### currencyCode = 'JPY'");
startTime = performance.now();
retailPrices = await arp(filter, "JPY");
endTime = performance.now();
console.dir(retailPrices);
console.log(`Response conut: ${retailPrices.length}`);
console.log(`Response time: ${Math.round(endTime - startTime) / 1000} s\n`);
}
17 changes: 13 additions & 4 deletions example/require.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@ const filter = {
getRetailPrices(filter);

async function getRetailPrices(filter) {
const startTime = performance.now();
const retailPrices = await arp(filter);
const endTime = performance.now();
console.log("##### without currencyCode option (USD)");
let startTime = performance.now();
let retailPrices = await arp(filter);
let endTime = performance.now();
console.dir(retailPrices);
console.log(`Response conut: ${retailPrices.length}`);
console.log(`Response time: ${Math.round(endTime - startTime) / 1000} s`);
console.log(`Response time: ${Math.round(endTime - startTime) / 1000} s\n`);

console.log("##### currencyCode = 'JPY'");
startTime = performance.now();
retailPrices = await arp(filter, "JPY");
endTime = performance.now();
console.dir(retailPrices);
console.log(`Response conut: ${retailPrices.length}`);
console.log(`Response time: ${Math.round(endTime - startTime) / 1000} s\n`);
}
17 changes: 17 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
moduleFileExtensions: ["ts", "js"],
transform: {
"^.+\\.ts$": "ts-jest",
},
globals: {
"ts-jest": {
tsConfig: "tsconfig.json",
diagnostics: {
/* Ignore the error "is declared, but not used."
https://huafu.github.io/ts-jest/user/config/diagnostics */
ignoreCodes: [2322],
},
},
},
testMatch: ["**/tests/**/*.test.ts"],
};
Loading

0 comments on commit 91bb23c

Please sign in to comment.