Module: CoinMarketCap
- Extended by:
- Configuration
- Defined in:
- lib/coinmarketcap_api.rb,
lib/coinmarketcap_api/version.rb,
lib/coinmarketcap_api/configuration.rb
Defined Under Namespace
Modules: Configuration
Constant Summary collapse
- VERSION =
'1.0.0'.freeze
Constants included from Configuration
Configuration::DEFAULT_API_ENDPOINT
Instance Attribute Summary
Attributes included from Configuration
Class Method Summary collapse
-
.connection ⇒ Object
Build or get an HTTP connection object.
-
.connection=(connection) ⇒ Object
Set an HTTP connection object.
-
.request(type: 'ticker', options: {}) ⇒ Array, Hash
Retrieve the request for a given type and options.
Methods included from Configuration
Class Method Details
.connection ⇒ Object
Build or get an HTTP connection object.
42 43 44 |
# File 'lib/coinmarketcap_api.rb', line 42 def connection @connection ||= Faraday.new(request: { timeout: CoinMarketCap.timeout }) end |
.connection=(connection) ⇒ Object
Set an HTTP connection object.
49 50 51 |
# File 'lib/coinmarketcap_api.rb', line 49 def connection=(connection) @connection = connection end |
.request(type: 'ticker', options: {}) ⇒ Array, Hash
Retrieve the request for a given type and options.
Can be either ‘ticker` or `global`. Valid options are `:currency`, `:start`, `:limit` and `:convert`.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/coinmarketcap_api.rb', line 21 def request(type: 'ticker', options: {}) request_response = get(request_url(, type), [:params]) if request_response.success? # Rename api properties due to ruby restrictions. dictionary = { '1h' => 'hourly', '24h' => 'daily', '7d' => 'weekly' } dictionary.each { |k, v| request_response.body.gsub!(k, v) } result = MultiJson.load(request_response.body) if multiple_responses?(, result, type) return result.map { |hash| Hashie::Mash.new(hash) } end result = result.first if result.length == 1 Hashie::Mash.new(result) end end |