coingecko_ruby 0.3.1 → 0.4.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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +27 -0
  4. data/README.md +5 -5
  5. data/fixtures/vcr_cassettes/test_that_it_gets_a_specific_exchange_ticker_from_an_exchange.yml +70 -0
  6. data/fixtures/vcr_cassettes/test_that_it_gets_btc_to_eth_exchange_rate.yml +49 -0
  7. data/fixtures/vcr_cassettes/test_that_it_gets_btc_to_usd_exchange_rate.yml +49 -0
  8. data/fixtures/vcr_cassettes/test_that_it_gets_daily_historical_prices_for_one_coin.yml +49 -0
  9. data/fixtures/vcr_cassettes/test_that_it_gets_historical_price_for_one_coin_at_a_previous_date.yml +49 -0
  10. data/fixtures/vcr_cassettes/test_that_it_gets_hourly_historical_prices_for_one_coin.yml +49 -0
  11. data/fixtures/vcr_cassettes/test_that_it_gets_indexes_by_market_id_and_coin_id.yml +66 -0
  12. data/fixtures/vcr_cassettes/test_that_it_gets_last_7_days_exchange_volume_from_an_exchange.yml +49 -0
  13. data/fixtures/vcr_cassettes/test_that_it_gets_market_data_for_a_coin.yml +98 -0
  14. data/fixtures/vcr_cassettes/test_that_it_gets_market_data_for_a_coin_in_myr.yml +49 -0
  15. data/fixtures/vcr_cassettes/test_that_it_gets_market_data_for_multiple_coins_in_eth.yml +49 -0
  16. data/fixtures/vcr_cassettes/test_that_it_gets_minutely_historical_prices_for_one_coin.yml +49 -0
  17. data/fixtures/vcr_cassettes/test_that_it_gets_ohlc_data_for_one_coin_in_the_last_30_days_in_myr.yml +47 -0
  18. data/fixtures/vcr_cassettes/test_that_it_gets_ohlc_data_for_one_coin_in_the_last_7_days.yml +47 -0
  19. data/fixtures/vcr_cassettes/test_that_it_gets_price_for_one_coin.yml +49 -0
  20. data/fixtures/vcr_cassettes/test_that_it_gets_price_for_one_coin_in_a_different_currency.yml +49 -0
  21. data/lib/coingecko_ruby/client.rb +6 -0
  22. data/lib/coingecko_ruby/client/categories.rb +21 -6
  23. data/lib/coingecko_ruby/client/coins.rb +28 -15
  24. data/lib/coingecko_ruby/client/derivatives.rb +30 -9
  25. data/lib/coingecko_ruby/client/events.rb +21 -6
  26. data/lib/coingecko_ruby/client/exchanges.rb +45 -13
  27. data/lib/coingecko_ruby/client/finance.rb +14 -4
  28. data/lib/coingecko_ruby/client/indexes.rb +22 -7
  29. data/lib/coingecko_ruby/client/infos.rb +27 -8
  30. data/lib/coingecko_ruby/client/prices.rb +74 -30
  31. data/lib/coingecko_ruby/connection.rb +5 -9
  32. data/lib/coingecko_ruby/version.rb +1 -1
  33. metadata +3 -2
@@ -9,7 +9,7 @@ module CoingeckoRuby
9
9
  # @return [Array<Hash>] each finance platform's name, category, url, facts (description), and centralized status.
10
10
  #
11
11
  # @example Get all finance platforms.
12
- # client.get_finance_platforms
12
+ # client.finance_platforms
13
13
  # @example Sample response object (truncated)
14
14
  # [
15
15
  # {
@@ -34,8 +34,13 @@ module CoingeckoRuby
34
34
  # "website_url"=>"https://cobo.com/"
35
35
  # }
36
36
  # ]
37
+ def finance_platforms(**options)
38
+ get 'finance_platforms', options
39
+ end
40
+
41
+ # @deprecated Use {#finance_platforms} instead
37
42
  def get_finance_platforms(options: {})
38
- get 'finance_platforms', { options: options }
43
+ finance_platforms(**options)
39
44
  end
40
45
 
41
46
  # Fetches the list of finance products (e.g. Binance Savings, Nexo, Fulcrum) listed in CoinGecko.
@@ -48,7 +53,7 @@ module CoingeckoRuby
48
53
  # @return [Array<Hash>] each finance product's platform, identifier, supply and borrow rate percentage, and the product duration data.
