Class: ForexRates::Forex

Inherits:
Object
  • Object
show all
Defined in:
lib/forex_rates/forex.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*cache_opts) ⇒ Forex

Returns a new instance of Forex.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/forex_rates/forex.rb', line 10

def initialize(*cache_opts)
    if cache_opts[0] && cache_opts[0].size > 0
        @api = Api.new do |builder|
             builder.use :http_cache, cache_opts[0]
             builder.adapter Faraday.default_adapter
        end
    else
        @api = Api.new
    end

end

Instance Attribute Details

#apiObject

Returns the value of attribute api.



8
9
10
# File 'lib/forex_rates/forex.rb', line 8

def api
  @api
end

Instance Method Details

#get_for_a_day(date, *opts) ⇒ Object



33
34
35
36
37
# File 'lib/forex_rates/forex.rb', line 33

def get_for_a_day(date, *opts)
    raise ForexRatesError.new "Date is not correct" unless verify_date(date)
    resp = api.get_for_a_day(date,opts)
    JSON.parse resp.body
end

#get_historical(start_date, end_date, *opts) ⇒ Object



27
28
29
30
31
# File 'lib/forex_rates/forex.rb', line 27

def get_historical(start_date, end_date, *opts)
    raise ForexRatesError.new "Date is not correct" unless verify_date(start_date) && verify_date(end_date)
    resp = api.get_history(start_date, end_date, opts)
    JSON.parse resp.body
end

#get_latest(*opts) ⇒ Object



22
23
24
25
# File 'lib/forex_rates/forex.rb', line 22

def get_latest(*opts)
    resp = api.get_latest(opts)
    JSON.parse resp.body
end