coingecko_ruby 0.1.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 +7 -0
- data/LICENSE.md +21 -0
- data/README.md +72 -0
- data/Rakefile +10 -0
- data/coingecko_ruby.gemspec +28 -0
- data/lib/coingecko_ruby.rb +10 -0
- data/lib/coingecko_ruby/client.rb +13 -0
- data/lib/coingecko_ruby/client/coins.rb +25 -0
- data/lib/coingecko_ruby/client/prices.rb +27 -0
- data/lib/coingecko_ruby/client/status.rb +9 -0
- data/lib/coingecko_ruby/connection.rb +26 -0
- data/lib/coingecko_ruby/version.rb +3 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2d4ca5a09aa9298cb8612205166f45778d4fcb5ccdcdd78b7e801b70b941f80f
|
4
|
+
data.tar.gz: 7730cf32e62d09879c8288ea5188ee3e1d8f8d491d21e1fbd4dce9c714c177b8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b4ca439622cddb324295ffc518b45318d72899402360a42543e83f5b90959b444c494cfd5797bfc255c3d0a88afa5bc2df8afe03d4bc418d8bb18b59de87b325
|
7
|
+
data.tar.gz: 55d787ce4dbd09cd6915eeabb987b94402eb3345b210d7b4f748d1d147b97d2a415b899e88640702c0f93f6bc75ce363b3e091f45d4a601b0926beba30c328f6
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 Julian Foo Siang Sen
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# CoingeckoRuby
|
2
|
+
|
3
|
+
CoingeckoRuby is an easy-to-use client/wrapper for CoinGecko's awesome cryptocurrency API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'coingecko_ruby'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install coingecko_ruby
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
1. Require the gem.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'coingecko_ruby'
|
27
|
+
```
|
28
|
+
|
29
|
+
2. Create a client instance.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
client = CoingeckoRuby.client
|
33
|
+
```
|
34
|
+
|
35
|
+
3. Use the client to fetch your desired data.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
# Example: Fetching the current price of Bitcoin
|
39
|
+
client.get_prices(ids: 'bitcoin', vs_currencies: 'usd')
|
40
|
+
```
|
41
|
+
|
42
|
+
## Documentation
|
43
|
+
|
44
|
+
WORK IN PROGRESS
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/julianfssen/coingecko_ruby.
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
MIT License
|
53
|
+
|
54
|
+
Copyright (c) 2021 Julian Foo Siang Sen
|
55
|
+
|
56
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
57
|
+
of this software and associated documentation files (the "Software"), to deal
|
58
|
+
in the Software without restriction, including without limitation the rights
|
59
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
60
|
+
copies of the Software, and to permit persons to whom the Software is
|
61
|
+
furnished to do so, subject to the following conditions:
|
62
|
+
|
63
|
+
The above copyright notice and this permission notice shall be included in all
|
64
|
+
copies or substantial portions of the Software.
|
65
|
+
|
66
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
67
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
68
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
69
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
70
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
71
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
72
|
+
SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'lib/coingecko_ruby/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "coingecko_ruby"
|
5
|
+
spec.version = CoingeckoRuby::VERSION
|
6
|
+
spec.authors = ["Julian Foo Siang Sen"]
|
7
|
+
spec.email = ["juliandevmy@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{An easy-to-use client/wrapper for CoinGecko's crypto API}
|
10
|
+
spec.description = %q{An easy-to-use client/wrapper for CoinGecko's crypto API. Get prices, exchanges, volume, and more without building your own API class.}
|
11
|
+
spec.homepage = "https://github.com/julianfssen/coingecko_ruby"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = "https://github.com/julianfssen/coingecko_ruby"
|
16
|
+
spec.metadata["changelog_uri"] = "https://github.com/julianfssen/coingecko_ruby"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
# spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
# `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
# end
|
23
|
+
spec.files = %w(LICENSE.md README.md Rakefile coingecko_ruby.gemspec)
|
24
|
+
spec.files += Dir.glob("lib/**/*.rb")
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'coingecko_ruby/connection'
|
2
|
+
require 'coingecko_ruby/client/status'
|
3
|
+
require 'coingecko_ruby/client/prices'
|
4
|
+
require 'coingecko_ruby/client/coins'
|
5
|
+
|
6
|
+
module CoingeckoRuby
|
7
|
+
class Client
|
8
|
+
include CoingeckoRuby::Connection
|
9
|
+
include CoingeckoRuby::Client::Status
|
10
|
+
include CoingeckoRuby::Client::Prices
|
11
|
+
include CoingeckoRuby::Client::Coins
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module CoingeckoRuby
|
2
|
+
class Client
|
3
|
+
module Coins
|
4
|
+
def coins_list
|
5
|
+
get('coins/list')
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_coin_data(id:)
|
9
|
+
get("coins/#{id}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_coin_tickers(id:)
|
13
|
+
get("coins/#{id}")
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_coin_data(id:)
|
17
|
+
get("coins/#{id}")
|
18
|
+
end
|
19
|
+
|
20
|
+
def markets
|
21
|
+
get('coins/markets')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module CoingeckoRuby
|
2
|
+
class Client
|
3
|
+
module Prices
|
4
|
+
def get_prices(ids:, vs_currencies: 'usd')
|
5
|
+
get('simple/price', { query: { ids: ids, vs_currencies: vs_currencies } })
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_historical_price_on_date(id:, date:)
|
9
|
+
get("coins/#{id}/history", { query: { date: date } })
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_minutely_historical_prices(id:, vs_currency: 'usd')
|
13
|
+
get("coins/#{id}/market_chart", { query: { vs_currency: vs_currency, days: 1 } })
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_hourly_historical_prices(id:, days:)
|
17
|
+
return get_daily_historical_prices(id: id, days: days) if days > 90
|
18
|
+
|
19
|
+
get("coins/#{id}/market_chart", { query: { vs_currency: vs_currency, days: days } })
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_daily_historical_prices(id:, days:)
|
23
|
+
get("coins/#{id}/market_chart", { query: { vs_currency: vs_currency, days: days, interval: 'daily' } })
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module CoingeckoRuby
|
6
|
+
module Connection
|
7
|
+
BASE_URL = 'https://api.coingecko.com/api/v3/'
|
8
|
+
|
9
|
+
def get(endpoint, options = {})
|
10
|
+
url = BASE_URL + endpoint
|
11
|
+
uri = URI(url)
|
12
|
+
if options[:query]
|
13
|
+
uri = build_params(uri, options[:query])
|
14
|
+
end
|
15
|
+
response = Net::HTTP.get(uri)
|
16
|
+
JSON.parse(response)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def build_params(uri, params)
|
22
|
+
uri.query = URI.encode_www_form(params)
|
23
|
+
uri
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coingecko_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Julian Foo Siang Sen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-05-13 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: An easy-to-use client/wrapper for CoinGecko's crypto API. Get prices,
|
14
|
+
exchanges, volume, and more without building your own API class.
|
15
|
+
email:
|
16
|
+
- juliandevmy@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- LICENSE.md
|
22
|
+
- README.md
|
23
|
+
- Rakefile
|
24
|
+
- coingecko_ruby.gemspec
|
25
|
+
- lib/coingecko_ruby.rb
|
26
|
+
- lib/coingecko_ruby/client.rb
|
27
|
+
- lib/coingecko_ruby/client/coins.rb
|
28
|
+
- lib/coingecko_ruby/client/prices.rb
|
29
|
+
- lib/coingecko_ruby/client/status.rb
|
30
|
+
- lib/coingecko_ruby/connection.rb
|
31
|
+
- lib/coingecko_ruby/version.rb
|
32
|
+
homepage: https://github.com/julianfssen/coingecko_ruby
|
33
|
+
licenses: []
|
34
|
+
metadata:
|
35
|
+
homepage_uri: https://github.com/julianfssen/coingecko_ruby
|
36
|
+
source_code_uri: https://github.com/julianfssen/coingecko_ruby
|
37
|
+
changelog_uri: https://github.com/julianfssen/coingecko_ruby
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.3.0
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubygems_version: 3.1.2
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: An easy-to-use client/wrapper for CoinGecko's crypto API
|
57
|
+
test_files: []
|