Class: BankExchangeApi::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/bank_exchange_api/connection.rb

Constant Summary collapse

HOST =
'api.bank.exchange'.freeze
PORT =
80.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cli) ⇒ Connection

Returns a new instance of Connection.



9
10
11
# File 'lib/bank_exchange_api/connection.rb', line 9

def initialize(cli)
  @cli = cli
end

Instance Attribute Details

#cliObject (readonly)

Returns the value of attribute cli.



7
8
9
# File 'lib/bank_exchange_api/connection.rb', line 7

def cli
  @cli
end

Instance Method Details

#get(uri) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/bank_exchange_api/connection.rb', line 26

def get(uri)
  bm :GET, uri do
    transport.get(uri, headers).tap do |http|
      error(uri, http) unless http.is_a?(Net::HTTPOK)
    end
  end
end

#headersObject



17
18
19
20
21
22
23
24
# File 'lib/bank_exchange_api/connection.rb', line 17

def headers
  {
      'Accept' => 'application/json',
      'X-Api-Token' => cli.config.api_token!,
      'X-Client' => 'bank_exchange_ruby_api',
      'X-Client-Version' => VERSION
  }
end

#transportObject



13
14
15
# File 'lib/bank_exchange_api/connection.rb', line 13

def transport
  @transport ||= Net::HTTP.new(HOST, PORT)
end