Class: OXR::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/oxr/configuration.rb

Constant Summary collapse

ENDPOINT =
'https://openexchangerates.org/api/'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#app_idObject

Returns the value of attribute app_id.



7
8
9
# File 'lib/oxr/configuration.rb', line 7

def app_id
  @app_id
end

#baseObject

Returns the value of attribute base.



7
8
9
# File 'lib/oxr/configuration.rb', line 7

def base
  @base
end

#currenciesObject



10
11
12
13
14
# File 'lib/oxr/configuration.rb', line 10

def currencies
  @currencies || URI.join(ENDPOINT, 'currencies.json').tap do |uri|
    uri.query = "app_id=#{app_id}"
  end.to_s
end

#historical(date) ⇒ Object



16
17
18
19
20
21
# File 'lib/oxr/configuration.rb', line 16

def historical(date)
  @historical || URI.join(ENDPOINT, "historical/#{date.strftime('%F')}.json").tap do |uri|
    uri.query = "app_id=#{app_id}"
    uri.query += "&base=#{base}" if base
  end.to_s
end

#latestObject



23
24
25
26
27
28
# File 'lib/oxr/configuration.rb', line 23

def latest
  @latest || URI.join(ENDPOINT, 'latest.json').tap do |uri|
    uri.query = "app_id=#{app_id}"
    uri.query += "&base=#{base}" if base
  end.to_s
end

#usageObject



30
31
32
33
34
# File 'lib/oxr/configuration.rb', line 30

def usage
  @usage || URI.join(ENDPOINT, 'usage.json').tap do |uri|
    uri.query = "app_id=#{app_id}"
  end.to_s
end

Instance Method Details

#reset_sourcesObject



36
37
38
39
40
41
# File 'lib/oxr/configuration.rb', line 36

def reset_sources
  @currencies = nil
  @historical = nil
  @latest     = nil
  @usage      = nil
end