Class: NubankSdk::Client::HTTP

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

Overview

create a new connection with the given url in Faraday

Instance Method Summary collapse

Constructor Details

#initialize(base_url, connection_adapter = nil) ⇒ HTTP

create a new connection with the given url in Faraday

Parameters:

  • base_url (String)
  • connection_adapter ([Symbol, Faraday::Adapter::Test::Stubs]) (defaults to: nil)


30
31
32
33
34
35
# File 'lib/nubank_sdk/client.rb', line 30

def initialize(base_url, connection_adapter = nil)
  @connection = Faraday.new(url: base_url) do |faraday|
    faraday.adapter(*connection_adapter) if connection_adapter
    faraday.adapter Faraday.default_adapter unless connection_adapter
  end
end

Instance Method Details

#get(path) ⇒ Faraday::Response

make get on connection with the given path

Parameters:

  • path (String)

Returns:

  • (Faraday::Response)


58
59
60
# File 'lib/nubank_sdk/client.rb', line 58

def get(path)
  @connection.get(path)
end

#post(path, body) ⇒ Faraday::Response

make put on connection with the given path

Parameters:

  • path (String)
  • body (Hash)

Returns:

  • (Faraday::Response)


44
45
46
47
48
49
50
# File 'lib/nubank_sdk/client.rb', line 44

def post(path, body)
  @connection.post(path) do |req|
    req.headers['Content-Type'] = 'application/json'
    req.headers['X-Correlation-Id'] = 'WEB-APP.pewW9'
    req.body = body.to_json
  end
end