Class: OandaRubyClient::ExchangeRatesClient
- Inherits:
-
Object
- Object
- OandaRubyClient::ExchangeRatesClient
- Defined in:
- lib/oanda_ruby_client/exchange_rates_client.rb
Instance Method Summary collapse
-
#currencies ⇒ Hash<String, String>
A hash of the supported currency codes to their descriptions.
-
#initialize(api_key = ENV['OANDA_RUBY_CLIENT_API_KEY'], use_ssl = true) ⇒ ExchangeRatesClient
constructor
A new instance of ExchangeRatesClient.
-
#rates(rates_request) ⇒ OpenStruct
Returns the exchanges rates based on the specified request.
-
#remaining_quotes ⇒ Fixnum, 'unlimited'
Returns the number of remaining quote requests.
Constructor Details
#initialize(api_key = ENV['OANDA_RUBY_CLIENT_API_KEY'], use_ssl = true) ⇒ ExchangeRatesClient
Returns a new instance of ExchangeRatesClient.
11 12 13 |
# File 'lib/oanda_ruby_client/exchange_rates_client.rb', line 11 def initialize(api_key = ENV['OANDA_RUBY_CLIENT_API_KEY'], use_ssl = true) @api_key, @use_ssl = api_key, use_ssl end |
Instance Method Details
#currencies ⇒ Hash<String, String>
Returns a hash of the supported currency codes to their descriptions.
16 17 18 19 20 21 22 23 24 |
# File 'lib/oanda_ruby_client/exchange_rates_client.rb', line 16 def currencies currencies_response = HTTParty.get("#{oanda_endpoint}#{CURRENCIES_PATH}", headers: oanda_headers) handle_response(currencies_response.response) result = {} currencies_response.parsed_response['currencies'].each do |currency| result[currency['code']] = currency['description'] end result end |
#rates(rates_request) ⇒ OpenStruct
Returns the exchanges rates based on the specified request
30 31 32 33 34 35 |
# File 'lib/oanda_ruby_client/exchange_rates_client.rb', line 30 def rates(rates_request) rates_uri = "#{oanda_endpoint}#{RATES_BASE_PATH}#{rates_request.base_currency}.json?#{rates_request.query_string}" rates_response = HTTParty.get(rates_uri, headers: oanda_headers) handle_response(rates_response.response) OpenStruct.new(rates_response.parsed_response) end |
#remaining_quotes ⇒ Fixnum, 'unlimited'
Returns the number of remaining quote requests
40 41 42 43 44 |
# File 'lib/oanda_ruby_client/exchange_rates_client.rb', line 40 def remaining_quotes remaining_quotes_response = HTTParty.get("#{oanda_endpoint}#{REMAINING_QUOTES_PATH}", headers: oanda_headers) handle_response(remaining_quotes_response.response) remaining_quotes_response.parsed_response['remaining_quotes'] end |