coinmarketcap_api 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a63d4c7022d4439232e82c24fc96e4a70470dccf4e4d087a90595c67fd2ab3bd
4
+ data.tar.gz: 723368327aafd269b87e090b6b640752b3a2090918e9311863e5c2501a1ad376
5
+ SHA512:
6
+ metadata.gz: ecae9fb9de7bd5519bb6d34789a5f5035199944621763fc7dd3dc76c67cf890915649b592cfe847e518b2ef5a731b253825fcb4e7c9a3b8089e620dc1c792e40
7
+ data.tar.gz: e6e5822fa9d1f3a63db48a94ff03fc7c2b1914422d60bd94d1b4a2d19d9bd98279933eac7ee1e6f833370ece55d468cea25b8057b27733025a605f54278fd99a
@@ -0,0 +1,12 @@
1
+ /.idea/
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,16 @@
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=fdaa2ff83ce5c382a3c7ef7886a95a108a7925b18f127f8591a83e83b1df4569
4
+ sudo: false
5
+ language: ruby
6
+ rvm:
7
+ - 2.5.0
8
+ before_install: gem install bundler -v 1.16.1
9
+ before_script:
10
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
11
+ - chmod +x ./cc-test-reporter
12
+ - ./cc-test-reporter before-build
13
+ scripts:
14
+ - bundle exec rspec spec
15
+ after_script:
16
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at dev.yuriy.a@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
@@ -0,0 +1,38 @@
1
+ # Contributing
2
+
3
+ We love contributions from everyone.
4
+ By participating in this project,
5
+ you agree to abide by the [Code of Conduct](https://github.com/yuriyalekseyev/coinmarketcap_api/blob/master/CODE_OF_CONDUCT.md).
6
+
7
+ ## Contributing Code
8
+
9
+ 1. [Fork](https://github.com/yuriyalekseyev/coinmarketcap_api/fork) a repo.
10
+
11
+ 2. Install dependencies.
12
+
13
+ bundle install
14
+
15
+ 3. Create your feature branch.
16
+
17
+ git checkout -b my-new-feature
18
+
19
+ 4. Make sure the tests pass:
20
+
21
+ bundle exec rspec
22
+
23
+ 5. Make your change, with new passing tests.
24
+ Write a [good commit message](https://github.com/erlang/otp/wiki/Writing-good-commit-messages).
25
+
26
+ git commit -am 'Add some feature'
27
+
28
+ 6. Push to your fork.
29
+
30
+ git push origin my-new-feature
31
+
32
+ 7. Create a new [Pull Request](https://github.com/yuriyalekseyev/coinmarketcap_api/pulls).
33
+
34
+ Others will give constructive feedback.
35
+
36
+ This is a time for discussion and improvements,
37
+ and making the necessary changes will be required before we can
38
+ merge the contribution.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in coinmarketcap_api.gemspec
6
+ gemspec
@@ -0,0 +1,79 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ coinmarketcap_api (1.0.0)
5
+ faraday
6
+ hashie
7
+ multi_json
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (5.1.5)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (~> 0.7)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ ansi (1.5.0)
18
+ concurrent-ruby (1.0.5)
19
+ diff-lcs (1.3)
20
+ docile (1.3.0)
21
+ ethon (0.11.0)
22
+ ffi (>= 1.3.0)
23
+ factory_bot (4.8.2)
24
+ activesupport (>= 3.0.0)
25
+ faraday (0.14.0)
26
+ multipart-post (>= 1.2, < 3)
27
+ ffi (1.9.23)
28
+ hashie (3.5.7)
29
+ hirb (0.7.3)
30
+ i18n (0.9.5)
31
+ concurrent-ruby (~> 1.0)
32
+ json (2.1.0)
33
+ minitest (5.11.3)
34
+ multi_json (1.13.1)
35
+ multipart-post (2.0.0)
36
+ rake (10.5.0)
37
+ rspec (3.7.0)
38
+ rspec-core (~> 3.7.0)
39
+ rspec-expectations (~> 3.7.0)
40
+ rspec-mocks (~> 3.7.0)
41
+ rspec-core (3.7.1)
42
+ rspec-support (~> 3.7.0)
43
+ rspec-expectations (3.7.0)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.7.0)
46
+ rspec-mocks (3.7.0)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.7.0)
49
+ rspec-support (3.7.1)
50
+ simplecov (0.16.1)
51
+ docile (~> 1.1)
52
+ json (>= 1.8, < 3)
53
+ simplecov-html (~> 0.10.0)
54
+ simplecov-console (0.4.2)
55
+ ansi
56
+ hirb
57
+ simplecov
58
+ simplecov-html (0.10.2)
59
+ thread_safe (0.3.6)
60
+ typhoeus (1.3.0)
61
+ ethon (>= 0.9.0)
62
+ tzinfo (1.2.5)
63
+ thread_safe (~> 0.1)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ bundler (~> 1.16)
70
+ coinmarketcap_api!
71
+ factory_bot (~> 4.0)
72
+ rake (~> 10.0)
73
+ rspec (~> 3.0)
74
+ simplecov
75
+ simplecov-console
76
+ typhoeus
77
+
78
+ BUNDLED WITH
79
+ 1.16.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Yuriy Alekseyev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,279 @@
1
+ # coinmarketcap_api
2
+
3
+ [Coinmarketcap.com](https://coinmarketcap.com/api/) API wrapper in Ruby.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/coinmarketcap_api.svg)](https://badge.fury.io/rb/coinmarketcap_api)
6
+ [![Downloads](https://img.shields.io/gem/dt/coinmarketcap_api.svg)](https://rubygems.org/gems/coinmarketcap_api)
7
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?longCache=true&license=MIT)](https://github.com/yuriyalekseyev/coinmarketcap_api/blob/master/LICENSE.txt)
8
+ [![Maintainability](https://api.codeclimate.com/v1/badges/c184f6db8ef8020581f4/maintainability)](https://codeclimate.com/github/yuriyalekseyev/coinmarketcap_api/maintainability)
9
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/c184f6db8ef8020581f4/test_coverage)](https://codeclimate.com/github/yuriyalekseyev/coinmarketcap_api/test_coverage)
10
+ [![Build Status](https://travis-ci.org/yuriyalekseyev/coinmarketcap_api.svg?branch=master)](https://travis-ci.org/yuriyalekseyev/coinmarketcap_api)
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'coinmarketcap_api'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ bundle install
23
+
24
+ Or install it yourself as:
25
+
26
+ gem install coinmarketcap_api
27
+
28
+ ## Usage
29
+
30
+ Make sure you require the library.
31
+
32
+ ```ruby
33
+ require 'coinmarketcap_api'
34
+ ```
35
+
36
+ You can then make requests to the `CoinMarketCap.request(type, options = {})` method.
37
+
38
+ Valid types in the `types` parameter are:
39
+
40
+ * `'ticker'`
41
+ * `'global'`
42
+
43
+ Default is `'ticker'`.
44
+
45
+ Valid options in the `options` hash are:
46
+
47
+ * `:currency` - `[String]`, return results only for specified currency, for example `'bitcoin'`.
48
+ * `:start` - `[Integer]`, return results from rank `[start]` and above.
49
+ * `:limit` - `[Integer]`, return a maximum of `[limit]` results (default is `100`, use `0` to return all results).
50
+ * `:convert` - `[String]`, return price, daily_volume, and market cap in terms of another currency.
51
+ * Valid values are: `"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"`.
52
+
53
+ ---
54
+
55
+ Get top 100 currencies:
56
+
57
+ ```ruby
58
+ CoinMarketCap.request()
59
+ ```
60
+
61
+ Get global data:
62
+
63
+ ```ruby
64
+ CoinMarketCap.request(type: 'global')
65
+ ```
66
+
67
+ Get global data with additional properties comparing it to `eur`:
68
+
69
+ ```ruby
70
+ CoinMarketCap.request(type: 'global', options: {compare: 'eur'})
71
+ ```
72
+
73
+ Get top 5 currencies:
74
+
75
+ ```ruby
76
+ CoinMarketCap.request(options: {limit: 5})
77
+ ```
78
+
79
+ Get 5 currencies starting from 6th:
80
+
81
+ ```ruby
82
+ CoinMarketCap.request(options: {limit: 5, start: 5})
83
+ ```
84
+
85
+ Get data for `bitcoin`:
86
+
87
+ ```ruby
88
+ CoinMarketCap.request(options: {currency: 'bitcoin'})
89
+ ```
90
+
91
+ Get data for `bitcoin` with additional properties comparing it to `eur`:
92
+
93
+ ```ruby
94
+ CoinMarketCap.request(options: {currency: 'bitcoin', compare: 'eur'})
95
+ ```
96
+
97
+ ---
98
+
99
+ The `request(...)` method will return a response that you can interact with in a more-friendly way, such as:
100
+
101
+ ```ruby
102
+ request = CoinMarketCap.request(options: {currency: 'bitcoin'})
103
+ request.percent_change_hourly
104
+ request.rank
105
+ ```
106
+
107
+ ```ruby
108
+ request = CoinMarketCap.request()
109
+ request.first.available_supply
110
+ request.first.symbol
111
+ ```
112
+
113
+ Depending on request options, responce parameters may differ:
114
+
115
+ ```ruby
116
+ request = CoinMarketCap.request(type: 'ticker').first
117
+
118
+ # Type: 'ticker' request return [Array] of objects with following methods:
119
+
120
+ request.id
121
+ # => "bitcoin"
122
+ request.name
123
+ # => "Bitcoin"
124
+ request.symbol
125
+ # => "BTC"
126
+ request.rank
127
+ # => "1"
128
+ request.price_usd
129
+ # => "7952.59"
130
+ request.price_btc
131
+ # => "1.0"
132
+ request.daily_volume_usd
133
+ # => "4905290000.0"
134
+ request.market_cap_usd
135
+ # => "134748486145"
136
+ request.available_supply
137
+ # => "16943975.0"
138
+ request.total_supply
139
+ # => "16943975.0"
140
+ request.max_supply
141
+ # => "21000000.0"
142
+ request.percent_change_hourly
143
+ # => "0.16"
144
+ request.percent_change_daily
145
+ # => "-0.23"
146
+ request.percent_change_weekly
147
+ # => "-12.44"
148
+ request.last_updated
149
+ # => "1522227867"
150
+ ```
151
+
152
+ ```ruby
153
+ request = CoinMarketCap.request(type: 'ticker', options: {convert: 'eur'}).first
154
+
155
+ # When convert option specified, following methods added for each responce object:
156
+
157
+ request.price_eur
158
+ # => "6408.92070769",
159
+ request.daily_volume_eur
160
+ # => "3953129063.39",
161
+ request.market_cap_eur
162
+ # => "108592592248"
163
+
164
+ # _eur part may change depending on your options: convert value
165
+ request = CoinMarketCap.request(type: 'ticker', options: {convert: 'aud'}).first
166
+
167
+ request.price_aud
168
+ # => "6408.92070769",
169
+ request.daily_volume_aud
170
+ # => "3953129063.39",
171
+ request.market_cap_aud
172
+ # => "108592592248"
173
+ ```
174
+
175
+ ```ruby
176
+ request = CoinMarketCap.request(type: 'global')
177
+
178
+ # Type: 'global' requests return [Object] with following methods:
179
+
180
+ request.total_market_cap_usd
181
+ # => 301152981078.0
182
+ request.total_daily_volume_usd
183
+ # => 13548242090.0
184
+ request.bitcoin_percentage_of_market_cap
185
+ # => 44.74
186
+ request.active_currencies
187
+ # => 916
188
+ request.active_assets
189
+ # => 675
190
+ request.active_markets
191
+ # => 9753
192
+ request.last_updated
193
+ # => 1522227867
194
+ ```
195
+
196
+ ```ruby
197
+ request = CoinMarketCap.request(type: 'global', options: {convert: 'eur'})
198
+
199
+ # When convert option specified for type:global requests,
200
+ # following methods added for a responce object:
201
+
202
+ request.total_market_cap_eur
203
+ # => 242696477074.0,
204
+ request.total_daily_volume_eur
205
+ # => 10918406367.0
206
+
207
+ # _eur part may change depending on your options: convert value
208
+ request = CoinMarketCap.request(type: 'global', options: {convert: 'aud'})
209
+
210
+ request.total_market_cap_aud
211
+ # => 242696477074.0,
212
+ request.total_daily_volume_aud
213
+ # => 10918406367.0
214
+ ```
215
+
216
+ Please refer to the [coinmarketcap](https://coinmarketcap.com/api/) API documentation for more information on the full response properties.
217
+
218
+ #### NOTE!
219
+ >Due to Ruby method naming restrictions [coinmarketcap](https://coinmarketcap.com/api/) API properties which contain `24h`, `1h`, `7d` was renamed to be `daily`, `hourly` and `weekly` respectively.
220
+
221
+ ## Configuration
222
+
223
+ The HTTP requests are made with [Faraday](https://github.com/lostisland/faraday), which uses `Net::HTTP` by default. Changing the adapter is easy. We will use typhoeus as an example.
224
+
225
+ Make sure to include the typhoeus gem in your `Gemfile`:
226
+
227
+ ```ruby
228
+ gem 'typhoeus'
229
+ ```
230
+
231
+ ```ruby
232
+ require 'typhoeus/adapters/faraday'
233
+
234
+ Faraday.default_adapter = :typhoeus
235
+ ```
236
+
237
+ Alternatively:
238
+
239
+ ```ruby
240
+ require 'typhoeus/adapters/faraday'
241
+
242
+ CoinMarketCap.connection = Faraday.new do |builder|
243
+ builder.adapter :typhoeus
244
+ end
245
+ ```
246
+
247
+ You can also customise the default parameters passed through on each API call:
248
+
249
+ ```ruby
250
+ CoinMarketCap.configure do |configuration|
251
+ configuration.timeout = 500
252
+ end
253
+ ```
254
+
255
+ ## Contributing to coinmarketcap_api
256
+
257
+ [Bug Reports] and [Pull Requests] are welcome on [GitHub Project page].
258
+
259
+ [github project page]: https://github.com/yuriyalekseyev/coinmarketcap_api
260
+ [bug reports]: https://github.com/yuriyalekseyev/coinmarketcap_api/issues
261
+ [pull requests]: https://github.com/yuriyalekseyev/coinmarketcap_api/pulls
262
+
263
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
264
+
265
+ Please read the [CONTRIBUTING.md] for details on our code of conduct, and the process for submitting pull requests to us.
266
+
267
+ [contributing.md]: https://github.com/yuriyalekseyev/coinmarketcap_api/blob/master/CONTRIBUTING.md
268
+
269
+ ## License
270
+
271
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
272
+
273
+ ## Code of Conduct
274
+
275
+ Everyone interacting in the `coinmarketcap_api` project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yuriyalekseyev/coinmarketcap_api/blob/master/CODE_OF_CONDUCT.md).
276
+
277
+ ## Copyright
278
+
279
+ Copyright (c) 2018 Yuriy Alekseyev. See [LICENSE.txt](https://github.com/yuriyalekseyev/coinmarketcap_api/blob/master/LICENSE.txt) for further details.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "coinmarketcap_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'coinmarketcap_api/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'coinmarketcap_api'
7
+ spec.version = CoinMarketCap::VERSION
8
+ spec.authors = ['Yuriy Alekseyev']
9
+ spec.email = ['dev.yuriy.a@gmail.com']
10
+
11
+ spec.summary = 'Friendly and convenient Coinmarketcap.com API wrapper in Ruby.'
12
+ spec.description = 'Friendly and convenient Coinmarketcap.com API wrapper in Ruby.'
13
+ spec.homepage = 'https://github.com/yuriyalekseyev/coinmarketcap_api'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'faraday'
25
+ spec.add_dependency 'hashie'
26
+ spec.add_dependency 'multi_json'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.16'
29
+ spec.add_development_dependency 'factory_bot', '~> 4.0'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.0'
32
+ spec.add_development_dependency 'simplecov'
33
+ spec.add_development_dependency 'simplecov-console'
34
+ spec.add_development_dependency 'typhoeus'
35
+ end
@@ -0,0 +1,73 @@
1
+ require 'coinmarketcap_api/version'
2
+ require 'coinmarketcap_api/configuration'
3
+
4
+ require 'hashie'
5
+ require 'multi_json'
6
+ require 'faraday'
7
+
8
+ module CoinMarketCap
9
+ extend Configuration
10
+
11
+ self.default_params = {}
12
+
13
+ class << self
14
+ # Retrieve the request for a given type and options.
15
+ #
16
+ # @param [String] type Type of request.
17
+ # Can be either `ticker` or `global`.
18
+ # @param [Object] options Optional parameters.
19
+ # Valid options are `:currency`, `:start`, `:limit` and `:convert`.
20
+ # @return [Array,Hash]
21
+ def request(type: 'ticker', options: {})
22
+ request_response = get(request_url(options, type), options[:params])
23
+
24
+ if request_response.success?
25
+ # Rename api properties due to ruby restrictions.
26
+ dictionary = { '1h' => 'hourly', '24h' => 'daily', '7d' => 'weekly' }
27
+ dictionary.each { |k, v| request_response.body.gsub!(k, v) }
28
+
29
+ result = MultiJson.load(request_response.body)
30
+
31
+ if multiple_responses?(options, result, type)
32
+ return result.map { |hash| Hashie::Mash.new(hash) }
33
+ end
34
+
35
+ result = result.first if result.length == 1
36
+
37
+ Hashie::Mash.new(result)
38
+ end
39
+ end
40
+
41
+ # Build or get an HTTP connection object.
42
+ def connection
43
+ @connection ||= Faraday.new(request: { timeout: CoinMarketCap.timeout })
44
+ end
45
+
46
+ # Set an HTTP connection object.
47
+ #
48
+ # @param connection Connection object to be used.
49
+ def connection=(connection)
50
+ @connection = connection
51
+ end
52
+
53
+ private
54
+ def request_url(options, type)
55
+ query_options = options.reject { |k| k == :currency }
56
+
57
+ result = "#{CoinMarketCap.api_endpoint}/#{type}/"
58
+ result += "#{options[:currency]}/" if options[:currency]
59
+ result += "?#{query_options.map { |k, v| "#{k}=#{v}" }.join('&')}"
60
+ result
61
+ end
62
+
63
+ def multiple_responses?(options, result, type)
64
+ result.is_a?(Array) && !options[:currency] && type != 'global'
65
+ end
66
+
67
+ def get(path, params = {})
68
+ params = CoinMarketCap.default_params.merge(params || {})
69
+
70
+ connection.get(path, params)
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,34 @@
1
+ module CoinMarketCap
2
+ module Configuration
3
+ # Default API endpoint
4
+ DEFAULT_API_ENDPOINT = 'https://api.coinmarketcap.com/v1'.freeze
5
+
6
+ # Request read timeout
7
+ attr_writer :timeout
8
+
9
+ # Default parameters
10
+ attr_accessor :default_params
11
+
12
+ # Yield self to be able to configure
13
+ # CoinMarketCap with block-style configuration.
14
+ #
15
+ # Example:
16
+ #
17
+ # CoinMarketCap.configure do |configuration|
18
+ # configuration.timeout = 500
19
+ # end
20
+ def configure
21
+ yield self
22
+ end
23
+
24
+ # API endpoint
25
+ def api_endpoint
26
+ @api_endpoint ||= DEFAULT_API_ENDPOINT
27
+ end
28
+
29
+ # Request read timeout
30
+ def timeout
31
+ @timeout
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module CoinMarketCap
2
+ VERSION = '1.0.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coinmarketcap_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuriy Alekseyev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hashie
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: multi_json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: factory_bot
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov-console
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: typhoeus
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Friendly and convenient Coinmarketcap.com API wrapper in Ruby.
154
+ email:
155
+ - dev.yuriy.a@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rspec"
162
+ - ".travis.yml"
163
+ - CODE_OF_CONDUCT.md
164
+ - CONTRIBUTING.md
165
+ - Gemfile
166
+ - Gemfile.lock
167
+ - LICENSE.txt
168
+ - README.md
169
+ - Rakefile
170
+ - bin/console
171
+ - bin/setup
172
+ - coinmarketcap_api.gemspec
173
+ - lib/coinmarketcap_api.rb
174
+ - lib/coinmarketcap_api/configuration.rb
175
+ - lib/coinmarketcap_api/version.rb
176
+ homepage: https://github.com/yuriyalekseyev/coinmarketcap_api
177
+ licenses:
178
+ - MIT
179
+ metadata: {}
180
+ post_install_message:
181
+ rdoc_options: []
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirements: []
195
+ rubyforge_project:
196
+ rubygems_version: 2.7.3
197
+ signing_key:
198
+ specification_version: 4
199
+ summary: Friendly and convenient Coinmarketcap.com API wrapper in Ruby.
200
+ test_files: []