Class: CTFC::API::ApiTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/ctfc/api/apitemplate.rb

Overview

Template for other sources. Every file in api dir should extend this class. Automatically call method #process to send api request after initialization. This mean every source should include method #process, that will be executed after initialization.

Direct Known Subclasses

Cryptocompare

Constant Summary collapse

MAX_RETRY =

max number of requests to send

3

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fiat, coins) ⇒ Object

Construct response hash from given arguments, and start counting requests. Call private method #process to extract data from web.

Examples:

Send request to cryptocompare

crypto = Cryptocompare.new :eur, %w[BTC XMR]

Parameters:

  • fiat (Symbol)

    *Required*. Fiat currency to use for conversion.

  • coins (Array)

    *Required*. Array of coins to extract data.



33
34
35
36
37
# File 'lib/ctfc/api/apitemplate.rb', line 33

def initialize(fiat, coins)
  @response = { fiat: fiat, coins: coins, success: false }
  @counter  = 0
  process
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



17
18
19
# File 'lib/ctfc/api/apitemplate.rb', line 17

def response
  @response
end

Class Method Details

.[](fiat, coins) ⇒ Hash

Initialize new instance, send request and return response hash.

Examples:

Cryptocompare[:eur, %w[BTC XMR]]

Parameters:

  • fiat (Symbol)

    *Required*. Fiat currency.

  • coins (Array)

    *Required*. Cryptocurrency coins.

Returns:

  • (Hash)

    Response hash object.



48
49
50
# File 'lib/ctfc/api/apitemplate.rb', line 48

def self.[](fiat, coins)
  new(fiat, coins).response
end