Skip to content

Commit

Permalink
Updated wrapper to work with CMC API v2
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavk99 committed May 7, 2018
1 parent 5478b18 commit 24ded7c
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 4 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,21 @@ client.getGlobal().then(console.log).catch(console.error)

#### Table of Contents

- [getListings](#getlistings)
- [getTicker](#getticker)
- [getGlobal](#getglobal)

### getListings

Get all active cryptocurrency listings

**Examples**

```javascript
const client = new CoinMarketCap()
client.getListings().then(console.log).catch(console.error)
```

### getTicker

Get ticker information
Expand Down
68 changes: 66 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset='utf-8' />
<title>coinmarketcap-api 1.0.2 | Documentation</title>
<title>coinmarketcap-api 1.0.3 | Documentation</title>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<link href='assets/bass.css' type='text/css' rel='stylesheet' />
<link href='assets/style.css' type='text/css' rel='stylesheet' />
Expand All @@ -14,7 +14,7 @@
<div id='split-left' class='overflow-auto fs0 height-viewport-100'>
<div class='py1 px2'>
<h3 class='mb0 no-anchor'>coinmarketcap-api</h3>
<div class='mb1'><code>1.0.2</code></div>
<div class='mb1'><code>1.0.3</code></div>
<input
placeholder='Filter'
id='filter-input'
Expand All @@ -24,6 +24,16 @@ <h3 class='mb0 no-anchor'>coinmarketcap-api</h3>
<ul class='list-reset h5 py1-ul'>


<li><a
href='#getlistings'
class="">
getListings

</a>

</li>


<li><a
href='#getticker'
class="">
Expand Down Expand Up @@ -53,6 +63,60 @@ <h3 class='mb0 no-anchor'>coinmarketcap-api</h3>
<div id='split-right' class='relative overflow-auto height-viewport-100'>


<section class='p2 mb2 clearfix bg-white minishadow'>


<div class='clearfix'>

<h3 class='fl m0' id='getlistings'>
getListings
</h3>


</div>


<p>Get all active cryptocurrency listings</p>


<div class='pre p1 fill-light mt0'>getListings()</div>



















<div class='py1 quiet mt1 prose-big'>Example</div>


<pre class='p1 overflow-auto round fill-light'><span class="hljs-keyword">const</span> client = <span class="hljs-keyword">new</span> CoinMarketCap()
client.getListings().then(<span class="hljs-built_in">console</span>.log).catch(<span class="hljs-built_in">console</span>.error)</pre>








</section>




<section class='p2 mb2 clearfix bg-white minishadow'>


Expand Down
16 changes: 15 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,28 @@ const qs = require('qs')
const BASE_URL = 'https://api.coinmarketcap.com'

class CoinMarketCap {
constructor ({ version = 'v1' } = {}) {
constructor ({ version = 'v2' } = {}) {
this.headers = {
Accept: 'application/json',
'Accept-Charset': 'utf-8'
}
this.url = `${BASE_URL}/${version}`
}

/**
* Get all active cryptocurrency listings
*
* @example
* const client = new CoinMarketCap()
* client.getListings().then(console.log).catch(console.error)
*/
getListings () {
return createRequest({
url: `${this.url}/listings`,
headers: this.headers
})
}

/**
* Get ticker information
*
Expand Down
10 changes: 9 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ test('should return new CoinMarketCap client', () => {
const client = new CoinMarketCap()
expect(client.getTicker).toBeDefined()
expect(client.getGlobal).toBeDefined()
expect(client.getListings).toBeDefined()
})

test('should get latest ticker', async () => {
Expand All @@ -17,7 +18,7 @@ test('should get latest ticker', async () => {

expect(typeof ticker1).toBe('object')
expect(typeof ticker2).toBe('object')
expect(ticker2.length).toBe(10)
expect(Object.keys(ticker2.data).length).toBe(10)
})

test('should get latest global', async () => {
Expand All @@ -27,3 +28,10 @@ test('should get latest global', async () => {
expect(typeof global).toBe('object')
})

test(`should get latest listings`, async () => {
const client = new CoinMarketCap()
const listings = await client.getListings()

expect(typeof listings).toBe('object')
})

0 comments on commit 24ded7c

Please sign in to comment.