Class: OandaRubyClient::RatesRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/oanda_ruby_client/rates_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_currency, query_params = {}) ⇒ RatesRequest

Returns a new instance of RatesRequest.

Parameters:

  • base_currency (String)

    Currency code for the base currency

  • query_params (Hash) (defaults to: {})

    Optional query parameters



12
13
14
# File 'lib/oanda_ruby_client/rates_request.rb', line 12

def initialize(base_currency, query_params = {})
  @base_currency, @query_params = base_currency.to_s.upcase, query_params
end

Instance Attribute Details

#base_currencyObject

Returns the value of attribute base_currency.



8
9
10
# File 'lib/oanda_ruby_client/rates_request.rb', line 8

def base_currency
  @base_currency
end

#query_paramsObject

Returns the value of attribute query_params.



8
9
10
# File 'lib/oanda_ruby_client/rates_request.rb', line 8

def query_params
  @query_params
end

Instance Method Details

#query_stringString

Returns the query string that will be passed to the API.

Returns:

  • (String)

    the query string that will be passed to the API



17
18
19
20
21
22
23
24
25
26
# File 'lib/oanda_ruby_client/rates_request.rb', line 17

def query_string
  [ :date, :start, :end ].each do |date_key|
    if query_params[date_key] && query_params[date_key].is_a?(Date)
      query_params[date_key] = query_params[date_key].iso8601
    end
  end
  uri = Addressable::URI.new
  uri.query_values = query_params
  uri.query
end