coinmarketcap.rb 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/coinmarketcap.rb.gemspec +0 -2
- data/lib/CoinMarketCap/Client.rb +28 -0
- data/lib/CoinMarketCap/V1/Client.rb +50 -11
- data/lib/CoinMarketCap/VERSION.rb +1 -1
- data/test/V1/client_test.rb +75 -0
- data/test/client_test.rb +145 -0
- data/test/helper.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f7dbda1e44c95ff829eccee383406c3b46c138875973a50e0815fc3b02b6637d
|
|
4
|
+
data.tar.gz: 9d20cb179391a63a92ff7db4bae83ecffe8ebe7c73711126846f1b833256c722
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e6ab6d372d36edbe877184caa46ca3f1676c43e904cbb204d71711880210f46e618d6813fec5a82d41d0385d4724abf5b6d663302e4093907dccede183469488
|
|
7
|
+
data.tar.gz: 626cf9a50ada60e0f076ba9ae22aa6cf7fe77aa42aa460bb5c1f14278318bdcdbdd97b69d74ab5350f7250b5fd6e71892054b0c5da2abe6795b34e61ece183d2
|
data/Gemfile
CHANGED
data/coinmarketcap.rb.gemspec
CHANGED
|
@@ -2,9 +2,7 @@ require_relative './lib/CoinMarketCap/VERSION'
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |spec|
|
|
4
4
|
spec.name = 'coinmarketcap.rb'
|
|
5
|
-
|
|
6
5
|
spec.version = CoinMarketCap::VERSION
|
|
7
|
-
spec.date = '2025-05-13'
|
|
8
6
|
|
|
9
7
|
spec.summary = "Access the coinmarketcap.com API with Ruby."
|
|
10
8
|
spec.description = "Access the coinmarketcap.com API with Ruby."
|
data/lib/CoinMarketCap/Client.rb
CHANGED
|
@@ -75,6 +75,34 @@ module CoinMarketCap
|
|
|
75
75
|
v1_client.trending_latest
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
+
def exchange_assets(id:)
|
|
79
|
+
v1_client.exchange_assets(id: id)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def exchange_info(**args)
|
|
83
|
+
v1_client.exchange_info(**args)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def exchange_map(**args)
|
|
87
|
+
v1_client.exchange_map(**args)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def exchange_listings(**args)
|
|
91
|
+
v1_client.exchange_listings_latest(**args)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def exchange_market_pairs(**args)
|
|
95
|
+
v1_client.exchange_market_pairs_latest(**args)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def exchange_quotes(historical: false, **args)
|
|
99
|
+
if historical
|
|
100
|
+
v1_client.exchange_quotes_historical(**args)
|
|
101
|
+
else
|
|
102
|
+
v1_client.exchange_quotes_latest(**args)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
78
106
|
private
|
|
79
107
|
|
|
80
108
|
def initialize(api_key:)
|
|
@@ -26,57 +26,96 @@ module CoinMarketCap
|
|
|
26
26
|
|
|
27
27
|
class << self
|
|
28
28
|
def path_prefix
|
|
29
|
-
'/v1
|
|
29
|
+
'/v1'
|
|
30
30
|
end
|
|
31
31
|
end # class << self
|
|
32
32
|
|
|
33
|
+
# /cryptocurrency
|
|
34
|
+
|
|
33
35
|
def airdrop(id:)
|
|
34
|
-
response = get(path: '/airdrop', args: {id: id})
|
|
36
|
+
response = get(path: '/cryptocurrency/airdrop', args: {id: id})
|
|
35
37
|
handle_response(response)
|
|
36
38
|
end
|
|
37
39
|
|
|
38
40
|
def airdrops
|
|
39
|
-
response = get(path: '/airdrops')
|
|
41
|
+
response = get(path: '/cryptocurrency/airdrops')
|
|
40
42
|
handle_response(response)
|
|
41
43
|
end
|
|
42
44
|
|
|
43
45
|
def categories
|
|
44
|
-
response = get(path: '/categories')
|
|
46
|
+
response = get(path: '/cryptocurrency/categories')
|
|
45
47
|
handle_response(response)
|
|
46
48
|
end
|
|
47
49
|
|
|
48
50
|
def category(id:)
|
|
49
|
-
response = get(path: '/category', args: {id: id})
|
|
51
|
+
response = get(path: '/cryptocurrency/category', args: {id: id})
|
|
50
52
|
handle_response(response)
|
|
51
53
|
end
|
|
52
54
|
|
|
53
55
|
def listings_historical
|
|
54
|
-
response = get(path: '/listings/historical')
|
|
56
|
+
response = get(path: '/cryptocurrency/listings/historical')
|
|
55
57
|
handle_response(response)
|
|
56
58
|
end
|
|
57
59
|
|
|
58
60
|
def listings_latest(**args)
|
|
59
|
-
response = get(path: '/listings/latest', args: args)
|
|
61
|
+
response = get(path: '/cryptocurrency/listings/latest', args: args)
|
|
60
62
|
handle_response(response)
|
|
61
63
|
end
|
|
62
64
|
|
|
63
65
|
def map
|
|
64
|
-
response = get(path: '/map')
|
|
66
|
+
response = get(path: '/cryptocurrency/map')
|
|
65
67
|
handle_response(response)
|
|
66
68
|
end
|
|
67
69
|
|
|
68
70
|
def trending_gainers_losers
|
|
69
|
-
response = get(path: '/trending/gainers-losers')
|
|
71
|
+
response = get(path: '/cryptocurrency/trending/gainers-losers')
|
|
70
72
|
handle_response(response)
|
|
71
73
|
end
|
|
72
74
|
|
|
73
75
|
def trending_latest
|
|
74
|
-
response = get(path: '/trending/latest')
|
|
76
|
+
response = get(path: '/cryptocurrency/trending/latest')
|
|
75
77
|
handle_response(response)
|
|
76
78
|
end
|
|
77
79
|
|
|
78
80
|
def trending_most_visited
|
|
79
|
-
response = get(path: '/trending/most-visited')
|
|
81
|
+
response = get(path: '/cryptocurrency/trending/most-visited')
|
|
82
|
+
handle_response(response)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# /exchange
|
|
86
|
+
|
|
87
|
+
def exchange_assets(id:)
|
|
88
|
+
response = get(path: '/exchange/assets', args: {id: id})
|
|
89
|
+
handle_response(response)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def exchange_info(**args)
|
|
93
|
+
response = get(path: '/exchange/info', args: args)
|
|
94
|
+
handle_response(response)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def exchange_map(**args)
|
|
98
|
+
response = get(path: "/exchange/map", args: args)
|
|
99
|
+
handle_response(response)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def exchange_listings_latest(**args)
|
|
103
|
+
response = get(path: "/exchange/listings/latest", args: args)
|
|
104
|
+
handle_response(response)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def exchange_market_pairs_latest(**args)
|
|
108
|
+
response = get(path: "/exchange/market-pairs/latest", args: args)
|
|
109
|
+
handle_response(response)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def exchange_quotes_historical(**args)
|
|
113
|
+
response = get(path: "/exchange/quotes/historical", args: args)
|
|
114
|
+
handle_response(response)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def exchange_quotes_latest(**args)
|
|
118
|
+
response = get(path: "/exchange/quotes/latest", args: args)
|
|
80
119
|
handle_response(response)
|
|
81
120
|
end
|
|
82
121
|
end
|
data/test/V1/client_test.rb
CHANGED
|
@@ -137,6 +137,81 @@ describe CoinMarketCap::V1::Client do
|
|
|
137
137
|
end
|
|
138
138
|
end
|
|
139
139
|
|
|
140
|
+
describe "#exchange_assets" do
|
|
141
|
+
it "returns exchange assets" do
|
|
142
|
+
VCR.use_cassette('v1/exchange/assets') do
|
|
143
|
+
response = client.exchange_assets(id: 270)
|
|
144
|
+
_(response).must_include('data')
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
describe "#exchange_info" do
|
|
150
|
+
it "returns exchange info" do
|
|
151
|
+
VCR.use_cassette('v1/exchange/info') do
|
|
152
|
+
response = client.exchange_info(slug: 'binance,gdax')
|
|
153
|
+
_(response).must_include('data')
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
describe "#exchange_map" do
|
|
159
|
+
it "returns exchange map" do
|
|
160
|
+
VCR.use_cassette('v1/exchange/map') do
|
|
161
|
+
response = client.exchange_map
|
|
162
|
+
_(response).must_include('data')
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
describe "#exchange_listings_latest" do
|
|
168
|
+
it "returns latest exchange listings" do
|
|
169
|
+
VCR.use_cassette('v1/exchange/listings/latest') do
|
|
170
|
+
assert_raises CoinMarketCap::Error do
|
|
171
|
+
response = client.exchange_listings_latest
|
|
172
|
+
# _(response).must_include('data')
|
|
173
|
+
_(JSON.parse(response.body).dig('status', 'error_message')).must_equal "Your API Key subscription plan doesn't support this endpoint."
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
describe "#exchange_market_pairs_latest" do
|
|
180
|
+
it "returns latest exchange market pairs" do
|
|
181
|
+
VCR.use_cassette('v1/exchange/market-pairs/latest') do
|
|
182
|
+
assert_raises CoinMarketCap::Error do
|
|
183
|
+
response = client.exchange_market_pairs_latest(id: '1')
|
|
184
|
+
# _(response).must_include('data')
|
|
185
|
+
_(JSON.parse(response.body).dig('status', 'error_message')).must_equal "Your API Key subscription plan doesn't support this endpoint."
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
describe "#exchange_quotes_historical" do
|
|
192
|
+
it "returns historical exchange quotes" do
|
|
193
|
+
VCR.use_cassette('v1/exchange/quotes/historical') do
|
|
194
|
+
assert_raises CoinMarketCap::Error do
|
|
195
|
+
response = client.exchange_quotes_historical(id: '1')
|
|
196
|
+
# _(response).must_include('data')
|
|
197
|
+
_(JSON.parse(response.body).dig('status', 'error_message')).must_equal "Your API Key subscription plan doesn't support this endpoint."
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
describe "#exchange_quotes_latest" do
|
|
204
|
+
it "returns latest exchange quotes" do
|
|
205
|
+
VCR.use_cassette('v1/exchange/quotes/latest') do
|
|
206
|
+
assert_raises CoinMarketCap::Error do
|
|
207
|
+
response = client.exchange_quotes_latest(id: '1')
|
|
208
|
+
# _(response).must_include('data')
|
|
209
|
+
_(JSON.parse(response.body).dig('status', 'error_message')).must_equal "Your API Key subscription plan doesn't support this endpoint."
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
140
215
|
describe "#handle_response" do
|
|
141
216
|
it "handles a successful response" do
|
|
142
217
|
raw_response = OpenStruct.new(success?: true, body: '{"data": {}}')
|
data/test/client_test.rb
CHANGED
|
@@ -223,4 +223,149 @@ describe CoinMarketCap::Client do
|
|
|
223
223
|
mocked_client.verify
|
|
224
224
|
end
|
|
225
225
|
end
|
|
226
|
+
|
|
227
|
+
describe "#exchange_assets" do
|
|
228
|
+
it "calls the V1 client" do
|
|
229
|
+
mocked_client = Minitest::Mock.new
|
|
230
|
+
mocked_client.expect(:exchange_assets, {'data' => []}) do |kwargs|
|
|
231
|
+
kwargs[:id] == 1
|
|
232
|
+
end
|
|
233
|
+
client.stub :v1_client, mocked_client do
|
|
234
|
+
client.exchange_assets(id: 1)
|
|
235
|
+
end
|
|
236
|
+
mocked_client.verify
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
describe "#exchange_info" do
|
|
241
|
+
context "WITHOUT args" do
|
|
242
|
+
it "calls the V1 client" do
|
|
243
|
+
mocked_client = Minitest::Mock.new
|
|
244
|
+
mocked_client.expect(:exchange_info, true, [])
|
|
245
|
+
client.stub :v1_client, mocked_client do
|
|
246
|
+
client.exchange_info
|
|
247
|
+
end
|
|
248
|
+
mocked_client.verify
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
context "WITH args" do
|
|
253
|
+
it "calls the V1 client" do
|
|
254
|
+
mocked_client = Minitest::Mock.new
|
|
255
|
+
mocked_client.expect(:exchange_info, {'data' => []}) do |kwargs|
|
|
256
|
+
kwargs[:id] == 1
|
|
257
|
+
end
|
|
258
|
+
client.stub :v1_client, mocked_client do
|
|
259
|
+
client.exchange_info(id: 1)
|
|
260
|
+
end
|
|
261
|
+
mocked_client.verify
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
describe "#exchange_map" do
|
|
267
|
+
context "WITHOUT args" do
|
|
268
|
+
it "calls the V1 client" do
|
|
269
|
+
mocked_client = Minitest::Mock.new
|
|
270
|
+
mocked_client.expect(:exchange_map, true, [])
|
|
271
|
+
client.stub :v1_client, mocked_client do
|
|
272
|
+
client.exchange_map
|
|
273
|
+
end
|
|
274
|
+
mocked_client.verify
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
context "WITH args" do
|
|
279
|
+
it "calls the V1 client" do
|
|
280
|
+
mocked_client = Minitest::Mock.new
|
|
281
|
+
mocked_client.expect(:exchange_map, {'data' => []}) do |kwargs|
|
|
282
|
+
kwargs[:listing_status] == 'active'
|
|
283
|
+
end
|
|
284
|
+
client.stub :v1_client, mocked_client do
|
|
285
|
+
client.exchange_map(listing_status: 'active')
|
|
286
|
+
end
|
|
287
|
+
mocked_client.verify
|
|
288
|
+
end
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
describe "#exchange_listings" do
|
|
293
|
+
context "WITHOUT args" do
|
|
294
|
+
it "calls the V1 client exchange_listings_latest method" do
|
|
295
|
+
mocked_client = Minitest::Mock.new
|
|
296
|
+
mocked_client.expect(:exchange_listings_latest, true, [])
|
|
297
|
+
client.stub :v1_client, mocked_client do
|
|
298
|
+
client.exchange_listings
|
|
299
|
+
end
|
|
300
|
+
mocked_client.verify
|
|
301
|
+
end
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
context "WITH args" do
|
|
305
|
+
it "calls the V1 client exchange_listings_latest method" do
|
|
306
|
+
mocked_client = Minitest::Mock.new
|
|
307
|
+
mocked_client.expect(:exchange_listings_latest, {'data' => []}) do |kwargs|
|
|
308
|
+
kwargs[:limit] == 10
|
|
309
|
+
end
|
|
310
|
+
client.stub :v1_client, mocked_client do
|
|
311
|
+
client.exchange_listings(limit: 10)
|
|
312
|
+
end
|
|
313
|
+
mocked_client.verify
|
|
314
|
+
end
|
|
315
|
+
end
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
describe "#exchange_market_pairs" do
|
|
319
|
+
context "WITHOUT args" do
|
|
320
|
+
it "calls the V1 client exchange_market_pairs_latest method" do
|
|
321
|
+
mocked_client = Minitest::Mock.new
|
|
322
|
+
mocked_client.expect(:exchange_market_pairs_latest, true, [])
|
|
323
|
+
client.stub :v1_client, mocked_client do
|
|
324
|
+
client.exchange_market_pairs
|
|
325
|
+
end
|
|
326
|
+
mocked_client.verify
|
|
327
|
+
end
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
context "WITH args" do
|
|
331
|
+
it "calls the V1 client exchange_market_pairs_latest method" do
|
|
332
|
+
mocked_client = Minitest::Mock.new
|
|
333
|
+
mocked_client.expect(:exchange_market_pairs_latest, {'data' => []}) do |kwargs|
|
|
334
|
+
kwargs[:id] == 1
|
|
335
|
+
end
|
|
336
|
+
client.stub :v1_client, mocked_client do
|
|
337
|
+
client.exchange_market_pairs(id: 1)
|
|
338
|
+
end
|
|
339
|
+
mocked_client.verify
|
|
340
|
+
end
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
describe "#exchange_quotes" do
|
|
345
|
+
context "when historical is false (default)" do
|
|
346
|
+
it "calls the V1 client exchange_quotes_latest method" do
|
|
347
|
+
mocked_client = Minitest::Mock.new
|
|
348
|
+
mocked_client.expect(:exchange_quotes_latest, {'data' => []}) do |kwargs|
|
|
349
|
+
kwargs[:id] == 1
|
|
350
|
+
end
|
|
351
|
+
client.stub :v1_client, mocked_client do
|
|
352
|
+
client.exchange_quotes(id: 1)
|
|
353
|
+
end
|
|
354
|
+
mocked_client.verify
|
|
355
|
+
end
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
context "when historical is true" do
|
|
359
|
+
it "calls the V1 client exchange_quotes_historical method" do
|
|
360
|
+
mocked_client = Minitest::Mock.new
|
|
361
|
+
mocked_client.expect(:exchange_quotes_historical, {'data' => []}) do |kwargs|
|
|
362
|
+
kwargs[:id] == 1
|
|
363
|
+
end
|
|
364
|
+
client.stub :v1_client, mocked_client do
|
|
365
|
+
client.exchange_quotes(historical: true, id: 1)
|
|
366
|
+
end
|
|
367
|
+
mocked_client.verify
|
|
368
|
+
end
|
|
369
|
+
end
|
|
370
|
+
end
|
|
226
371
|
end
|
data/test/helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: coinmarketcap.rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- thoran
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: http.rb
|
|
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
61
61
|
- !ruby/object:Gem::Version
|
|
62
62
|
version: '0'
|
|
63
63
|
requirements: []
|
|
64
|
-
rubygems_version:
|
|
64
|
+
rubygems_version: 4.0.6
|
|
65
65
|
specification_version: 4
|
|
66
66
|
summary: Access the coinmarketcap.com API with Ruby.
|
|
67
67
|
test_files: []
|