49
54
  #
50
55
  # @example Get all finance products.
51
- # client.get_finance_products
56
+ # client.finance_products
52
57
  # @example Sample response object (truncated)
53
58
  # [
54
59
  # {"platform"=>"Binance Savings",
@@ -82,8 +87,13 @@ module CoingeckoRuby
82
87
  # "value_at"=>0,
83
88
  # "redeem_at"=>0}
84
89
  # ]
90
+ def finance_products(**options)
91
+ get 'finance_products', options
92
+ end
93
+
94
+ # @deprecated Use {#finance_products} instead
85
95
  def get_finance_products(options: {})
86
- get 'finance_products', { options: options }
96
+ finance_products(**options)
87
97
  end
88
98
  end
89
99
  end
@@ -9,7 +9,7 @@ module CoingeckoRuby
9
9
  # @return [Array<Hash>] each index's id, name, market name, last done, and whether it's a multiasset composite index.
10
10
  #
11
11
  # @example Get all market indexes.
12
- # client.get_indexes
12
+ # client.indexes
13
13
  # @example Sample response object
14
14
  # [
15
15
  # {"name"=>"CoinFLEX (Futures) DFN",
@@ -28,8 +28,13 @@ module CoingeckoRuby
28
28
  # "last"=>nil,
29
29
  # "is_multi_asset_composite"=>false}
30
30
  # ]
31
+ def indexes(**options)
32
+ get 'indexes', options
33
+ end
34
+
35
+ # @deprecated Use {#indexes} instead
31
36
  def get_indexes(options: {})
32
- get 'indexes', { options: options }
37
+ indexes(**options)
33
38
  end
34
39
 
35
40
  # Fetches the ids of market indexes listed in CoinGecko.
@@ -37,7 +42,7 @@ module CoingeckoRuby
37
42
  # @return [Array<Hash>] each index's id and name.
38
43
  #
39
44
  # @example Get all market index ids and names.
40
- # client.get_indexes_ids
45
+ # client.index_ids
41
46
  # @example Sample response object
42
47
  # [
43
48
  # {"id"=>"LINK", "name"=>"Bibox (Futures) LINK"},
@@ -45,19 +50,24 @@ module CoingeckoRuby
45
50
  # {"id"=>"XRP", "name"=>"Bibox (Futures) XRP"},
46
51
  # {"id"=>"ETH", "name"=>"Crypto.com (Futures) ETH"}
47
52
  # ]
48
- def get_indexes_ids
53
+ def index_ids
49
54
  get 'indexes/list'
50
55
  end
51
56
 
57
+ # @deprecated Use {#index_ids} instead
58
+ def get_indexes_ids
59
+ index_ids
60
+ end
61
+
52
62
  # Fetches the list of indexes based on the market and index given.
53
63
  #
54
64
  # @param market_id [String] filter results by the market id.
55
- # @param index_id [String] filter indexes from the given market by the index id.
65
+ # @param coin_id [String] filter indexes from the given market by the index id.
56
66
  #
57
67
  # @return [Array<Hash>] the index's name, market, last done, and whether it's a multiasset composite index.
58
68
  #
59
69
  # @example Get all BTC indexes in the CME Futures market.
60
- # client.get_indexes_by_market_and_index(market_id: 'cme_futures', index_id: 'btc')
70
+ # client.indexes_by_market_and_coin(market_id: 'cme_futures', coin_id: 'btc')
61
71
  # @example Sample response object
62
72
  # {
63
73
  # "name"=>"CME Bitcoin Futures BTC",
@@ -65,8 +75,13 @@ module CoingeckoRuby
65
75
  # "last"=>nil,
66
76
  # "is_multi_asset_composite"=>false
67
77
  # }
78
+ def indexes_by_market_and_coin(market_id, coin_id, **options)
79
+ get "indexes/#{market_id}/#{coin_id}", options
80
+ end
81
+
82
+ # @deprecated Use {#indexes_by_market_and_coin} instead
68
83
  def get_indexes_by_market_and_index(market_id:, index_id:, options: {})
69
- get "indexes/#{market_id}/#{index_id}", { options: options }
84
+ indexes_by_market_and_index(market_id, index_id, **options)
70
85
  end
71
86
  end
72
87
  end
@@ -6,7 +6,7 @@ module CoingeckoRuby
6
6
  # @return [Hash] global crypto data (e.g. market cap, total volume, active ICOs, etc.)
7
7
  #
