Skip to content

Commit

Permalink
Release v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-jarota committed Sep 24, 2019
1 parent df415ca commit a6be163
Show file tree
Hide file tree
Showing 10 changed files with 389 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/node_modules
package-lok.json
package-lock.json
/.idea
yarn.lock
/coverage
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ client.getCoins().then(console.log).catch(console.error);
```

#### getTicker

(**DEPRECATED**)
Get information on all tickers or specifed ticker.


Expand All @@ -71,6 +71,42 @@ client.getTicker().then(console.log).catch(console.error);
client.getTicker({coinId: 'btc-bitcoin'}).then(console.log).catch(console.error);
```

#### getAllTickers

Get tickers for all coins

##### Parameters

- `params` (optional, default `{}`)
- `coinId` string (optional but *`required` with historical key*)
- `quotes` array of strings (optional)
- `historical` object (optional)
- start: string (required)
- end: string (optional)
- limit: integer (optional)
- quote: string (optional)
- interval: string (optional)

##### Examples
```javascript
const client = new CoinpaprikaAPI()
client.getAllTickers({
coinId:'btc-bitcoin',
quotes: ['BTC', 'ETH']
}).then(console.log).catch(console.error)

client.getAllTickers({
coinId:'btc-bitcoin',
historical: {
start: '2018-02-15',
end: '2018-02-16',
limit: 2000,
quote: 'btc',
interval: '30m'
}
}).then(console.log).catch(console.error)
```

## License

CoinpaprikaAPI is available under the MIT license. See the LICENSE file for more info.
70 changes: 69 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,20 @@ class CoinpaprikaAPI {

/**
* Get information on all tickers or specifed ticker.
* DEPRECATED
*
* @param {Object=} options Options for the request
* @param {String=} [options.coinId="all"] Type of cryptocurrency to include ("all" | "coins" | "tokens")
*
* @example
* const client = new CoinpaprikaAPI()
* client.getTicker({coinId: 3}).then(console.log).catch(console.error)
* client.getTicker().then(console.log).catch(console.error)
*/
getTicker (args = {}) {
if (Object.prototype.toString.call(args) !== '[object Object]') {
throw Error('Please pass object as arg.')
}

let { coinId } = args
return createRequest({
fetcher: this.fetcher,
Expand All @@ -63,6 +67,70 @@ class CoinpaprikaAPI {
})
}

/**
* Get tickers for all coins
* @param {Object=} options for the request consistent to https://api.coinpaprika.com/#tag/Tickers
* @param coinId: string
* @param quotes: array of strings
* @param historical: object
* @example
* const client = new CoinpaprikaAPI()
* client.getAllTickers({
* coinId:'btc-bitcoin',
* quotes: ['BTC', 'ETH']
* })
* .then(console.log)
* .catch(console.error)
*
* client.getAllTickers({
* coinId:'btc-bitcoin',
* historical: {
* start: '2018-02-15',
* end: '2018-02-16',
* limit: 2000,
* quote: 'btc',
* interval: '30m'
* }
* })
* .then(console.log)
* .catch(console.error)
*/
getAllTickers (params = {}) {
if (Object.prototype.toString.call(params) !== '[object Object]') {
throw Error('Please pass object as arg.')
}

const { coinId, quotes, historical } = params

if ((historical && typeof coinId === 'undefined') || (coinId && historical && typeof historical.start === 'undefined')) {
throw Error('required param was not pass, please check CoinpaprikaAPI client usage')
}

const coinIdParam = coinId ? `/${coinId}` : ''
const quotesParam = quotes ? `?quotes=${quotes.join(',')}` : ''
let historicalParam = ''
if (historical && coinId) {
historicalParam = ((historicalArgs = {}) => {
const { start, end, limit, quote, interval } = historicalArgs
const startParam = `start=${start}`
const endParam = end ? `&end=${end}` : ''
const limitParam = limit ? `&limit=${limit}` : ''
const quoteParam = quote ? `&quote=${quote}` : ''
const intervalParam = interval ? `&interval=${interval}` : ''

return `/historical?${startParam}${endParam}${limitParam}${quoteParam}${intervalParam}`
})(historical)
}

const query = `${coinIdParam}${historicalParam}${quotesParam}`

return createRequest({
fetcher: this.fetcher,
url: `${this.url}/tickers/${query}`,
config: this.config
})
}

/**
* Get a list of all cryptocurrencies available on coinpaprika.com.
*
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coinpaprika/api-nodejs-client",
"version": "1.0.2",
"version": "1.1.0",
"description": "This library provides convenient way to use Coinpaprika.com API in NodeJS",
"license": "MIT",
"repository": {
Expand All @@ -20,16 +20,16 @@
"pretest": "npm run lint"
},
"jest": {
"setupTestFrameworkScriptFile": "./test.js"
"verbose": true
},
"author": "coinpaprika.com",
"devDependencies": {
"documentation": "^8.1.2",
"dotenv": "^6.0.0",
"husky": "^0.14.3",
"jest": "^23.5.0",
"jest-chain": "^1.0.3",
"jest-extended": "^0.8.1",
"jest": "^24.9.0",
"jest-chain": "^1.1.2",
"jest-extended": "^0.11.2",
"standard": "^12.0.1"
},
"dependencies": {
Expand All @@ -48,4 +48,4 @@
"bitcoin",
"cryptocurrency"
]
}
}
64 changes: 0 additions & 64 deletions test.js

This file was deleted.

20 changes: 20 additions & 0 deletions tests/CoinpaprikaAPI.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const CoinpaprikaAPI = require('../index')

describe('CoinpaprikaAPI class', () => {
let client = null

beforeEach(() => {
client = new CoinpaprikaAPI()
})

it('is defined', () => {
expect(client).toBeDefined()
})

it('has defined all endpoints consistent to API documentation', () => {
expect(client.getGlobal).toBeDefined()
expect(client.getCoins).toBeDefined()
expect(client.getAllTickers).toBeDefined()
expect(client.getTicker).toBeDefined()
})
})
Loading

0 comments on commit a6be163

Please sign in to comment.