coinmarketcap.rb 0.4.1 → 0.6.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9409ddfa64039ff7b7d59474283bd3a5053acbfd9094c4a6df984611ec8bc9a9
4
- data.tar.gz: 5432428de98a131ba5210c1b0b62bfe56feaee316f2986e4d0a8285532a87413
3
+ metadata.gz: 4e2248fec84988c40e7973c1ada6f06019f2d1c07a5570af95c469a49de2afd2
4
+ data.tar.gz: 3f030d0f7b25646ceba951e3c5271586f14794db38913e7b9d5dfc965f9c47ea
5
5
  SHA512:
6
- metadata.gz: 0ace0916f6a52e6539de74818628ed9334dcfcccee327c5d52a57603563ec0642833537f3c4d8b19e1c71daaa26b95374aa829d88d72bf41b727faa11cac0d75
7
- data.tar.gz: 938dd5c24f42f0d18b7e9b80e309f57fa01543a0278f779c19c47c7bac660d6c7a17b5e9ca84bd507dde0f8c4b81eca5784f3305415eed4d2f7af2992bdf0742
6
+ metadata.gz: 53aad33c51a71a6ef91f919bf5050c2925e12cc37ff5742c19843c8c2eb1b8def3e8d8e67762d14785bb654b9b4195530a83e2405c627158157b9a50ff83bbdc
7
+ data.tar.gz: 3e7173c834af80b8004d4627c425c085144502d849dacc0c9d47105943f06792eca95a913af96f69eab187b0f16ffabdfb6b8b40d2032922d87208c5a893831f
data/Gemfile CHANGED
@@ -6,4 +6,5 @@ group :development, :test do
6
6
  gem 'minitest'
7
7
  gem 'minitest-spec-context'
8
8
  gem 'vcr'
9
+ gem 'webmock'
9
10
  end
data/README.md CHANGED
@@ -69,7 +69,7 @@ coinmarketcap_client.info(id: 123)
69
69
  coinmarketcap_client.latest_listings
70
70
  ```
71
71
 
72
- ### Latest OHLCV Price Data
72
+ ### Latest Price Data (OHLCV)
73
73
  ```ruby
74
74
  coinmarketcap_client.latest_price_data