8
8
  # @example Get global crypto data.
9
- # client.get_global_crypto_data
9
+ # client.global_crypto_data
10
10
  # @example Sample response object (truncated)
11
11
  # {
12
12
  # "data" => {
@@ -35,16 +35,21 @@ module CoingeckoRuby
35
35
  # "updated_at" => 1621344957
36
36
  # }
37
37
  # }
38
- def get_global_crypto_data
38
+ def global_crypto_data
39
39
  get 'global'
40
40
  end
41
41
 
42
+ # @deprecated Use {#global_crypto_data} instead
43
+ def get_global_crypto_data
44
+ global_crypto_data
45
+ end
46
+
42
47
  # Fetches global crypto data from CoinGecko.
43
48
  #
44
49
  # @return [Hash] global defi data.
45
50
  #
46
51
  # @example Get global defi data.
47
- # client.get_global_defi_data
52
+ # client.global_defi_data
48
53
  # @example Sample response object
49
54
  # {
50
55
  # "data" => {
@@ -59,16 +64,21 @@ module CoingeckoRuby
59
64
  # "top_coin_defi_dominance" => 14.449398175884316
60
65
  # }
61
66
  # }
62
- def get_global_defi_data
67
+ def global_defi_data
63
68
  get 'global/decentralized_finance_defi'
64
69
  end
65
70
 
71
+ # @deprecated Use {#global_defi_data} instead
72
+ def get_global_defi_data
73
+ global_defi_data
74
+ end
75
+
66
76
  # Fetches the top 7 coin searches from CoinGecko in the last 24 hours.
67
77
  #
68
78
  # @return [Hash] the ternding searches and its information.
69
79
  #
70
80
  # @example Get trending searches in the last 24 hours.
71
- # client.get_trending_searches
81
+ # client.trending_searches
72
82
  # @example Sample response object (truncated)
73
83
  # {
74
84
  # "coins" => [{
@@ -92,10 +102,15 @@ module CoingeckoRuby
92
102
  # ],
93
103
  # "exchanges" => []
94
104
  # }
95
- def get_trending_searches
105
+ def trending_searches
96
106
  get 'search/trending'
97
107
  end
98
108
 
109
+ # @deprecated Use {#trending_searches} instead
110
+ def get_trending_searches
111
+ trending_searches
112
+ end
113
+
99
114
  # Fetches coin and/or market status updates.
100
115
  #
101
116
  # @option options [String] :category filter results by the given category. Valid values: general, milestone, partnership, exchange_listing, software_release, fund_movement, new_listings, event
@@ -106,7 +121,7 @@ module CoingeckoRuby
106
121
  # @return [Hash] the list of status updates and its information.
107
122
  #
108
123
  # @example Get a single status update.
109
- # client.get_status_updates(options: { per_page: 1 })
124
+ # client.status_updates(per_page: 1)
110
125
  # @example Sample response object
111
126
  # {
112
127
  # "status_updates" => [{
@@ -147,8 +162,12 @@ module CoingeckoRuby
147
162
  # }
148
163
  # }]
149
164
  # }
165
+ def status_updates(**options)
166
+ get 'status_updates', options
167
+ end
168
+
150
169
  def get_status_updates(options: {})
151
- get 'status_updates', { options: options }
170
+ status_updates(**options)
152
171
  end
153
172
  end
154
173
  end
@@ -2,8 +2,8 @@ module CoingeckoRuby
2
2
  class Client
3
3
  module Prices
4
4
  # Fetches the current price for a coin in the given coin or currency.
5
- # @param id [String] the coin id to fetch.
6
- # @param currency [String] the currency to display the coin's price.
5
+ # @param ids [String, Array] the coin id or array of ids to fetch.
6
+ # @param currency [String, Array] the currency or array of currencies to display the coin's price. Defaults to 'USD'
7
7
  # @option options [Boolean] :include_market_cap include market cap data.
8
8
  # @option options [Boolean] :include_24hr_vol include 24 hour volume data.
9
9
  # @option options [Boolean] :include_24hr_change include 24 hour price change data.
@@ -12,7 +12,7 @@ module CoingeckoRuby
12
12
  # @return [Hash] returns the given coin id and its current price.
13
13
  #
14
14
  # @example Fetch the current price in USD for Bitcoin.
15
- # client.get_price(id: 'bitcoin', currency: 'usd')
15
+ # client.price('bitcoin', currency: 'usd')
16
16
  # @example Sample response object
