Class: CurrencyConversion::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/currency-conversion/client.rb

Overview

Client

Constant Summary collapse

BASE_URL =

Returns Default API endpoint.

Returns:

  • (String)

    Default API endpoint

'https://api.currencyapi.com'
API_VERSION =

Returns API Version.

Returns:

  • (String)

    API Version

'v3'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, adapter: Faraday.default_adapter) ⇒ Currency::Conversion::Client

Initialize a new client

Parameters:

  • api_key (String)

    API Key

  • adapter (Symbol) (defaults to: Faraday.default_adapter)

    Faraday Adapter



24
25
26
27
# File 'lib/currency-conversion/client.rb', line 24

def initialize(api_key:, adapter: Faraday.default_adapter)
  @api_key = api_key
  @adapter = adapter
end

Instance Attribute Details

#adapterSymbol (readonly)

Returns Gets the Symbol key identifying a default Adapter to use.

Returns:

  • (Symbol)

    Gets the Symbol key identifying a default Adapter to use



16
17
18
# File 'lib/currency-conversion/client.rb', line 16

def adapter
  @adapter
end

#api_keyString (readonly)

Returns API Key.

Returns:

  • (String)

    API Key



13
14
15
# File 'lib/currency-conversion/client.rb', line 13

def api_key
  @api_key
end

Instance Method Details

#connectionFaraday::Connection

Initializes a new Faraday connection

Returns:

  • (Faraday::Connection)


53
54
55
56
57
58
59
# File 'lib/currency-conversion/client.rb', line 53

def connection
  @connection ||= Faraday.new(headers: default_headers) do |conn|
    conn.url_prefix = connection_url
    conn.response :json, content_type: 'application/json'
    conn.adapter adapter
  end
end

#currenciesCurrenciesEndpoint

Currencies Endpoint instance

Returns:



39
40
41
# File 'lib/currency-conversion/client.rb', line 39

def currencies
  CurrenciesEndpoint.new(self)
end

#exchange_ratesExchangeRatesEndpoint

Exchange Rates Endpoint instance



46
47
48
# File 'lib/currency-conversion/client.rb', line 46

def exchange_rates
  ExchangeRatesEndpoint.new(self)
end

#statusStatusEndpoint

Status Endpoint instance

Returns:



32
33
34
# File 'lib/currency-conversion/client.rb', line 32

def status
  StatusEndpoint.new(self)
end