Class: OEXRWrapper::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/oexrwrapper/client.rb

Constant Summary collapse

BASE_URL =
"https://openexchangerates.org/api/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_id:, base_rate_code: "USD") ⇒ Client

Returns a new instance of Client.



10
11
12
13
# File 'lib/oexrwrapper/client.rb', line 10

def initialize(app_id:, base_rate_code: "USD")
  @app_id = app_id
  @base_rate_code = base_rate_code
end

Instance Attribute Details

#app_idObject (readonly)

Returns the value of attribute app_id.



8
9
10
# File 'lib/oexrwrapper/client.rb', line 8

def app_id
  @app_id
end

#base_rate_codeObject (readonly)

Returns the value of attribute base_rate_code.



8
9
10
# File 'lib/oexrwrapper/client.rb', line 8

def base_rate_code
  @base_rate_code
end

Instance Method Details

#connectionObject



23
24
25
26
27
28
29
30
31
# File 'lib/oexrwrapper/client.rb', line 23

def connection
  @connection = Faraday.new do |conn|
    conn.url_prefix = BASE_URL
    conn.request :json
    conn.response :json, content_type: "application/json"
    conn.params["app_id"] = @app_id
    conn.params["base"] = @base_rate_code.upcase
  end
end

#currenciesObject



19
20
21
# File 'lib/oexrwrapper/client.rb', line 19

def currencies
  CurrenciesResources.new self
end

#latestObject



15
16
17
# File 'lib/oexrwrapper/client.rb', line 15

def latest
  LatestResource.new self
end