17
17
  # {
18
18
  # "bitcoin" => {
@@ -20,7 +20,7 @@ module CoingeckoRuby
20
20
  # }
21
21
  # }
22
22
  # @example Fetch the current price, market cap, 24 hour volume, 24 hour price change and last updated at for Bitcoin.
23
- # client.get_price(id: 'bitcoin', currency: 'usd', options: { include_market_cap: true, include_24hr_vol: true, include_24hr_change: true, include_last_updated_at: true })
23
+ # client.price('bitcoin', 'usd', include_market_cap: true, include_24hr_vol: true, include_24hr_change: true, include_last_updated_at: true)
24
24
  # @example Sample response object
25
25
  # {
26
26
  # "bitcoin" => {
@@ -31,18 +31,30 @@ module CoingeckoRuby
31
31
  # "last_updated_at" => 1621142197 # last updated at UNIX timestamp for the given coin
32
32
  # }
33
33
  # }
34
+ def price(ids, currency: 'usd', **options)
35
+ ids = ids.join(',') if ids.is_a? Array
36
+ currency = currency.join(',') if currency.is_a? Array
37
+ get 'simple/price', { ids: ids, vs_currencies: currency, **options }
38
+ end
39
+
40
+ # @see Alias for {#price}
41
+ def prices(ids, currency: 'usd', **options)
42
+ price(ids, currency: currency, **options)
43
+ end
44
+
45
+ # @deprecated Use {#price} or {#prices} instead
34
46
  def get_price(id:, currency: 'usd', options: {})
35
- get 'simple/price', { ids: id, vs_currencies: currency, options: options }
47
+ price(id, currency, **options)
36
48
  end
37
49
 
38
50
  # Fetches historical price data for a coin at a given date.
39
51
  # @param id [String] the coin id to fetch.
40
- # @param date [String] the date to fetch the historical price, date given must be in the form of 'DD-MM-YYYY' (e.g: '14-05-2021').
52
+ # @param date [String] the date to fetch the historical price, date given must be in the form of 'DD-MM-YYYY' (e.g: '14-05-2021'). Defaults to today's date.
41
53
  #
42
54
  # @return [Hash] returns the coin's historical price data on the given date.
43
55
  #
44
56
  # @example Fetch Bitcoin's price on 30th December, 2017.
45
- # client.get_historical_price_on_date(id: 'bitcoin', date: '30-12-2017')
57
+ # client.historical_price('bitcoin', date: '30-12-2017')
46
58
  # @example Sample response object (truncated)
47
59
  # {
48
60
  # "id": "bitcoin",
@@ -107,19 +119,26 @@ module CoingeckoRuby
107
119
  # "bing_matches": null
108
120
  # }
109
121
  # }
122
+ def historical_price(id, date:, **options)
123
+ date = Time.now.strftime('%d-%m-%Y') if date.nil?
124
+
125
+ get "coins/#{id}/history", { date: date, **options }
126
+ end
127
+
128
+ # @deprecated Use {#historical_price} instead
110
129
  def get_historical_price_on_date(id:, date:)
111
- get "coins/#{id}/history", { date: date }
130
+ historical_price(id, date: date)
112
131
  end
113
132
 
114
133
  # Fetches a coin's historical price data in 5 - 10 minutes ranges.
115
134
  # @note Minutely historical data is only available within the last 24 hours.
116
135
  # @param id [String] the coin id to fetch.
117
- # @param currency [String] the currency used to display minutely historical price.
136
+ # @param currency [String] the currency used to display minutely historical price. Defaults to 'USD'
118
137
  #
119
138
  # @return [Hash] returns the coin's minutely historical price data within the last 24 hours.
120
139
  #
121
140
  # @example Fetch Bitcoin's minutely historical price within the last 24 hours.
122
- # client.get_minutely_historical_prices(id: 'bitcoin')
141
+ # client.minutely_historical_price('bitcoin')
123
142
  # @example Sample response object (truncated)
124
143
  # {
125
144
  # "prices" => [
@@ -138,20 +157,25 @@ module CoingeckoRuby
138
157
  # [1621058047104, 57046967935.326035],
139
158
  # ]
140
159
  # }
160
+ def minutely_historical_price(id, currency: 'usd', **options)
161
+ get "coins/#{id}/market_chart", { vs_currency: currency, days: 1, **options }
162
+ end
163
+
164
+ # @deprecated Use {#minutely_historical_price} instead
141
165
  def get_minutely_historical_prices(id:, currency: 'usd')
