coin_market_pro 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/Gemfile.lock +3 -3
- data/README.md +16 -83
- data/lib/coin_market_pro.rb +5 -0
- data/lib/coin_market_pro/client/base.rb +18 -5
- data/lib/coin_market_pro/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5d17f07be79da69922c5737daa7e9d0c518ce5f3d082a0b530c6478f332096e
|
4
|
+
data.tar.gz: af126477e9dfa0fea53b1e6e8eab8db454bf722592e164ee53e538149913c1bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a0e6ab9fac771c8393d97452d89169b920ef7a37adc5d192b623ab5dd497254e625ab8e45518c247b46999d8604e8d407992b20a14cc86587444e6c25fa549a
|
7
|
+
data.tar.gz: 448c47f2cd89f66ae37754c79f03c2a1db9c9eba74839cdaa2459a1999b1961dc664322b2e7b530907071795ee8a28479cd86281a9fc4af7a360c6c65e2872d3
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
coin_market_pro (0.1.
|
5
|
-
activesupport (
|
4
|
+
coin_market_pro (0.1.1)
|
5
|
+
activesupport (~> 5.1)
|
6
6
|
multi_json (~> 1.13)
|
7
7
|
rest-client (~> 2.0)
|
8
8
|
|
@@ -82,7 +82,7 @@ PLATFORMS
|
|
82
82
|
DEPENDENCIES
|
83
83
|
bundler (~> 1.16)
|
84
84
|
coin_market_pro!
|
85
|
-
pry
|
85
|
+
pry (~> 0.11)
|
86
86
|
rake (~> 12.3)
|
87
87
|
rspec (~> 3.8)
|
88
88
|
simplecov (~> 0.16)
|
data/README.md
CHANGED
@@ -6,10 +6,10 @@ The CoinMarketCap Professional API is a suite of high-performance RESTful JSON e
|
|
6
6
|
|
7
7
|
## Available Endpoints:
|
8
8
|
|
9
|
-
* [Cryptocurrency](
|
10
|
-
* [Exchange](
|
11
|
-
* [Global Metrics](
|
12
|
-
* [Tools](
|
9
|
+
* [Cryptocurrency](#cryptocurrency)
|
10
|
+
* [Exchange](#exchange)
|
11
|
+
* [Global Metrics](#global-metrics)
|
12
|
+
* [Tools](#tools)
|
13
13
|
|
14
14
|
## Installation
|
15
15
|
|
@@ -26,26 +26,27 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
## Environment Variables
|
28
28
|
|
29
|
-
| Variable
|
30
|
-
|
|
31
|
-
| `
|
29
|
+
| Variable | Description | Default |
|
30
|
+
| ------------------|:--------------------------|:---------:|
|
31
|
+
| `CMC_PRO_API_KEY` | CoinMarketCap Pro API Key | - |
|
32
32
|
|
33
33
|
## Usage
|
34
34
|
|
35
35
|
### Initialize CoinMarketPro
|
36
36
|
|
37
|
-
Client Api Key defaults to `
|
37
|
+
Client Api Key defaults to `CMC_PRO_API_KEY` ENV. Override the client with `api_key` param.
|
38
38
|
|
39
39
|
```ruby
|
40
40
|
# Rails Example
|
41
41
|
#
|
42
42
|
# config/initializers/coin_market_pro.rb
|
43
43
|
module CoinMarketPro
|
44
|
-
|
44
|
+
# Testing endpoint available with sandbox: true option
|
45
|
+
Api ||= CoinMarketPro.new(api_key: 'CMC-Pro-Api-Key', logger: Rails.logger)
|
45
46
|
end
|
46
47
|
|
47
48
|
# Ruby
|
48
|
-
client = CoinMarketPro.new(api_key: '
|
49
|
+
client = CoinMarketPro.new(api_key: 'CMC-Pro-Api-Key')
|
49
50
|
```
|
50
51
|
|
51
52
|
### [Common Errors](https://pro.coinmarketcap.com/api/v1#section/Errors-and-Rate-Limits)
|
@@ -62,77 +63,9 @@ Client Api Key defaults to `COIN_MARKET_PRO_API_KEY` ENV. Override the client wi
|
|
62
63
|
|
63
64
|
Response object returned as hash with keys: `status`, `code`, `headers`, `body`, `raw`. For consistency, `body` will always be returned as an array.
|
64
65
|
|
65
|
-
|
66
|
-
# Using `client` defined from above
|
67
|
-
|
68
|
-
client.cryptocurrency.info(id: [1])
|
69
|
-
# => #<CoinMarketPro::Client::Result:0x00007f9045657d18
|
70
|
-
# @body=
|
71
|
-
# [{:urls=>
|
72
|
-
# {:website=>["https://bitcoin.org/"],
|
73
|
-
# :twitter=>[],
|
74
|
-
# :reddit=>["https://reddit.com/r/bitcoin"],
|
75
|
-
# :message_board=>["https://bitcointalk.org"],
|
76
|
-
# :announcement=>[],
|
77
|
-
# :chat=>[],
|
78
|
-
# :explorer=>["https://blockchain.info/", "https://live.blockcypher.com/btc/", "https://blockchair.com/bitcoin/blocks"],
|
79
|
-
# :source_code=>["https://github.com/bitcoin/"]},
|
80
|
-
# :logo=>"https://s2.coinmarketcap.com/static/img/coins/64x64/1.png",
|
81
|
-
# :id=>1,
|
82
|
-
# :name=>"Bitcoin",
|
83
|
-
# :symbol=>"BTC",
|
84
|
-
# :slug=>"bitcoin",
|
85
|
-
# :date_added=>"2013-04-28T00:00:00.000Z",
|
86
|
-
# :tags=>["mineable"],
|
87
|
-
# :category=>"coin"}],
|
88
|
-
# @code=200,
|
89
|
-
# @headers=
|
90
|
-
# {:content_type=>"application/json; charset=utf-8",
|
91
|
-
# :transfer_encoding=>"chunked",
|
92
|
-
# :connection=>"keep-alive",
|
93
|
-
# :date=>"Mon, 08 Oct 2018 02:04:13 GMT",
|
94
|
-
# :server=>"nginx",
|
95
|
-
# :vary=>"origin,accept-encoding",
|
96
|
-
# :access_control_expose_headers=>"WWW-Authenticate,Server-Authorization",
|
97
|
-
# :cache_control=>"no-cache",
|
98
|
-
# :content_encoding=>"gzip",
|
99
|
-
# :x_cache=>"Miss from cloudfront",
|
100
|
-
# :via=>"1.1 39f9e0f028321e95b5ebd1cd55661fd6.cloudfront.net (CloudFront)",
|
101
|
-
# :x_amz_cf_id=>"uQcyrXXRjyNb_oFO5hlXDAAX9TgYvmUXUaXujxxzYgRfoq_XleXjhQ=="},
|
102
|
-
# @raw=
|
103
|
-
# {:status=>{:timestamp=>"2018-10-08T02:04:13.628Z", :error_code=>0, :error_message=>nil, :elapsed=>11, :credit_count=>1},
|
104
|
-
# :data=>
|
105
|
-
# {:"1"=>
|
106
|
-
# {:urls=>
|
107
|
-
# {:website=>["https://bitcoin.org/"],
|
108
|
-
# :twitter=>[],
|
109
|
-
# :reddit=>["https://reddit.com/r/bitcoin"],
|
110
|
-
# :message_board=>["https://bitcointalk.org"],
|
111
|
-
# :announcement=>[],
|
112
|
-
# :chat=>[],
|
113
|
-
# :explorer=>
|
114
|
-
# ["https://blockchain.info/", "https://live.blockcypher.com/btc/", "https://blockchair.com/bitcoin/blocks"],
|
115
|
-
# :source_code=>["https://github.com/bitcoin/"]},
|
116
|
-
# :logo=>"https://s2.coinmarketcap.com/static/img/coins/64x64/1.png",
|
117
|
-
# :id=>1,
|
118
|
-
# :name=>"Bitcoin",
|
119
|
-
# :symbol=>"BTC",
|
120
|
-
# :slug=>"bitcoin",
|
121
|
-
# :date_added=>"2013-04-28T00:00:00.000Z",
|
122
|
-
# :tags=>["mineable"],
|
123
|
-
# :category=>"coin"}}},
|
124
|
-
# @status=
|
125
|
-
# {:timestamp=>"2018-10-08T02:04:13.628Z",
|
126
|
-
# :error_code=>0,
|
127
|
-
# :error_message=>nil,
|
128
|
-
# :elapsed=>11,
|
129
|
-
# :credit_count=>1,
|
130
|
-
# :result=>:success}>
|
131
|
-
```
|
132
|
-
|
133
|
-
### Endpoints
|
66
|
+
## Endpoints
|
134
67
|
|
135
|
-
|
68
|
+
## [Cryptocurrency](https://pro.coinmarketcap.com/api/v1#tag/cryptocurrency)
|
136
69
|
|
137
70
|
##### [Info/Metadata](https://pro.coinmarketcap.com/api/v1#operation/getV1CryptocurrencyInfo)
|
138
71
|
|
@@ -336,7 +269,7 @@ Get the latest market quote for 1 or more cryptocurrencies. Use the "convert" op
|
|
336
269
|
client.cryptocurrency.quotes(id: [1]).body
|
337
270
|
```
|
338
271
|
|
339
|
-
|
272
|
+
## [Exchange](https://pro.coinmarketcap.com/api/v1#tag/exchange)
|
340
273
|
|
341
274
|
##### [Info/Metadata](https://pro.coinmarketcap.com/api/v1#operation/getV1ExchangeInfo)
|
342
275
|
|
@@ -428,7 +361,7 @@ Get the latest 24 hour volume quote for 1 or more exchanges. Additional market d
|
|
428
361
|
client.exchange.quotes(id: [1, 2])
|
429
362
|
```
|
430
363
|
|
431
|
-
|
364
|
+
## [Global Metrics](https://pro.coinmarketcap.com/api/v1#tag/global-metrics)
|
432
365
|
|
433
366
|
##### [Quotes (Historical)](https://pro.coinmarketcap.com/api/v1#operation/getV1GlobalmetricsQuotesHistorical)
|
434
367
|
|
@@ -460,7 +393,7 @@ Get the latest quote of aggregate market metrics. Use the "convert" option to re
|
|
460
393
|
client.global_metrics.quotes
|
461
394
|
```
|
462
395
|
|
463
|
-
|
396
|
+
## [Tools](https://pro.coinmarketcap.com/api/v1#tag/tools)
|
464
397
|
|
465
398
|
##### [Price conversion](https://pro.coinmarketcap.com/api/v1#operation/getV1ToolsPriceconversion)
|
466
399
|
|
data/lib/coin_market_pro.rb
CHANGED
@@ -6,6 +6,11 @@ require_relative 'coin_market_pro/client/base'
|
|
6
6
|
module CoinMarketPro
|
7
7
|
module_function
|
8
8
|
|
9
|
+
# @param args [Hash]
|
10
|
+
# @param args [String] :api_key Required. Defaults to CMC_PRO_API_KEY
|
11
|
+
# @param args [Boolean] :sandbox Defaults to false
|
12
|
+
# @param args [Logger] :logger Defaults to Logger.new(STDOUT)
|
13
|
+
# @param args [Integer] :timeout Defaults to 10
|
9
14
|
def new(**args)
|
10
15
|
Client::Base.new(args)
|
11
16
|
end
|
@@ -16,15 +16,23 @@ module CoinMarketPro
|
|
16
16
|
end
|
17
17
|
|
18
18
|
class Base
|
19
|
-
attr_reader :host, :api_key, :logger, :cryptocurrency, :exchange, :global_metrics, :tools
|
19
|
+
attr_reader :host, :api_key, :sandbox, :logger, :cryptocurrency, :exchange, :global_metrics, :tools
|
20
20
|
|
21
|
-
API_DOMAIN = 'https://
|
21
|
+
API_DOMAIN = 'https://SUBDOMAIN.coinmarketcap.com'
|
22
22
|
API_VERSION = 'v1'
|
23
23
|
API_URL = "#{API_DOMAIN}/#{API_VERSION}"
|
24
24
|
DEFAULT_TIMEOUT = 10
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
PRO_SUBDOMAIN = 'pro-api'
|
26
|
+
SANDBOX_SUBDOMAIN = 'sandbox'
|
27
|
+
|
28
|
+
# @param api_key [String] Required. Defaults to CMC_PRO_API_KEY
|
29
|
+
# @param sandbox [Boolean] Defaults to false
|
30
|
+
# @param logger [Logger]
|
31
|
+
# @param timeout [Integer] Defaults to DEFAULT_TIMEOUT
|
32
|
+
def initialize(api_key: ENV.fetch('CMC_PRO_API_KEY'), sandbox: false,
|
33
|
+
logger: Logger.new(STDOUT), timeout: DEFAULT_TIMEOUT)
|
34
|
+
@sandbox = sandbox
|
35
|
+
@host = @sandbox ? API_URL.gsub('SUBDOMAIN', SANDBOX_SUBDOMAIN) : API_URL.gsub('SUBDOMAIN', PRO_SUBDOMAIN)
|
28
36
|
@api_key = api_key
|
29
37
|
@logger = logger
|
30
38
|
@timeout = timeout
|
@@ -112,6 +120,11 @@ module CoinMarketPro
|
|
112
120
|
@open_timeout || DEFAULT_TIMEOUT
|
113
121
|
end
|
114
122
|
|
123
|
+
# @return [Boolean]
|
124
|
+
def sandbox?
|
125
|
+
sandbox
|
126
|
+
end
|
127
|
+
|
115
128
|
private
|
116
129
|
|
117
130
|
# @return [Boolean]
|