coinmarketcap-ruby-client 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 378c754280f2105451ade40e5c3f56a8ffe66dded187feb5948fdc7aa83b3ba7
4
+ data.tar.gz: ab7bce01c3133499a282c777e4f049cbea1ad661699ca5ef2a26158fd44e670d
5
+ SHA512:
6
+ metadata.gz: f8058075d308ecec683b1e95b9632411ea2ef7bfe1f0540cdd80a90aa019210505f7e405506e231cd567b5ddde475b54a47f8afb60f1975f1d5f81076f7b875c
7
+ data.tar.gz: '079587b57b95e4b9d9bad537750b7859b18a3d79ed46d610aaf219fcdf280bd02f4f8446bacec97f384437d6cbd7cd7274f00ba6a184f68bfc09feda4ad36bab'
data/.rubocop.yml ADDED
@@ -0,0 +1,12 @@
1
+ AllCops:
2
+ Exclude:
3
+ - vendor/**/*
4
+
5
+ Style/FrozenStringLiteralComment:
6
+ Enabled: false
7
+ Metrics/MethodLength:
8
+ Max: 25
9
+ Metrics/LineLength:
10
+ Max: 100
11
+ Style/Documentation:
12
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ ### 1.0.1 (Next)
2
+ * Contributions here
3
+
4
+ ### 1.0.0 (2021/10/05)
5
+ * [#1](https://github.com/koffeefinance/coinmarketcap-ruby-client/pull/1): Added support to fetch the CoinMarketCap ID Map.
6
+
@@ -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 mathusans52@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 [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in coinmarketcap-ruby-client.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ coinmarketcap-ruby-client (1.0.0)
5
+ faraday (>= 1.8)
6
+ faraday_middleware (>= 1.1)
7
+ hashie
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.8.0)
13
+ public_suffix (>= 2.0.2, < 5.0)
14
+ ast (2.4.2)
15
+ crack (0.4.5)
16
+ rexml
17
+ faraday (1.8.0)
18
+ faraday-em_http (~> 1.0)
19
+ faraday-em_synchrony (~> 1.0)
20
+ faraday-excon (~> 1.1)
21
+ faraday-httpclient (~> 1.0.1)
22
+ faraday-net_http (~> 1.0)
23
+ faraday-net_http_persistent (~> 1.1)
24
+ faraday-patron (~> 1.0)
25
+ faraday-rack (~> 1.0)
26
+ multipart-post (>= 1.2, < 3)
27
+ ruby2_keywords (>= 0.0.4)
28
+ faraday-em_http (1.0.0)
29
+ faraday-em_synchrony (1.0.0)
30
+ faraday-excon (1.1.0)
31
+ faraday-httpclient (1.0.1)
32
+ faraday-net_http (1.0.1)
33
+ faraday-net_http_persistent (1.2.0)
34
+ faraday-patron (1.0.0)
35
+ faraday-rack (1.0.0)
36
+ faraday_middleware (1.1.0)
37
+ faraday (~> 1.0)
38
+ hashdiff (1.0.1)
39
+ hashie (4.1.0)
40
+ jaro_winkler (1.5.4)
41
+ minitest (5.14.4)
42
+ mocha (1.13.0)
43
+ multipart-post (2.1.1)
44
+ parallel (1.21.0)
45
+ parser (3.0.2.0)
46
+ ast (~> 2.4.1)
47
+ public_suffix (4.0.6)
48
+ rainbow (3.0.0)
49
+ rake (12.3.3)
50
+ rexml (3.2.5)
51
+ rubocop (0.72.0)
52
+ jaro_winkler (~> 1.5.1)
53
+ parallel (~> 1.10)
54
+ parser (>= 2.6)
55
+ rainbow (>= 2.2.2, < 4.0)
56
+ ruby-progressbar (~> 1.7)
57
+ unicode-display_width (>= 1.4.0, < 1.7)
58
+ ruby-progressbar (1.11.0)
59
+ ruby2_keywords (0.0.5)
60
+ unicode-display_width (1.6.1)
61
+ vcr (6.0.0)
62
+ webmock (3.14.0)
63
+ addressable (>= 2.8.0)
64
+ crack (>= 0.3.2)
65
+ hashdiff (>= 0.4.0, < 2.0.0)
66
+
67
+ PLATFORMS
68
+ ruby
69
+
70
+ DEPENDENCIES
71
+ coinmarketcap-ruby-client!
72
+ minitest (~> 5.0)
73
+ mocha (~> 1.13)
74
+ rake (~> 12.0)
75
+ rubocop (= 0.72.0)
76
+ vcr (~> 6.0)
77
+ webmock (~> 3.14)
78
+
79
+ BUNDLED WITH
80
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Mathusan Selvarajah
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.
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # CoinMarketCap Ruby API Client
2
+
3
+ A ruby API client for [CoinMarketCap](https://coinmarketcap.com/api/documentation/v1/)
4
+
5
+ # Table of Contents
6
+
7
+ - [Installation](#installation)
8
+ - [Usage](#usage)
9
+ - [Get an API Key](#get-an-api-token)
10
+ - [Configure](#configure)
11
+ - [Get CoinMarketCap ID Map](#get-coinmarketcap-id-map)
12
+ - [Development](#development)
13
+ - [Contributing](#contributing)
14
+ - [License](#license)
15
+ - [Code of Conduct](#code-of-conduct)
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem 'coinmarketcap-ruby-client'
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ $ bundle install
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install coinmarketcap-ruby-client
32
+
33
+ ## Usage
34
+
35
+ ### Get an API Key
36
+
37
+ Create an account on [CoinMarketCap](https://pro.coinmarketcap.com/) and get copy the API key from the developer console.
38
+
39
+ ### Configure
40
+
41
+ ```ruby
42
+ CoinMarketCap::Api.configure do |config|
43
+ config.api_key = 'api_key'
44
+ config.user_agent = 'custom/user_agent' # Default: 'CoinMarketCap Ruby Client/1.0.0'
45
+ config.user_agent = 'https://pro-api.coinmarketcap.com/v1' # Default: 'https://pro-api.coinmarketcap.com/v1'
46
+ end
47
+ ```
48
+
49
+ ### Get CoinMarketCap ID Map
50
+
51
+ Fetches the CoinMarketCap ID Map. By default this endpoint returns cryptocurrencies that have actively tracked markets on supported exchanges.
52
+
53
+ ```ruby
54
+ cryptocurrencies = client.map
55
+
56
+ currency = cryptocurrencies.first
57
+ currency.id # 825
58
+ currency.name # 'Tether'
59
+ currency.symbol # 'USDT'
60
+ currency.rank # 5
61
+ currency.slug # 'tether'
62
+ currency.is_active # 1
63
+ currency.first_historical_data # <Date: 2015-02-25 ((2457079j,0s,0n),+0s,2299161j)>
64
+ currency.last_historical_data # <Date: 2021-10-05 ((2459493j,0s,0n),+0s,2299161j)>
65
+
66
+ platform = currency.platform
67
+ platform.id # 1027
68
+ platform.name # 'Ethereum'
69
+ platform.symbol # 'ETH'
70
+ platform.slug # 'ethereum'
71
+ platform.token_address # '0xdac17f958d2ee523a2206206994597c13d831ec7'
72
+ ```
73
+
74
+ See [Cryptocurrency Map](https://coinmarketcap.com/api/documentation/v1/#operation/getV1CryptocurrencyMap) for detailed documentation.
75
+
76
+ ## Development
77
+
78
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
79
+
80
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
81
+
82
+ ## Contributing
83
+
84
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[koffeefinance]/coinmarketcap-ruby-client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/koffeefinance/coinmarketcap-ruby-client/blob/master/CODE_OF_CONDUCT.md).
85
+
86
+ ## License
87
+
88
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
89
+
90
+ ## Code of Conduct
91
+
92
+ Everyone interacting in the CoinMarketCap-Ruby-Client project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/koffeefinance/coinmarketcap-ruby-client/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "coinmarketcap/ruby/client"
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__)
data/bin/setup ADDED
@@ -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,37 @@
1
+ require_relative 'lib/coinmarketcap/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'coinmarketcap-ruby-client'
5
+ spec.version = CoinMarketCap::VERSION
6
+ spec.authors = ['Mathusan Selvarajah']
7
+ spec.email = ['mathusans52@gmail.com']
8
+
9
+ spec.summary = 'CoinMarketCap API Ruby client.'
10
+ spec.description = 'An actively maintined Ruby Client for CoinMarketCap API'
11
+ spec.homepage = 'https://github.com/koffeefinance/coinmarketcap-ruby-client'
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
14
+
15
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/koffeefinance/coinmarketcap-ruby-client'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/koffeefinance/coinmarketcap-ruby-client/CHANGELOG.md'
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_dependency 'faraday', '>= 1.8'
31
+ spec.add_dependency 'faraday_middleware', '>= 1.1'
32
+ spec.add_dependency 'hashie'
33
+ spec.add_development_dependency 'mocha', '~> 1.13'
34
+ spec.add_development_dependency 'rubocop', '0.72.0'
35
+ spec.add_development_dependency 'vcr', '~> 6.0'
36
+ spec.add_development_dependency 'webmock', '~> 3.14'
37
+ end
@@ -0,0 +1,25 @@
1
+ module CoinMarketCap
2
+ module Api
3
+ extend Config::Client::Accessor
4
+ extend Config::Logger::Accessor
5
+
6
+ class Client
7
+ include Endpoints::Cryptocurrency
8
+
9
+ include Cloud::Connection
10
+ include Cloud::Request
11
+
12
+ attr_accessor(*Config::Client::ATTRIBUTES)
13
+
14
+ attr_reader :logger
15
+
16
+ def initialize(options = {})
17
+ Config::Client::ATTRIBUTES.each do |key|
18
+ send("#{key}=", options[key] || CoinMarketCap::Api.config.send(key))
19
+ end
20
+ @logger = Config::Logger.dup
21
+ @logger.instance = options[:logger] if options.key?(:logger)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,37 @@
1
+ module CoinMarketCap
2
+ module Api
3
+ module Config
4
+ module Client
5
+ ATTRIBUTES = %i[
6
+ endpoint
7
+ api_key
8
+ user_agent
9
+ ].freeze
10
+
11
+ class << self
12
+ include Config::Logger::Accessor
13
+
14
+ attr_accessor(*ATTRIBUTES)
15
+
16
+ def reset!
17
+ self.endpoint = 'https://pro-api.coinmarketcap.com/v1'
18
+ self.api_key = ENV['COINMARKETCAP_API_KEY']
19
+ self.user_agent = "CoinMarketCap Ruby Client/#{CoinMarketCap::VERSION}"
20
+ end
21
+ end
22
+
23
+ module Accessor
24
+ def configure
25
+ block_given? ? yield(Config::Client) : Config::Client
26
+ end
27
+
28
+ def config
29
+ Config::Client
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ CoinMarketCap::Api::Config::Client.reset!
@@ -0,0 +1,35 @@
1
+ module CoinMarketCap
2
+ module Api
3
+ module Config
4
+ module Logger
5
+ ATTRIBUTES = %i[
6
+ instance
7
+ options
8
+ proc
9
+ ].freeze
10
+
11
+ class << self
12
+ attr_accessor(*ATTRIBUTES)
13
+
14
+ def reset!
15
+ self.instance = nil
16
+ self.options = {}
17
+ self.proc = nil
18
+ end
19
+ end
20
+
21
+ module Accessor
22
+ def logger
23
+ block_given? ? yield(Config::Logger) : Config::Logger
24
+ end
25
+
26
+ def logger=(instance)
27
+ logger.instance = instance
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ CoinMarketCap::Api::Config::Logger.reset!
@@ -0,0 +1,5 @@
1
+ require_relative 'endpoints/cryptocurrency'
2
+
3
+ require_relative 'api/config/logger'
4
+ require_relative 'api/config/client'
5
+ require_relative 'api/client'
@@ -0,0 +1,36 @@
1
+ module CoinMarketCap
2
+ module Cloud
3
+ module Connection
4
+ private
5
+
6
+ def headers
7
+ {}
8
+ end
9
+
10
+ def connection
11
+ @connection ||= begin
12
+ options = {}
13
+
14
+ options[:headers] = {}
15
+ options[:headers]['Accept'] = 'application/json; charset=utf-8'
16
+ options[:headers]['Content-Type'] = 'application/json; charset=utf-8'
17
+ options[:headers]['User-Agent'] = user_agent if user_agent
18
+ options[:headers]['X-CMC_PRO_API_KEY'] = api_key || ''
19
+
20
+ request_options = {}
21
+ request_options[:params_encoder] = Faraday::FlatParamsEncoder
22
+ options[:request] = request_options if request_options.any?
23
+
24
+ ::Faraday::Connection.new(endpoint, options) do |connection|
25
+ connection.use ::Faraday::Request::Multipart
26
+ connection.use ::Faraday::Request::UrlEncoded
27
+ connection.use ::CoinMarketCap::Cloud::Response::RaiseError
28
+ connection.use ::FaradayMiddleware::ParseJson, content_type: /\bjson$/
29
+ connection.response(:logger, logger.instance, logger.options, &logger.proc) if logger.instance
30
+ connection.adapter ::Faraday.default_adapter
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,38 @@
1
+ module CoinMarketCap
2
+ module Cloud
3
+ module Request
4
+ def get(path, options = {})
5
+ request(:get, path, options)
6
+ end
7
+
8
+ def post(path, options = {})
9
+ request(:post, path, options)
10
+ end
11
+
12
+ def put(path, options = {})
13
+ request(:put, path, options)
14
+ end
15
+
16
+ def delete(path, options = {})
17
+ request(:delete, path, options)
18
+ end
19
+
20
+ private
21
+
22
+ def request(method, path, options)
23
+ path = [endpoint, path].join('/')
24
+ response = connection.send(method) do |request|
25
+ case method
26
+ when :get, :delete
27
+ request.url(path, options)
28
+ when :post, :put
29
+ request.path = path
30
+ request.body = options.to_json unless options.empty?
31
+ end
32
+ request.options.merge!(options.delete(:request)) if options.key?(:request)
33
+ end
34
+ response.body
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,20 @@
1
+ module CoinMarketCap
2
+ module Cloud
3
+ module Response
4
+ class RaiseError < ::Faraday::Response::RaiseError
5
+ def on_complete(env)
6
+ case env[:status]
7
+ when 404
8
+ raise Faraday::ResourceNotFound, response_values(env)
9
+ when 401, 403
10
+ raise CoinMarketCap::Errors::PermissionDeniedError, response_values(env)
11
+ when ClientErrorStatuses
12
+ raise CoinMarketCap::Errors::ClientError, response_values(env)
13
+ else
14
+ super
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ require_relative 'cloud/connection'
2
+ require_relative 'cloud/request'
3
+ require_relative 'cloud/response'
@@ -0,0 +1,10 @@
1
+ module CoinMarketCap
2
+ module Endpoints
3
+ module Cryptocurrency
4
+ def map(options = {})
5
+ response = get('cryptocurrency/map', {}.merge(options))
6
+ response['data'].map { |row| CoinMarketCap::Resources::Cryptocurrency.new(row) }
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,24 @@
1
+ module CoinMarketCap
2
+ module Errors
3
+ class ClientError < StandardError
4
+ attr_reader :response
5
+
6
+ def initialize(response)
7
+ @response = response
8
+ super error
9
+ end
10
+
11
+ def error
12
+ if body.is_a?(Hash) && body.key?('error')
13
+ body['error']
14
+ else
15
+ body
16
+ end
17
+ end
18
+
19
+ def body
20
+ response[:body]
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ module CoinMarketCap
2
+ module Errors
3
+ class PermissionDeniedError < ClientError; end
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require_relative 'errors/client_error'
2
+ require_relative 'errors/permission_denied_error'
@@ -0,0 +1,18 @@
1
+ module CoinMarketCap
2
+ module Resources
3
+ class Cryptocurrency < Resource
4
+ property 'id'
5
+ property 'name'
6
+ property 'symbol'
7
+ property 'rank'
8
+ property 'slug'
9
+ property 'is_active'
10
+ property 'status'
11
+ property 'first_historical_data', transform_with: ->(v) { iso8601_date(v) }
12
+ property 'last_historical_data', transform_with: ->(v) { iso8601_date(v) }
13
+ property 'platform', transform_with: lambda { |v|
14
+ CoinMarketCap::Resources::Platform.new(v) unless v.nil?
15
+ }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ module CoinMarketCap
2
+ module Resources
3
+ class Platform < Resource
4
+ property 'id'
5
+ property 'name'
6
+ property 'symbol'
7
+ property 'slug'
8
+ property 'token_address'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ require 'date'
2
+
3
+ module CoinMarketCap
4
+ module Resources
5
+ class Resource < Hashie::Trash
6
+ include Hashie::Extensions::IgnoreUndeclared
7
+
8
+ def self.iso8601_date(timestamp)
9
+ Date.iso8601(timestamp)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ require_relative 'resources/resource'
2
+
3
+ require_relative 'resources/platform'
4
+ require_relative 'resources/cryptocurrency'
@@ -0,0 +1,3 @@
1
+ module CoinMarketCap
2
+ VERSION = '1.0.0'.freeze
3
+ end
@@ -0,0 +1,10 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'hashie'
4
+ require 'faraday_middleware/response_middleware'
5
+
6
+ require_relative 'coinmarketcap/version'
7
+ require_relative 'coinmarketcap/cloud'
8
+ require_relative 'coinmarketcap/errors'
9
+ require_relative 'coinmarketcap/resources'
10
+ require_relative 'coinmarketcap/api'
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coinmarketcap-ruby-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mathusan Selvarajah
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-10-06 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: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hashie
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: mocha
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.13'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.13'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.72.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.72.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '6.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '6.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.14'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.14'
111
+ description: An actively maintined Ruby Client for CoinMarketCap API
112
+ email:
113
+ - mathusans52@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".rubocop.yml"
119
+ - CHANGELOG.md
120
+ - CODE_OF_CONDUCT.md
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - coinmarketcap-ruby-client.gemspec
129
+ - lib/coinmarketcap.rb
130
+ - lib/coinmarketcap/api.rb
131
+ - lib/coinmarketcap/api/client.rb
132
+ - lib/coinmarketcap/api/config/client.rb
133
+ - lib/coinmarketcap/api/config/logger.rb
134
+ - lib/coinmarketcap/cloud.rb
135
+ - lib/coinmarketcap/cloud/connection.rb
136
+ - lib/coinmarketcap/cloud/request.rb
137
+ - lib/coinmarketcap/cloud/response.rb
138
+ - lib/coinmarketcap/endpoints/cryptocurrency.rb
139
+ - lib/coinmarketcap/errors.rb
140
+ - lib/coinmarketcap/errors/client_error.rb
141
+ - lib/coinmarketcap/errors/permission_denied_error.rb
142
+ - lib/coinmarketcap/resources.rb
143
+ - lib/coinmarketcap/resources/cryptocurrency.rb
144
+ - lib/coinmarketcap/resources/platform.rb
145
+ - lib/coinmarketcap/resources/resource.rb
146
+ - lib/coinmarketcap/version.rb
147
+ homepage: https://github.com/koffeefinance/coinmarketcap-ruby-client
148
+ licenses:
149
+ - MIT
150
+ metadata:
151
+ allowed_push_host: https://rubygems.org
152
+ homepage_uri: https://github.com/koffeefinance/coinmarketcap-ruby-client
153
+ source_code_uri: https://github.com/koffeefinance/coinmarketcap-ruby-client
154
+ changelog_uri: https://github.com/koffeefinance/coinmarketcap-ruby-client/CHANGELOG.md
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: 2.3.0
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubygems_version: 3.1.4
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: CoinMarketCap API Ruby client.
174
+ test_files: []