142
- get "coins/#{id}/market_chart", { id: id, vs_currency: currency, days: 1 }
166
+ minutely_historical_price(id, currency: currency)
143
167
  end
144
168
 
145
169
  # Fetches a coin's historical price data in 1 hour ranges.
146
170
  # @note Hourly historical data is only available within the last 90 days.
147
171
  # @param id [String] the coin id to fetch.
148
- # @param days [Integer] the number of days to fetch hourly historical prices (min: 1 day, max: 90 days)
149
- # @param currency [String] the currency used to display hourly historical price.
172
+ # @param currency [String] the currency used to display hourly historical price. Defaults to 'USD'
173
+ # @param days [Integer] the number of days to fetch hourly historical prices (min: 1 day, max: 90 days). Defaults to 7 days
150
174
  #
151
175
  # @return [Hash] returns the coin's hourly historical price data within the number of days given.
152
176
  #
153
- # @example Fetch Bitcoin's hourly historical price within the last 7 days.
154
- # client.get_hourly_historical_prices(id: 'bitcoin', days: 7)
177
+ # @example Fetch Bitcoin's hourly historical price in USD within the last 7 days.
178
+ # client.hourly_historical_price('bitcoin', days: 7)
155
179
  # @example Sample response object (truncated)
156
180
  # {
157
181
  # "prices" => [
@@ -168,21 +192,26 @@ module CoingeckoRuby
168
192
  # [1620547381049, 72064327648.28767],
169
193
  # ]
170
194
  # }
171
- def get_hourly_historical_prices(id:, days:, currency: 'usd')
172
- return get_daily_historical_prices(id: id, days: days) if days > 90
195
+ def hourly_historical_price(id, currency: 'usd', days: 7, **options)
196
+ return daily_historical_price(id, currrency: currency, days: days) if days > 90
173
197
 
174
- get "coins/#{id}/market_chart", { vs_currency: currency, days: days }
198
+ get "coins/#{id}/market_chart", { vs_currency: currency, days: days, **options }
199
+ end
200
+
201
+ # @deprecated Use {#hourly_historical_price} instead
202
+ def get_hourly_historical_prices(id:, days:, currency: 'usd')
203
+ hourly_historical_price(id, currency: currency, days: days)
175
204
  end
176
205
 
177
206
  # Fetches a coin's historical price data in daily ranges.
178
207
  # @param id [String] the coin id to fetch.
179
- # @param days [Integer] the number of days to fetch daily historical prices.
180
- # @param currency [String] the currency used to display daily historical price.
208
+ # @param days [Integer] the number of days to fetch daily historical prices. Defaults to 7 days.
209
+ # @param currency [String] the currency used to display daily historical price. Defaults to USD.
181
210
  #
182
211
  # @return [Hash] returns the coin's daily historical price data within the number of days given.
183
212
  #
184
213
  # @example Fetch Bitcoin's daily historical price within the last 14 days.
185
- # client.get_daily_historical_prices(id: 'bitcoin', days: 14)
214
+ # client.daily_historical_prices('bitcoin', days: 14)
186
215
  # @example Sample response object (truncated)
187
216
  # {
188
217
  # "prices" => [
@@ -199,30 +228,40 @@ module CoingeckoRuby
199
228
  # [1620172800000, 71296763919.13268],
200
229
  # ]
201
230
  # }
231
+ def daily_historical_price(id, currency: 'usd', days: 7, **options)
232
+ get "coins/#{id}/market_chart", { vs_currency: currency, days: days, interval: 'daily', **options }
233
+ end
234
+
235
+ # @deprecated Use {#daily_historical_price} instead
202
236
  def get_daily_historical_prices(id:, days:, currency: 'usd')
203
- get "coins/#{id}/market_chart", { vs_currency: currency, days: days, interval: 'daily' }
237
+ daily_historical_price(id, currency: currency, days: days)
204
238
  end
205
239
 
206
240
  # Fetches a coin's open, high, low, and close (OHLC) data within the number of days given.
207
241
  # @param id [String] the coin id to fetch.
208
- # @param days [Integer, String] the number of days to fetch daily historical prices. Valid values: 1/7/14/30/90/180/365/'max'
209
- # @param currency [String] the currency to display OHLC data.
242
+ # @param days [Integer, String] the number of days to fetch daily historical prices. Valid values: 1/7/14/30/90/180/365/'max'. Defaults to 7 days.
243
+ # @param currency [String] the currency to display OHLC data. Defaults to 'USD'.
210
244
  #
