Class: CcyConvertor::CurrencyLayer

Inherits:
RateProvider show all
Defined in:
lib/ccy_convertor/rate_providers/currency_layer.rb

Instance Attribute Summary

Attributes included from RateCache

#cache_duration

Class Method Summary collapse

Methods inherited from RateProvider

api_key_nil?, convert, rate_from_rate_matrix, rate_matrix_response, rate_provider_name, rate_response, response_hash

Methods included from RateCache

#cache, #cache_duration_nil?, #cache_key

Methods included from ProcessAndValidateOption

#validate_amount!, #validate_currency_codes!, #validate_currency_support!, #validate_options!, #validate_presence_of_hash_keys!

Class Method Details

.rate_matrix(base_ccy = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/ccy_convertor/rate_providers/currency_layer.rb', line 8

def rate_matrix(base_ccy = nil)
  rate_matrix_response = rate_matrix_response(base_ccy)
  if error = rate_matrix_response['error']
    raise CcyConvertor::ResponseInvalid, error['info']
  end
  rate_matrix_response['quotes'].inject({}) do |acc, (k, v)|
    acc[k[3, 3]] = v; acc
  end
end

.rest_url_for_rate_matrix(base_ccy) ⇒ Object



4
5
6
# File 'lib/ccy_convertor/rate_providers/currency_layer.rb', line 4

def rest_url_for_rate_matrix(base_ccy)
  "http://apilayer.net/api/live?access_key=#{api_key}&source=#{base_ccy || 'USD'}&format=1"
end