Class: OXR::Configuration

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

Constant Summary collapse

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

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

#currenciesObject



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

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

#historical(date) ⇒ Object



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

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

#latestObject



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

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

#usageObject



28
29
30
31
32
# File 'lib/oxr/configuration.rb', line 28

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

Instance Method Details

#reset_sourcesObject



34
35
36
37
38
39
# File 'lib/oxr/configuration.rb', line 34

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