Class: Fixer::Client::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/fixer/client/http_client.rb

Constant Summary collapse

BASE_URI =
"http://data.fixer.io/api".freeze
SCOPES =
[
  :latest,
   :historical
].freeze
CONFIG_FILE =
"config/fixerio_client.yml".freeze

Instance Method Summary collapse

Constructor Details

#initialize(scope = :latest) ⇒ HttpClient

Returns a new instance of HttpClient.

Raises:

  • (::ArgumentError)


19
20
21
22
23
24
# File 'lib/fixer/client/http_client.rb', line 19

def initialize(scope = :latest)
   raise ::ArgumentError.new unless SCOPES.include?(scope)
   @scope = scope
   @config = read_config
   @api_key = get_api_key
end

Instance Method Details

#fetch(symbols = [], date = nil) ⇒ Object

Raises:

  • (::ArgumentError)


26
27
28
29
30
31
# File 'lib/fixer/client/http_client.rb', line 26

def fetch(symbols = [], date = nil)
   raise ::ArgumentError.new("You cannot put date argument for 'latest' mode client") if @scope == :latest && !date.nil? && !date.empty?
   response_hash = hash(symbols)
   raise Fixer::Client::Errors::InvalidResponse.new("Response: #{response_hash}") if response_hash["success"].to_s != "true"
   response_hash
end