coinmarketcap_free 0.4.1 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/Gemfile.lock +1 -1
- data/README.md +148 -52
- data/lib/coinmarketcap_free/coin/histories.rb +29 -0
- data/lib/coinmarketcap_free/coin/icon.rb +27 -0
- data/lib/coinmarketcap_free/coin/model.rb +63 -0
- data/lib/coinmarketcap_free/coin.rb +87 -25
- data/lib/coinmarketcap_free/coin_history.rb +55 -23
- data/lib/coinmarketcap_free/helper.rb +26 -8
- data/lib/coinmarketcap_free/version.rb +2 -2
- data/lib/coinmarketcap_free.rb +18 -52
- metadata +6 -3
- data/lib/coinmarketcap_free/icon.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84d7327edba1a064c58e5b76ec5e5046519e7226fa91bc4e0f98dfb35c3fb34b
|
4
|
+
data.tar.gz: cecb71581b982b9fc34afab19606d085278e57ce39f4ecb2e497ce1abdafd2a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 976ec0dfecfe6cc6d553937d42ed6afac390100b94d0e9d8a4b2e8c57bb6b045b1588494eaa8dde8c30441dc0d6d15753a3cc722c6b33e1758c4e9d7f29203ac
|
7
|
+
data.tar.gz: 16818ff459c549b658992e4ffefef6464103edbd57ef6ad969a538e1298316f6b900d67c24383e52ff968ecdc6c2a7298c5c2dc5b0cff976d7817549b9791b8c
|
data/.DS_Store
ADDED
Binary file
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -15,16 +15,75 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
15
15
|
## How to use?
|
16
16
|
|
17
17
|
``` Ruby
|
18
|
-
|
18
|
+
coins = CoinmarketcapFree::Coin.list
|
19
19
|
```
|
20
20
|
|
21
|
-
or
|
21
|
+
or
|
22
22
|
|
23
23
|
``` Ruby
|
24
|
-
|
24
|
+
coins = CoinmarketcapFree.coins
|
25
|
+
```
|
26
|
+
|
27
|
+
####Result:
|
28
|
+
|
29
|
+
Model:
|
30
|
+
```Ruby
|
31
|
+
[...
|
32
|
+
#<CoinmarketcapFree::Coin:0x00000001064388a0
|
33
|
+
@cmc_rank=1,
|
34
|
+
@id=1,
|
35
|
+
@market_pair_count=10861,
|
36
|
+
@name=#<struct Struct::FullName name="Bitcoin", symbol="BTC", slug="bitcoin">,
|
37
|
+
@quotes=
|
38
|
+
[#<struct Struct::Quotes
|
39
|
+
name="USD",
|
40
|
+
price=66949.41999188314,
|
41
|
+
volume_24h=92116022162.1663,
|
42
|
+
market_cap=1315314616282.593,
|
43
|
+
percent_change_1h=0.39277979,
|
44
|
+
percent_change_24h=3.06216236,
|
45
|
+
percent_change_7d=10.037655,
|
46
|
+
percent_change_30d=56.63354406,
|
47
|
+
percent_change_60d=52.21058851,
|
48
|
+
percent_change_90d=54.57419557,
|
49
|
+
percent_change_1y=197.24478021,
|
50
|
+
last_updated=#<DateTime: 2024-03-06T17:46:00+00:00 ((2460376j,63960s,0n),+0s,2299161j)>>],
|
51
|
+
@state=#<struct Struct::State last_updated=#<DateTime: 2024-03-06T17:46:00+00:00 ((2460376j,63960s,0n),+0s,2299161j)>, added=#<DateTime: 2010-07-13T00:00:00+00:00 ((2455391j,0s,0n),+0s,2299161j)>>,
|
52
|
+
@supply=#<struct Struct::Supply circulating=19646393.0, total=19646393.0, maximum=21000000.0>,
|
53
|
+
@tags=
|
54
|
+
["mineable",
|
55
|
+
"pow",
|
56
|
+
"sha-256",
|
57
|
+
"store-of-value",
|
58
|
+
"state-channel",
|
59
|
+
"coinbase-ventures-portfolio",
|
60
|
+
"three-arrows-capital-portfolio",
|
61
|
+
"polychain-capital-portfolio",
|
62
|
+
"binance-labs-portfolio",
|
63
|
+
"blockchain-capital-portfolio",
|
64
|
+
"boostvc-portfolio",
|
65
|
+
"cms-holdings-portfolio",
|
66
|
+
"dcg-portfolio",
|
67
|
+
"dragonfly-capital-portfolio",
|
68
|
+
"electric-capital-portfolio",
|
69
|
+
"fabric-ventures-portfolio",
|
70
|
+
"framework-ventures-portfolio",
|
71
|
+
"galaxy-digital-portfolio",
|
72
|
+
"huobi-capital-portfolio",
|
73
|
+
"alameda-research-portfolio",
|
74
|
+
"a16z-portfolio",
|
75
|
+
"1confirmation-portfolio",
|
76
|
+
"winklevoss-capital-portfolio",
|
77
|
+
"usv-portfolio",
|
78
|
+
"placeholder-ventures-portfolio",
|
79
|
+
"pantera-capital-portfolio",
|
80
|
+
"multicoin-capital-portfolio",
|
81
|
+
"paradigm-portfolio",
|
82
|
+
"bitcoin-ecosystem",
|
83
|
+
"ftx-bankruptcy-estate"]>]
|
25
84
|
```
|
26
85
|
|
27
|
-
|
86
|
+
Json data:
|
28
87
|
``` JSON
|
29
88
|
{
|
30
89
|
"data": {
|
@@ -109,77 +168,115 @@ Result:
|
|
109
168
|
}
|
110
169
|
```
|
111
170
|
|
112
|
-
|
171
|
+
Get a list of cryptocurrencies
|
172
|
+
``` Ruby
|
173
|
+
list = CoinmarketcapFree.coins(limit: 100, start: 1)
|
174
|
+
```
|
175
|
+
|
176
|
+
If you want to sort in ascending:
|
113
177
|
|
114
178
|
``` Ruby
|
115
|
-
list = CoinmarketcapFree
|
179
|
+
list = CoinmarketcapFree.coins(limit: 100, start: 1, sort_type:'asc')
|
116
180
|
```
|
117
181
|
|
118
|
-
|
182
|
+
or in descending
|
119
183
|
|
120
184
|
``` Ruby
|
121
|
-
list = CoinmarketcapFree
|
185
|
+
list = CoinmarketcapFree.coins(limit: 100, start: 1, sort_type:'desc')
|
122
186
|
```
|
123
187
|
|
124
|
-
|
188
|
+
Also you can sort by name with ascending:
|
125
189
|
|
126
190
|
``` Ruby
|
127
|
-
list = CoinmarketcapFree
|
128
|
-
start: 1,
|
129
|
-
sort_type:'asc',
|
130
|
-
sort_by: 'name',
|
131
|
-
convert: 'USD,BTC,ETH')
|
191
|
+
list = CoinmarketcapFree.coins(limit: 100, start: 1, sort_type:'asc', sort_by: 'name')
|
132
192
|
```
|
133
193
|
|
194
|
+
Convert cryptocurrency to USD:
|
195
|
+
|
196
|
+
``` Ruby
|
197
|
+
list = CoinmarketcapFree.coins(limit: 100, start: 1, convert: 'USD')
|
198
|
+
```
|
199
|
+
|
200
|
+
or together
|
201
|
+
|
202
|
+
``` Ruby
|
203
|
+
list = CoinmarketcapFree.coins(limit: 100, start: 1, convert: 'USD,BTC,ETH')
|
204
|
+
```
|
134
205
|
|
135
|
-
Parameters for CoinmarketcapFree::Coin.list
|
206
|
+
Parameters for ```CoinmarketcapFree::Coin.list``` or ```CoinmarketcapFree.coins```:
|
136
207
|
|
137
208
|
| Name | Type | Description | Examples |
|
138
209
|
|:------------------------------|:---------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:---------------------------------------------|
|
139
|
-
| ```limit:``` | Integer
|
140
|
-
| ```start:``` | Integer
|
141
|
-
| ```sort_by:``` | String
|
142
|
-
| ```sort_type:``` | String
|
143
|
-
| ```convert:``` | String
|
144
|
-
| ```crypto_type:``` | String
|
145
|
-
| ```tag_type:``` | String
|
146
|
-
| ```audited:``` | Boolean
|
147
|
-
| ```
|
148
|
-
| ```
|
149
|
-
| ```
|
150
|
-
| ```
|
151
|
-
| ```
|
152
|
-
| ```
|
153
|
-
| ```market_cap_range:``` | String. | Optionally specify a threshold market cap to filter results by. | ```0~100000000000000000``` |
|
210
|
+
| ```limit:``` | Integer | Optionally specify the number of results to return. Use this parameter and the "start" parameter to determine your own pagination size. ||
|
211
|
+
| ```start:``` | Integer | Optionally offset the start (1-based index) of the paginated list of items to return. ||
|
212
|
+
| ```sort_by:``` | String | Default: ```market_cap```. (```rank```, ```name```, ```symbol```, ```date_added```, ```market_cap```, ```market_cap_strict```, ```price```, ```circulating_supply```, ```total_supply```, ```max_supply```, ```num_market_pairs```, ```volume_24h```, ```percent_change_1h```, ```percent_change_24h```, ```percent_change_7d```, ```market_cap_by_total_supply_strict```, ```volume_7d```, ```volume_30d```). What field to sort the list of cryptocurrencies by. ||
|
213
|
+
| ```sort_type:``` | String | Default: ```desc```. (```asc``` or ```desc```). The direction in which to order cryptocurrencies against the specified sort. ||
|
214
|
+
| ```convert:``` | String | Default: ```USD``` . Select cryptocurrencies to exchange (```AUD```, ```BRL```, ```CAD```, ```CHF```, ```CLP```, ```CNY```, ```CZK```, ```DKK```, ```EUR```, ```GBP```, ```HKD```, ```HUF```, ```IDR```, ```ILS```, ```INR```, ```JPY```, ```KRW```, ```MXN```, ```MYR```, ```NOK```, ```NZD```, ```PHP```, ```PKR```, ```PLN```, ```RUB```, ```SEK```, ```SGD```, ```THB```, ```TRY```, ```TWD```, ```ZAR```). | ```USD``` or together ```USD,BTC,ETH``` |
|
215
|
+
| ```crypto_type:``` | String | Default: ```all```. (```all```, ```coins```, ```tokens```). The type of cryptocurrency to include. ||
|
216
|
+
| ```tag_type:``` | String | Default: ```all```. (```all```, ```defi```, ```filesharing```). The tag of cryptocurrency to include. ||
|
217
|
+
| ```audited:``` | Boolean | Show audited (true) or not (false) ||
|
218
|
+
| ```tags:``` | String | If you want to see cryptocurrencies that can be mined, just type ```mineable```. ||
|
219
|
+
| ```volume24h_range:``` | String | Optionally specify a threshold 24 hour USD volume to filter results by. | ```0~100000000000000000``` |
|
220
|
+
| ```percent_change24h_range:``` | String | Optionally specify a threshold 24 hour percent change to filter results by. | ```0~100``` or ```-10~100``` |
|
221
|
+
| ```circulating_supply_range:``` | String | Optionally specify a threshold circulating supply to filter results by. | ```0~100000000000000000``` |
|
222
|
+
| ```price_range:``` | String | Optionally specify a threshold USD price to filter results by. | ```0~100000000000000000``` |
|
223
|
+
| ```market_cap_range:``` | String | Optionally specify a threshold market cap to filter results by. | ```0~100000000000000000``` |
|
154
224
|
|
155
225
|
### Returns an interval of historic market quotes:
|
156
226
|
|
157
227
|
``` Ruby
|
158
|
-
|
159
|
-
|
228
|
+
histories = CoinmarketcapFree::CoinHistory.custom_time(id_coin, '1D')
|
229
|
+
histories = CoinmarketcapFree::CoinHistory.custom_time(id_coin, '1668981600~1671659999')
|
160
230
|
```
|
161
231
|
|
162
232
|
or short
|
163
233
|
|
164
234
|
``` Ruby
|
165
|
-
|
166
|
-
|
235
|
+
histories = CoinmarketcapFree.coin_histories(id_coin, '1D')
|
236
|
+
histories = CoinmarketcapFree.coin_histories(id_coin, '1668981600~1671659999')
|
167
237
|
```
|
168
238
|
|
169
|
-
|
239
|
+
Also you can call method like this:
|
170
240
|
|
171
241
|
``` Ruby
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
242
|
+
histories = CoinmarketcapFree::CoinHistory.one_day(id_coin)
|
243
|
+
histories = CoinmarketcapFree::CoinHistory.seven_days(id_coin)
|
244
|
+
histories = CoinmarketcapFree::CoinHistory.one_month(id_coin)
|
245
|
+
histories = CoinmarketcapFree::CoinHistory.three_months(id_coin)
|
246
|
+
histories = CoinmarketcapFree::CoinHistory.one_year(id_coin)
|
247
|
+
histories = CoinmarketcapFree::CoinHistory.current_year(id_coin)
|
248
|
+
histories = CoinmarketcapFree::CoinHistory.all(id_coin)
|
179
249
|
```
|
180
250
|
|
181
|
-
|
182
|
-
|
251
|
+
or in model ```CoinmarketcapFree::Coin```
|
252
|
+
|
253
|
+
``` Ruby
|
254
|
+
coin = CoinmarketcapFree::Coin.list.first
|
255
|
+
histories = coin.histories('1D')
|
256
|
+
histories = coin.one_day
|
257
|
+
histories = coin.seven_days
|
258
|
+
histories = coin.one_month
|
259
|
+
histories = coin.three_months
|
260
|
+
histories = coin.one_year
|
261
|
+
histories = coin.current_year
|
262
|
+
histories = coin.all
|
263
|
+
```
|
264
|
+
|
265
|
+
####Result:
|
266
|
+
|
267
|
+
Model:
|
268
|
+
|
269
|
+
```Ruby
|
270
|
+
[... #<CoinmarketcapFree::CoinHistory:0x0000000106479530
|
271
|
+
@market_cap=1317962149986.5,
|
272
|
+
@price=67084.17926825049,
|
273
|
+
@time=2024-03-06 19:50:10 +0200,
|
274
|
+
@totaly_supply=19646392.999999978,
|
275
|
+
@volume_24h=92029823321.77837>]
|
276
|
+
```
|
277
|
+
|
278
|
+
Json:
|
279
|
+
```JSON
|
183
280
|
{
|
184
281
|
"data": {
|
185
282
|
"points": {
|
@@ -211,22 +308,21 @@ Result:
|
|
211
308
|
|
212
309
|
```
|
213
310
|
|
214
|
-
Parameters for CoinmarketcapFree::CoinHistory.custom_time
|
311
|
+
Parameters for ```CoinmarketcapFree::CoinHistory.custom_time``` or ```CoinmarketcapFree.coin_histories```:
|
215
312
|
|
216
313
|
| Name | Type | Description | Examples |
|
217
314
|
|:-----------------|:---------|:----------------------------------------------|:-------------------------------------------------------------------------------------------------------------------|
|
218
|
-
| ```id``` | Integer
|
219
|
-
| ```range_time``` | String
|
315
|
+
| ```id``` | Integer | Cryptocurrency identifier from coinmarketcap. | Bitcoin has id 1 |
|
316
|
+
| ```range_time``` | String | Range time. | ```1D```, ```7D```, ```1M```, ```3M```, ```1Y```, ```YTD```, ```ALL``` or custom range ```1668981600~1671659999``` |
|
220
317
|
|
221
|
-
### Generation a link
|
318
|
+
### Generation a link:
|
222
319
|
|
223
320
|
``` Ruby
|
224
|
-
|
321
|
+
coin = CoinmarketcapFree.coins.first # take first coin
|
322
|
+
icon = coin.get_icon(64) # generate string uri
|
225
323
|
```
|
226
324
|
|
227
|
-
```
|
228
|
-
"https://s2.coinmarketcap.com/static/img/coins/64x64/1.png"
|
229
|
-
```
|
325
|
+
Result string: ```https://s2.coinmarketcap.com/static/img/coins/64x64/1.png```
|
230
326
|
|
231
327
|
| Name | Type | Description | Examples |
|
232
328
|
|:-----------------|:---------|:----------------------------------------------|:-------------------------------------------------------------------------------------------------------------------|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module CoinmarketcapFree
|
2
|
+
class Coin
|
3
|
+
# Create all methods for each time interval
|
4
|
+
CoinHistory::INTERVAL_TIME.each do |key, value|
|
5
|
+
class_eval("def #{key}; histories('#{value}'); end", __FILE__, __LINE__)
|
6
|
+
end
|
7
|
+
|
8
|
+
# Get the full history of cryptocurrencies and their prices.
|
9
|
+
#
|
10
|
+
# coin = CoinmarketcapFree::Coin.list.first
|
11
|
+
# histories = coin.histories('1D')
|
12
|
+
#
|
13
|
+
# or
|
14
|
+
#
|
15
|
+
# histories = coin.one_day
|
16
|
+
# histories = coin.seven_days
|
17
|
+
# histories = coin.one_month
|
18
|
+
# histories = coin.three_months
|
19
|
+
# histories = coin.one_year
|
20
|
+
# histories = coin.current_year
|
21
|
+
# histories = coin.all
|
22
|
+
#
|
23
|
+
# @param interval [String] Select time interval. ('1D', '7D', '1M', '3M', '1Y', 'YTD', 'ALL' or custom '1668981600~1671659999')
|
24
|
+
# @return [Array<CoinmarketcapFree::CoinHistory>] Return CoinHistory object
|
25
|
+
def histories(interval)
|
26
|
+
CoinHistory.custom_time(@id, interval)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CoinmarketcapFree
|
4
|
+
class Coin
|
5
|
+
# Generate a URI icon of a coin
|
6
|
+
#
|
7
|
+
# coin = CoinmarketcapFree::Coin.list.first
|
8
|
+
# logo = coin.get_icon(64) # size 64x64
|
9
|
+
#
|
10
|
+
# Result:
|
11
|
+
#
|
12
|
+
# "https://s2.coinmarketcap.com/static/img/coins/64x64/1.png"
|
13
|
+
#
|
14
|
+
# @param [Integer] id_coin Identify coin. For example, bitcoin has 1
|
15
|
+
# @param [Integer] size Choose one size: 64, 128, 200
|
16
|
+
# @return [String] Return URI from coinmarketcap
|
17
|
+
def get_icon(size)
|
18
|
+
size_x_size = case size
|
19
|
+
when 64, 128, 200
|
20
|
+
"#{size}x#{size}"
|
21
|
+
else
|
22
|
+
raise ArgumentError, "Can't find this value: #{size}"
|
23
|
+
end
|
24
|
+
"https://s2.coinmarketcap.com/static/img/coins/#{size_x_size}/#{@id}.png"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module CoinmarketcapFree
|
2
|
+
class Coin
|
3
|
+
FullName = Struct.new('FullName',
|
4
|
+
:name,
|
5
|
+
:symbol,
|
6
|
+
:slug) do
|
7
|
+
def self.convert_json(data)
|
8
|
+
FullName.new(data['name'],
|
9
|
+
data['symbol'],
|
10
|
+
data['slug'])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Supply = Struct.new("Supply",
|
15
|
+
:circulating,
|
16
|
+
:total,
|
17
|
+
:maximum) do
|
18
|
+
def self.convert_json(data)
|
19
|
+
Supply.new(data['circulatingSupply'],
|
20
|
+
data['totalSupply'],
|
21
|
+
data['maxSupply'])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
State = Struct.new("State",
|
26
|
+
:last_updated,
|
27
|
+
:added) do
|
28
|
+
def self.convert_json(data)
|
29
|
+
State.new(DateTime.parse(data['lastUpdated']),
|
30
|
+
DateTime.parse(data['dateAdded']))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
Quotes = Struct.new("Quotes",
|
35
|
+
:name,
|
36
|
+
:price,
|
37
|
+
:volume_24h,
|
38
|
+
:market_cap,
|
39
|
+
:percent_change_1h,
|
40
|
+
:percent_change_24h,
|
41
|
+
:percent_change_7d,
|
42
|
+
:percent_change_30d,
|
43
|
+
:percent_change_60d,
|
44
|
+
:percent_change_90d,
|
45
|
+
:percent_change_1y,
|
46
|
+
:last_updated) do
|
47
|
+
def self.convert_json(data)
|
48
|
+
Quotes.new(data['name'],
|
49
|
+
data['price'],
|
50
|
+
data['volume24h'],
|
51
|
+
data['marketCap'],
|
52
|
+
data['percentChange1h'],
|
53
|
+
data['percentChange24h'],
|
54
|
+
data['percentChange7d'],
|
55
|
+
data['percentChange30d'],
|
56
|
+
data['percentChange60d'],
|
57
|
+
data['percentChange90d'],
|
58
|
+
data['percentChange1y'],
|
59
|
+
DateTime.parse(data['lastUpdated']))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -1,18 +1,65 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'helper'
|
4
|
+
require_relative 'coin/icon'
|
5
|
+
require_relative 'coin/model'
|
6
|
+
require_relative 'coin_history'
|
7
|
+
require_relative 'coin/histories'
|
4
8
|
|
5
9
|
module CoinmarketcapFree
|
6
|
-
#
|
7
|
-
|
8
|
-
|
10
|
+
# Model for Cryptocurrency
|
11
|
+
class Coin
|
12
|
+
attr_accessor :id,
|
13
|
+
:name,
|
14
|
+
:tags,
|
15
|
+
:cmc_rank,
|
16
|
+
:market_pair_count,
|
17
|
+
:supply,
|
18
|
+
:state,
|
19
|
+
:quotes
|
20
|
+
|
21
|
+
def initialize(id, name, tags, cmc_rank, market_pair_count, supply, state, quotes)
|
22
|
+
@id = id
|
23
|
+
@name = name
|
24
|
+
@tags = tags
|
25
|
+
@cmc_rank = cmc_rank
|
26
|
+
@market_pair_count = market_pair_count
|
27
|
+
@supply = supply
|
28
|
+
@state = state
|
29
|
+
@quotes = quotes
|
30
|
+
end
|
9
31
|
|
10
32
|
class << self
|
11
33
|
# Get a list of cryptocurrencies
|
12
34
|
#
|
13
35
|
# list = CoinmarketcapFree::Coin.list(limit: 100, start: 1)
|
14
36
|
#
|
15
|
-
#
|
37
|
+
# If you want to sort in ascending, just write parameter:
|
38
|
+
#
|
39
|
+
# list = CoinmarketcapFree::Coin.list(limit: 100, start: 1, sort_type:'asc')
|
40
|
+
#
|
41
|
+
# or in descending
|
42
|
+
#
|
43
|
+
# list = CoinmarketcapFree::Coin.list(limit: 100, start: 1, sort_type:'desc')
|
44
|
+
#
|
45
|
+
# Or sort by name with ascending:
|
46
|
+
#
|
47
|
+
# list = CoinmarketcapFree::Coin.list(limit: 100, start: 1, sort_type:'asc', sort_by: 'name')
|
48
|
+
#
|
49
|
+
# Convert cryptocurrency to USD:
|
50
|
+
#
|
51
|
+
# list = CoinmarketcapFree::Coin.list(limit: 100, start: 1, convert: 'USD')
|
52
|
+
#
|
53
|
+
# or together
|
54
|
+
#
|
55
|
+
# list = CoinmarketcapFree::Coin.list(limit: 100, start: 1, convert: 'USD,BTC,ETH')
|
56
|
+
#
|
57
|
+
# Also you can get all histories of cryptocurrency:
|
58
|
+
#
|
59
|
+
# coin = CoinmarketcapFree::Coin.list(limit: 100, start: 1).first
|
60
|
+
# coin.histories('1D')
|
61
|
+
#
|
62
|
+
# Result json data:
|
16
63
|
#
|
17
64
|
# {
|
18
65
|
# "data": {
|
@@ -101,24 +148,6 @@ module CoinmarketcapFree
|
|
101
148
|
# 'totalCount' - Total number of cryptocurrencies
|
102
149
|
# 'status' - Standardized status object for API calls.
|
103
150
|
#
|
104
|
-
# If you want to sort in ascending, just write parameter:
|
105
|
-
#
|
106
|
-
# list = CoinmarketcapFree::Coin.list(limit: 100, start: 1, sort_type:'asc')
|
107
|
-
#
|
108
|
-
# or
|
109
|
-
#
|
110
|
-
# list = CoinmarketcapFree::Coin.list(limit: 100, start: 1, sort_type:'desc')
|
111
|
-
#
|
112
|
-
# You can also adding sort by:
|
113
|
-
#
|
114
|
-
# list = CoinmarketcapFree::Coin.list(limit: 100, start: 1, sort_type:'asc', sort_by: 'name')
|
115
|
-
#
|
116
|
-
# Convert cryptocurrency to::
|
117
|
-
#
|
118
|
-
# list = CoinmarketcapFree::Coin.list(limit: 100, start: 1, convert: 'USD,BTC,ETH')
|
119
|
-
#
|
120
|
-
#
|
121
|
-
# @return [String]
|
122
151
|
# @param start [Integer] Optionally offset the start (1-based index) of the paginated list of items to return.
|
123
152
|
# @param limit [Integer] Optionally specify the number of results to return. Use this parameter and the 'start' parameter to determine your own pagination size.
|
124
153
|
# @param sort_by [String] What field to sort the list of cryptocurrencies by. ('rank', 'name', 'symbol', 'date_added', 'market_cap', 'market_cap_strict', 'price', 'circulating_supply', 'total_supply', 'max_supply', 'num_market_pairs', 'volume_24h', 'percent_change_1h', 'percent_change_24h', 'percent_change_7d', 'market_cap_by_total_supply_strict', 'volume_7d', 'volume_30d")
|
@@ -127,14 +156,48 @@ module CoinmarketcapFree
|
|
127
156
|
# @param crypto_type [String] The type of cryptocurrency to include. ('all', 'coins', 'tokens')
|
128
157
|
# @param tag_type [String] The tag of cryptocurrency to include. ('all', 'defi', 'filesharing')
|
129
158
|
# @param audited [TrueClass, FalseClass] Show audited 'true' or not 'false'
|
130
|
-
# @param aux [String] Optionally specify a comma-separated list of supplemental data fields to return. Pass 'ath, atl, high24h, low24h, num_market_pairs, cmc_rank, date_added, max_supply, circulating_supply, total_supply, volume_7d, volume_30d, self_reported_circulating_supply, self_reported_market_cap' to include all auxiliary fields.
|
131
159
|
# @param tags [String] If you want to see cryptocurrencies that can be mined, just type 'mineable'.
|
132
160
|
# @param volume24h_range [String] Optionally specify a threshold 24 hour USD volume to filter results by. For example, '0~100000000000000000'
|
133
161
|
# @param percent_change24h_range [String] Optionally specify a threshold 24 hour percent change to filter results by. For example, '0~100' or '-10~100'
|
134
162
|
# @param circulating_supply_range [String] Optionally specify a threshold circulating supply to filter results by. For example, '0~100000000000000000'
|
135
163
|
# @param price_range [String] Optionally specify a threshold USD price to filter results by. For example, '0~100000000000000000'
|
136
164
|
# @param market_cap_range [String] Optionally specify a threshold market cap to filter results by. For example, '0~100000000000000000'
|
165
|
+
# @return [CoinmarketcapFree::Coin] Return Coin object
|
137
166
|
def list(**params)
|
167
|
+
options = generate_options(params)
|
168
|
+
json = Helper.get_cryptocarencies(options)
|
169
|
+
|
170
|
+
@total_count = json['data']['totalCount'].to_i # update total count
|
171
|
+
|
172
|
+
json['data']["cryptoCurrencyList"].map { |coin| Coin.convert_json(coin) }
|
173
|
+
end
|
174
|
+
|
175
|
+
def total_count
|
176
|
+
@total_count || 0
|
177
|
+
end
|
178
|
+
|
179
|
+
# Convert json data to Coin
|
180
|
+
# @param data [Hash] Data
|
181
|
+
# @return [CoinmarketcapFree::Coin] Return Coin object
|
182
|
+
def convert_json(data)
|
183
|
+
id = data['id']
|
184
|
+
name = FullName.convert_json(data)
|
185
|
+
tags = data['tags'] || []
|
186
|
+
cmc_rank = data['cmcRank']
|
187
|
+
market_pair_count = data['marketPairCount']
|
188
|
+
supply = Supply.convert_json(data)
|
189
|
+
state = State.convert_json(data)
|
190
|
+
quotes = data['quotes'].nil? ? [] : data['quotes'].map { |quote| Quotes.convert_json(quote) }
|
191
|
+
|
192
|
+
Coin.new(id, name, tags, cmc_rank, market_pair_count, supply, state, quotes)
|
193
|
+
end
|
194
|
+
|
195
|
+
private
|
196
|
+
|
197
|
+
# Generate options
|
198
|
+
# @param params [Hash]
|
199
|
+
# @return [Hash] Return options
|
200
|
+
def generate_options(params)
|
138
201
|
options = {}
|
139
202
|
|
140
203
|
options[:start] = params[:start] || 1 # Integer
|
@@ -145,7 +208,6 @@ module CoinmarketcapFree
|
|
145
208
|
options[:cryptoType] = params[:crypto_type] || 'all' # String
|
146
209
|
options[:tagType] = params[:tag_type] || 'all' # String
|
147
210
|
options[:audited] = params[:audited] || false # Boolean
|
148
|
-
options[:aux] = params[:aux] # String
|
149
211
|
options[:tags] = params[:tags] # String
|
150
212
|
options[:volume24hRange] = params[:volume24h_range] # String
|
151
213
|
options[:percentChange24hRange] = params[:percent_change24h_range] # String
|
@@ -153,7 +215,7 @@ module CoinmarketcapFree
|
|
153
215
|
options[:priceRange] = params[:price_range] # String
|
154
216
|
options[:marketCapRange] = params[:market_cap_range] # String
|
155
217
|
|
156
|
-
|
218
|
+
options
|
157
219
|
end
|
158
220
|
end
|
159
221
|
end
|
@@ -1,12 +1,8 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require_relative 'helper'
|
4
2
|
|
5
3
|
module CoinmarketcapFree
|
6
|
-
#
|
7
|
-
|
8
|
-
URI_API = "#{BASE_URI}#{VERSION_API}/cryptocurrency/detail/chart"
|
9
|
-
|
4
|
+
# Model for Cryptocurrency History
|
5
|
+
class CoinHistory
|
10
6
|
INTERVAL_TIME = {
|
11
7
|
one_day: '1D',
|
12
8
|
seven_days: '7D',
|
@@ -17,36 +13,56 @@ module CoinmarketcapFree
|
|
17
13
|
all: 'ALL'
|
18
14
|
}.freeze
|
19
15
|
|
16
|
+
attr_accessor :time,
|
17
|
+
:price,
|
18
|
+
:volume_24h,
|
19
|
+
:market_cap,
|
20
|
+
:totaly_supply
|
21
|
+
|
22
|
+
def initialize(date, price, volume_24h, market_cap, totaly_supply)
|
23
|
+
@time = date
|
24
|
+
@price = price
|
25
|
+
@volume_24h = volume_24h
|
26
|
+
@market_cap = market_cap
|
27
|
+
@totaly_supply = totaly_supply
|
28
|
+
end
|
29
|
+
|
20
30
|
class << self
|
21
31
|
# Returns an interval of historic market quotes for any cryptocurrency based on time and interval parameters.
|
22
32
|
#
|
23
|
-
# You can use one of the following intervals: 1D, 7D, 1M, 3M, 1Y, YTD, ALL
|
33
|
+
# You can use one of the following intervals: 1D, 7D, 1M, 3M, 1Y, YTD, ALL or custom range '1668981600~1671659999'
|
34
|
+
# or call the method by its full name: one_day, seven_days, one_month, three_months, one_year, current_year, all
|
24
35
|
#
|
25
|
-
# history = CoinmarketcapFree::CoinHistory.custom_time(
|
36
|
+
# history = CoinmarketcapFree::CoinHistory.custom_time(id_coin, '1D')
|
26
37
|
#
|
27
|
-
#
|
38
|
+
# or
|
28
39
|
#
|
29
|
-
#
|
40
|
+
# histories = CoinmarketcapFree::CoinHistory.one_day(id_coin)
|
41
|
+
# histories = CoinmarketcapFree::CoinHistory.seven_days(id_coin)
|
42
|
+
# histories = CoinmarketcapFree::CoinHistory.one_month(id_coin)
|
43
|
+
# histories = CoinmarketcapFree::CoinHistory.three_months(id_coin)
|
44
|
+
# histories = CoinmarketcapFree::CoinHistory.one_year(id_coin)
|
45
|
+
# histories = CoinmarketcapFree::CoinHistory.current_year(id_coin)
|
46
|
+
# histories = CoinmarketcapFree::CoinHistory.all(id_coin)
|
30
47
|
#
|
31
|
-
# Just add a prefix to the method: interval_(one_day, seven_days, one_month, three_months, one_year, current_year, all)
|
32
48
|
#
|
33
49
|
# Result json:
|
34
50
|
#
|
35
51
|
# {
|
36
52
|
# "data": {
|
37
53
|
# "points": {
|
38
|
-
# "1673192010": {
|
54
|
+
# "1673192010": { # time in seconds
|
39
55
|
# "v": [
|
40
|
-
# 16953.771282696678,
|
41
|
-
# 7609543976.45,
|
42
|
-
# 326457581376.786557398500,
|
56
|
+
# 16953.771282696678, # price
|
57
|
+
# 7609543976.45, # volume 24h
|
58
|
+
# 326457581376.786557398500, # market cap
|
43
59
|
# 1,
|
44
|
-
# 19255750.00000000000000000000
|
60
|
+
# 19255750.00000000000000000000 # total supply
|
45
61
|
# ],
|
46
62
|
# "c": [
|
47
|
-
# 16953.771282696678,
|
48
|
-
# 7609543976.45,
|
49
|
-
# 326457581376.786557398500
|
63
|
+
# 16953.771282696678, # price
|
64
|
+
# 7609543976.45, # volume 24h
|
65
|
+
# 326457581376.786557398500 # market cap
|
50
66
|
# ]
|
51
67
|
# },
|
52
68
|
# ...
|
@@ -68,19 +84,35 @@ module CoinmarketcapFree
|
|
68
84
|
#
|
69
85
|
# @param id [Integer] Cryptocurrency identifier from coinmarketcap. For example, Bitcoin has the number 1
|
70
86
|
# @param range_time [String] Range time. For example, '1D', '7D', '1M', '3M', '1Y', 'YTD', 'ALL' or custom range '1668981600~1671659999'
|
71
|
-
# @return [
|
87
|
+
# @return [Array<CoinmarketcapFree::CoinHistory] Return CoinHistory object
|
72
88
|
def custom_time(id, range_time)
|
73
|
-
Helper.
|
89
|
+
json = Helper.get_cryptocurrency_histories({ id: id, range: range_time })
|
90
|
+
|
91
|
+
json['data']['points'].map { |key, value| CoinHistory.convert_json(key, value['v']) }
|
74
92
|
end
|
75
93
|
|
76
|
-
#
|
94
|
+
# Create interval methods
|
77
95
|
INTERVAL_TIME.each do |key, value|
|
78
96
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
79
|
-
def
|
97
|
+
def #{key}(id)
|
80
98
|
custom_time(id, '#{value}')
|
81
99
|
end
|
82
100
|
RUBY
|
83
101
|
end
|
102
|
+
|
103
|
+
# Convert json data to CoinHistory
|
104
|
+
# @param utc_timestamp [Integer] Time in seconds
|
105
|
+
# @param data [Array] Data
|
106
|
+
# @return [CoinmarketcapFree::CoinHistory] Return CoinHistory object
|
107
|
+
def convert_json(utc_timestamp, data)
|
108
|
+
timestamp = utc_timestamp.is_a?(String) ? utc_timestamp.to_i : utc_timestamp
|
109
|
+
|
110
|
+
CoinHistory.new(Time.at(timestamp), # convert time utc
|
111
|
+
data[0], # price
|
112
|
+
data[1], # volume 24h
|
113
|
+
data[2], # market cap
|
114
|
+
data[4]) # total supply
|
115
|
+
end
|
84
116
|
end
|
85
117
|
end
|
86
118
|
end
|
@@ -1,24 +1,42 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require 'uri'
|
4
2
|
require 'net/http'
|
5
3
|
require 'openssl'
|
6
4
|
require 'json'
|
5
|
+
require 'date'
|
7
6
|
|
8
7
|
module CoinmarketcapFree
|
9
|
-
|
10
|
-
VERSION_API = 'v3'
|
11
|
-
|
12
|
-
# Helper module for CoinmarketcapFree
|
8
|
+
# Helper module
|
13
9
|
module Helper
|
10
|
+
BASE_URI = 'https://api.coinmarketcap.com/data-api/'
|
11
|
+
VERSION_API = 'v3'
|
12
|
+
|
13
|
+
URI_API_CRYPTOCURRENCIES = "#{BASE_URI}#{VERSION_API}/cryptocurrency/listing"
|
14
|
+
URI_API_CRYPTOCURRENCY_HISTORIES = "#{BASE_URI}#{VERSION_API}/cryptocurrency/detail/chart"
|
15
|
+
|
14
16
|
class << self
|
17
|
+
# Get cryptocurrency of histories
|
18
|
+
# @param data [Hash] Parameters for Coinmarketcap API
|
19
|
+
# @return [Hash] Return coin histories
|
20
|
+
def get_cryptocurrency_histories(data)
|
21
|
+
str = http_get(URI_API_CRYPTOCURRENCY_HISTORIES, data)
|
22
|
+
JSON.parse(str)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Get cryptocurrencies
|
26
|
+
# @param data [Hash] Parameters for Coinmarketcap API
|
27
|
+
# @return [Hash] Return cryptocurrencies
|
28
|
+
def get_cryptocarencies(data)
|
29
|
+
str = http_get(URI_API_CRYPTOCURRENCIES, data)
|
30
|
+
JSON.parse(str)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
15
35
|
def http_get(url, data = nil)
|
16
36
|
uri = URI(generate_url(url, data))
|
17
37
|
Net::HTTP.get(uri)
|
18
38
|
end
|
19
39
|
|
20
|
-
private
|
21
|
-
|
22
40
|
def generate_url(url, data = nil)
|
23
41
|
"#{url}#{data ? '?' : ''}#{data.map { |key, value| "#{key}=#{value}" }.join('&')}"
|
24
42
|
end
|
data/lib/coinmarketcap_free.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require_relative 'coinmarketcap_free/coin_history'
|
4
2
|
require_relative 'coinmarketcap_free/coin'
|
5
|
-
require_relative 'coinmarketcap_free/icon'
|
6
3
|
require_relative 'coinmarketcap_free/version'
|
7
4
|
|
8
5
|
# Get data from Coinmarketcap API without requiring an API key.
|
@@ -16,24 +13,21 @@ module CoinmarketcapFree
|
|
16
13
|
#
|
17
14
|
# list = CoinmarketcapFree.coins(limit: 100, start: 1, sort_type:'asc')
|
18
15
|
#
|
19
|
-
# or
|
16
|
+
# or in descending
|
20
17
|
#
|
21
18
|
# list = CoinmarketcapFree.coins(limit: 100, start: 1, sort_type:'desc')
|
22
19
|
#
|
23
|
-
#
|
20
|
+
# Or sort by name with ascending:
|
24
21
|
#
|
25
22
|
# list = CoinmarketcapFree.coins(limit: 100, start: 1, sort_type:'asc', sort_by: 'name')
|
26
23
|
#
|
27
|
-
# Convert cryptocurrency to
|
28
|
-
#
|
29
|
-
# list = CoinmarketcapFree.coins(limit: 100, start: 1, convert: 'USD,BTC,ETH')
|
24
|
+
# Convert cryptocurrency to USD:
|
30
25
|
#
|
31
|
-
#
|
26
|
+
# list = CoinmarketcapFree.coins(limit: 100, start: 1, convert: 'USD')
|
32
27
|
#
|
33
|
-
#
|
34
|
-
# JSON.parse(data)
|
35
|
-
# end
|
28
|
+
# or together
|
36
29
|
#
|
30
|
+
# list = CoinmarketcapFree.coins(limit: 100, start: 1, convert: 'USD,BTC,ETH')
|
37
31
|
#
|
38
32
|
# @param start [Integer] Optionally offset the start (1-based index) of the paginated list of items to return.
|
39
33
|
# @param limit [Integer] Optionally specify the number of results to return. Use this parameter and the 'start' parameter to determine your own pagination size.
|
@@ -43,61 +37,33 @@ module CoinmarketcapFree
|
|
43
37
|
# @param crypto_type [String] The type of cryptocurrency to include. ('all', 'coins', 'tokens')
|
44
38
|
# @param tag_type [String] The tag of cryptocurrency to include. ('all', 'defi', 'filesharing')
|
45
39
|
# @param audited [TrueClass, FalseClass] Show audited 'true' or not 'false'
|
46
|
-
# @param aux [String] Optionally specify a comma-separated list of supplemental data fields to return. Pass 'ath, atl, high24h, low24h, num_market_pairs, cmc_rank, date_added, max_supply, circulating_supply, total_supply, volume_7d, volume_30d, self_reported_circulating_supply, self_reported_market_cap' to include all auxiliary fields.
|
47
40
|
# @param tags [String] If you want to see cryptocurrencies that can be mined, just type 'mineable'.
|
48
41
|
# @param volume24h_range [String] Optionally specify a threshold 24 hour USD volume to filter results by. For example, '0~100000000000000000'
|
49
42
|
# @param percent_change24h_range [String] Optionally specify a threshold 24 hour percent change to filter results by. For example, '0~100' or '-10~100'
|
50
43
|
# @param circulating_supply_range [String] Optionally specify a threshold circulating supply to filter results by. For example, '0~100000000000000000'
|
51
44
|
# @param price_range [String] Optionally specify a threshold USD price to filter results by. For example, '0~100000000000000000'
|
52
45
|
# @param market_cap_range [String] Optionally specify a threshold market cap to filter results by. For example, '0~100000000000000000'
|
53
|
-
# @return [
|
46
|
+
# @return [Array<CoinmarketcapFree::Coin>] Return CoinmarketcapFree::Coin object
|
54
47
|
def coins(**params)
|
55
|
-
|
56
|
-
|
57
|
-
return yield data if block_given?
|
58
|
-
|
59
|
-
JSON.parse(data)
|
48
|
+
Coin.list(**params)
|
60
49
|
end
|
61
50
|
|
62
51
|
# Returns an interval of historic market quotes for any cryptocurrency based on time and interval parameters.
|
63
52
|
#
|
64
|
-
# You can use one of the following intervals: 1D, 7D, 1M, 3M, 1Y, YTD, ALL
|
65
|
-
#
|
66
|
-
# history = CoinmarketcapFree.coin_history(1, '1D')
|
53
|
+
# You can use one of the following intervals: 1D, 7D, 1M, 3M, 1Y, YTD, ALL or custom range like this '1668981600~1671659999'
|
54
|
+
# or call the method by its full name: one_day, seven_days, one_month, three_months, one_year, current_year, all
|
67
55
|
#
|
68
|
-
#
|
56
|
+
# history = CoinmarketcapFree::CoinHistory.custom_time(id_coin, '1D')
|
69
57
|
#
|
70
|
-
#
|
71
|
-
# JSON.parse(data)
|
72
|
-
# end
|
58
|
+
# OR
|
73
59
|
#
|
74
|
-
#
|
75
|
-
# 'points' - Price range history
|
76
|
-
# 'status' - Standardized status object for API calls.
|
60
|
+
# history = CoinmarketcapFree::CoinHistory.one_day(id_coin)
|
77
61
|
#
|
78
62
|
# @param id [Integer] Cryptocurrency identifier from coinmarketcap. For example, Bitcoin has the number 1
|
79
|
-
# @param range_time [String] Range time. For example, '1D', '7D', '1M', '3M', '1Y', 'YTD', 'ALL' or custom range '1668981600~1671659999'
|
80
|
-
# @return [
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
return yield data if block_given?
|
85
|
-
|
86
|
-
JSON.parse(data)
|
87
|
-
end
|
88
|
-
|
89
|
-
# Generate URI image of a coin
|
90
|
-
#
|
91
|
-
# logo = CoinmarketcapFree.coin_icon(1, 64)
|
92
|
-
#
|
93
|
-
# Result:
|
94
|
-
# "https://s2.coinmarketcap.com/static/img/coins/64x64/1.png"
|
95
|
-
#
|
96
|
-
# @param [Integer] id_coin Identify coin. For example, bitcoin has 1
|
97
|
-
# @param [Integer] size Choose one size: 64, 128, 200
|
98
|
-
# @return [String] Return URI from coinmarketcap
|
99
|
-
def coin_icon(id_coin, size)
|
100
|
-
Icon.generate_url(id_coin, size)
|
63
|
+
# @param range_time [String] Range time. For example, '1D', '7D', '1M', '3M', '1Y', 'YTD', 'ALL' or custom range like this '1668981600~1671659999'
|
64
|
+
# @return [Array<CoinmarketcapFree::CoinHistory] Return CoinHistory object
|
65
|
+
def coin_histories(id, range_time)
|
66
|
+
CoinHistory.custom_time(id, range_time)
|
101
67
|
end
|
102
68
|
end
|
103
|
-
end
|
69
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coinmarketcap_free
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vitalii Bakun
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Cryptocurrency information from the Coinmarketcap site without a key.
|
14
14
|
email:
|
@@ -17,6 +17,7 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- ".DS_Store"
|
20
21
|
- ".rubocop.yml"
|
21
22
|
- Gemfile
|
22
23
|
- Gemfile.lock
|
@@ -25,9 +26,11 @@ files:
|
|
25
26
|
- Rakefile
|
26
27
|
- lib/coinmarketcap_free.rb
|
27
28
|
- lib/coinmarketcap_free/coin.rb
|
29
|
+
- lib/coinmarketcap_free/coin/histories.rb
|
30
|
+
- lib/coinmarketcap_free/coin/icon.rb
|
31
|
+
- lib/coinmarketcap_free/coin/model.rb
|
28
32
|
- lib/coinmarketcap_free/coin_history.rb
|
29
33
|
- lib/coinmarketcap_free/helper.rb
|
30
|
-
- lib/coinmarketcap_free/icon.rb
|
31
34
|
- lib/coinmarketcap_free/version.rb
|
32
35
|
homepage:
|
33
36
|
licenses:
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module CoinmarketcapFree
|
4
|
-
# Get static image of a coin from coinmarketcap.com
|
5
|
-
module Icon
|
6
|
-
class << self
|
7
|
-
# Generate URI image of a coin
|
8
|
-
#
|
9
|
-
# logo = CoinmarketcapFree::Icon.generate_url(1, 64)
|
10
|
-
#
|
11
|
-
# Result:
|
12
|
-
# "https://s2.coinmarketcap.com/static/img/coins/64x64/1.png"
|
13
|
-
#
|
14
|
-
# @param [Integer] id_coin Identify coin. For example, bitcoin has 1
|
15
|
-
# @param [Integer] size Choose one size: 64, 128, 200
|
16
|
-
# @return [String] Return URI from coinmarketcap
|
17
|
-
def generate_url(id_coin, size)
|
18
|
-
size_x_size = case size
|
19
|
-
when 64, 128, 200
|
20
|
-
"#{size}x#{size}"
|
21
|
-
else
|
22
|
-
raise ArgumentError, "Can't find this value: #{size}"
|
23
|
-
end
|
24
|
-
"https://s2.coinmarketcap.com/static/img/coins/#{size_x_size}/#{id_coin}.png"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|