75
75
  ```
@@ -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-03-30'
8
6
 
9
7
  spec.summary = "Access the coinmarketcap.com API with Ruby."
10
8
  spec.description = "Access the coinmarketcap.com API with Ruby."
@@ -47,8 +47,8 @@ module CoinMarketCap
47
47
  v1_client.map
48
48
  end
49
49
 
50
- def latest_listings
51
- v2_client.market_pairs_latest
50
+ def latest_listings(**args)
51
+ v2_client.market_pairs_latest(args)
52
52
  end
53
53
 
54
54
  def latest_price_data
@@ -26,57 +26,96 @@ module CoinMarketCap
26
26
 
27
27
  class << self
28
28
  def path_prefix
29
- '/v1/cryptocurrency'
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
- def listings_latest
59
- response = get(path: '/listings/latest')
60
+ def listings_latest(**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
@@ -32,8 +32,8 @@ module CoinMarketCap
32
32
  handle_response(response)
33
33
  end
34
34
 
35
- def market_pairs_latest
36
- response = get(path: '/market-pairs/latest')
35
+ def market_pairs_latest(**args)
36
+ response = get(path: '/market-pairs/latest', args: args)
37
37
  handle_response(response)
38
38
  end
39
39
 
@@ -2,5 +2,5 @@
2
2
  # CoinMarketCap::VERSION
3
3
 
4
4
  module CoinMarketCap
5
- VERSION = '0.4.1'
5
+ VERSION = '0.6.0'
6
6
  end
@@ -67,12 +67,26 @@ describe CoinMarketCap::V1::Client do
67
67
  end
68
68
 
69
69
  describe "#listings_latest" do
70
- it "returns an array of latest prices" do
71
- VCR.use_cassette('v1/cryptocurrency/listings/latest') do
72
- response = client.listings_latest
73
- _(response).must_include('data')
74
- _(response['data']).must_be_kind_of(Array)
75
- _(response['data'][0]).must_be_kind_of(Hash)
70
+ context "WITHOUT args" do
71
+ it "returns an array of latest prices" do
72
+ VCR.use_cassette('v1/cryptocurrency/listings/latest') do
73
+ response = client.listings_latest
74
+ _(response).must_include('data')
75
+ _(response['data']).must_be_kind_of(Array)
76
+ _(response['data'][0]).must_be_kind_of(Hash)
77
+ end
78
+ end
79
+ end
80
+
81
+ context "#WITH args" do
82
+ it "returns an array of latest prices" do
83
+ VCR.use_cassette('v1/cryptocurrency/listings/latest_with_args') do
84
+ response = client.listings_latest(limit: 10)
85
+ _(response).must_include('data')
86
+ _(response['data']).must_be_kind_of(Array)
87
+ _(response['data'].count).must_equal(10)
88
+ _(response['data'][0]).must_be_kind_of(Hash)
89
+ end
76
90
  end
77
91
  end
78
92
  end
@@ -123,6 +137,81 @@ describe CoinMarketCap::V1::Client do
123
137
  end
124
138
  end
125
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
+
126
215
  describe "#handle_response" do
127
216
  it "handles a successful response" do
128
217
  raw_response = OpenStruct.new(success?: true, body: '{"data": {}}')
@@ -15,12 +15,26 @@ describe CoinMarketCap::V2::Client do
15
15
  end
16
16
 
17
17
  describe "#market_pairs_latest" do
18
- it "retrieves the latest market pairs" do
19
- VCR.use_cassette('v2/cryptocurrency/market-pairs/latest') do
20
- assert_raises CoinMarketCap::Error do
21
- response = client.market_pairs_latest
22
- # _(response).must_include('data')
23
- _(JSON.parse(response.body).dig('status', 'error_message')).must_equal "Your API Key subscription plan doesn't support this endpoint."
18
+ context "WITHOUT args" do
19
+ it "retrieves the latest market pairs" do
20
+ VCR.use_cassette('v2/cryptocurrency/market-pairs/latest') do
21
+ assert_raises CoinMarketCap::Error do
22
+ response = client.market_pairs_latest
23
+ # _(response).must_include('data')
24
+ _(JSON.parse(response.body).dig('status', 'error_message')).must_equal "Your API Key subscription plan doesn't support this endpoint."
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ context "#WITH args" do
31
+ it "retrieves the latest market pairs" do
32
+ VCR.use_cassette('v2/cryptocurrency/market-pairs/latest_with_args') do
33
+ assert_raises CoinMarketCap::Error do
34
+ response = client.market_pairs_latest(limit: 10)
35
+ # _(response).must_include('data')
36
+ _(JSON.parse(response.body).dig('status', 'error_message')).must_equal "Your API Key subscription plan doesn't support this endpoint."
37
+ end
24
38
  end
25
39
  end
26
40
  end
data/test/client_test.rb CHANGED
@@ -131,13 +131,26 @@ describe CoinMarketCap::Client do
131
131
  end
132
132
 
133
133
  describe "#latest_listings" do
134
- it "calls the V2 client" do
135
- mocked_client = Minitest::Mock.new
136
- mocked_client.expect(:market_pairs_latest, true, [])
137
- client.stub :v2_client, mocked_client do
138
- client.latest_listings
134
+ context "WITHOUT args" do
135
+ it "calls the V2 client" do
136
+ mocked_client = Minitest::Mock.new
137
+ mocked_client.expect(:market_pairs_latest, true, [{}])
138
+ client.stub :v2_client, mocked_client do
139
+ client.latest_listings
140
+ end
141
+ mocked_client.verify
142
+ end
143
+ end
144
+
145
+ context "WITH args" do
146
+ it "calls the V2 client" do
147
+ mocked_client = Minitest::Mock.new
148
+ mocked_client.expect(:market_pairs_latest, true, [{limit: 10}])
149
+ client.stub :v2_client, mocked_client do
150
+ client.latest_listings(limit: 10)
151
+ end
152
+ mocked_client.verify
139
153
  end
140
- mocked_client.verify
141
154
  end
142
155
  end
143
156
 
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.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-30 00:00:00.000000000 Z
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: 3.6.6
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: []