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.



11
12
13
# File 'lib/bank_exchange_api/connection.rb', line 11

def initialize(cli)
  @cli = cli
end

Instance Attribute Details

#cliObject (readonly)

Returns the value of attribute cli.



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

def cli
  @cli
end

Instance Method Details

#get(uri) ⇒ Object



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

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



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

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

#transportObject



15
16
17
# File 'lib/bank_exchange_api/connection.rb', line 15

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