211
245
  # @return [Array<Array<String, Float>>] returns the coin's OHLC data within the number of days given.
212
246
  # If the number of days given is between 1-2 days, the OHLC data is returned in 30-minute intervals.
213
247
  # If the number of days given is between 3-30 days, the OHLC data is returned in 4-hour intervals.
214
248
  # If the number of days given is more than 30 days, the OHLC data is returned in 4-day intervals.
215
249
  #
216
- # @example Fetch Bitcoin's OHLC data in USD within the last 7 days.
217
- # client.get_ohlc(id: 'bitcoin', days: 7, currency: 'usd')
250
+ # @example Fetch Bitcoin's OHLC data within the last 7 days.
251
+ # client.ohlc('bitcoin', days: 7)
218
252
  # @example Sample response object (truncated)
219
253
  # [
220
254
  # [1620547200000, 58384.27, 58384.27, 58384.27, 58384.27], # [UNIX timestamp for OHLC data, open, high, low, close]
221
255
  # [1620561600000, 58022.03, 58214.96, 57943.18, 58048.35],
222
256
  # [1620576000000, 57956.7, 57956.7, 56636.68, 57302.22],
223
257
  # ]
258
+ def ohlc(id, currency: 'usd', days: 7, **options)
259
+ get "coins/#{id}/ohlc", { vs_currency: currency, days: days, **options }
260
+ end
261
+
262
+ # @deprecated Use {#ohlc} instead
224
263
  def get_ohlc(id:, days:, currency: 'usd')
225
- get "coins/#{id}/ohlc", { vs_currency: currency, days: days }
264
+ ohlc(id, currency: currency, days: days)
226
265
  end
227
266
 
228
267
  # Fetches the list of currencies currently supported by CoinGecko's API.
@@ -247,12 +286,12 @@ module CoingeckoRuby
247
286
 
248
287
  # Fetches the exchange rate for a coin or currency in the given coin or currency.
249
288
  # @param from [String] the coin id or currency to be converted.
250
- # @param to [String] the coin id or currency to convert against.
289
+ # @param to [String] the coin id or currency to convert against. Defaults to 'USD'.
251
290
  #
252
291
  # @return [Hash] returns the coin's exchange rate against the given coin or currency.
253
292
  #
254
293
  # @example Fetch the exchange rate for BTC-USD.
255
- # client.get_exchange_rate(from: 'bitcoin', to: 'usd')
294
+ # client.exchange_rate(from: 'bitcoin', to: 'usd')
256
295
  # @example Sample response object
257
296
  # {
258
297
  # "bitcoin" => {
@@ -267,8 +306,13 @@ module CoingeckoRuby
267
306
  # "eth" => 12.71434 # current price in given currency
268
307
  # }
269
308
  # }
309
+ def exchange_rate(from:, to: 'usd')
310
+ price(from, currency: to)
311
+ end
312
+
313
+ # @deprecated Use {#exchange_rate} instead
270
314
  def get_exchange_rate(from:, to: 'usd')
271
- get_price(id: from, currency: to)
315
+ exchange_rate(from: from, to: to)
272
316
  end
273
317
  end
274
318
  end
@@ -4,24 +4,20 @@ require 'json'
4
4
 
5
5
  module CoingeckoRuby
6
6
  module Connection
7
- BASE_URL = 'https://api.coingecko.com/api/v3/'
7
+ BASE_URL = 'https://api.coingecko.com/api/v3/'.freeze
8
8
 
9
- def get(endpoint, options = {})
9
+ def get(endpoint, params = {}, **options)
10
10
  url = BASE_URL + endpoint
11
11
  uri = URI(url)
12
- uri = build_query(uri, options) unless options.empty?
12
+ uri = build_request(uri, params) unless params.empty?
13
13
  response = Net::HTTP.get(uri)
14
14
  JSON.parse(response)
15
15
  end
16
16
 
17
17
  private
18
18
 
19
- def build_query(uri, query)
20
- if query[:options]
21
- options = query.delete(:options)
22
- query = query.merge(options)
23
- end
24
- uri.query = URI.encode_www_form(query)
19
+ def build_request(uri, params)
20
+ uri.query = URI.encode_www_form(params)
25
21
  uri
26
22
  end
27
23
  end