Class: NubankSdk::Client::HTTP

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

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)


22
23
24
25
26
27
# File 'lib/nubank_sdk/client.rb', line 22

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)


49
50
51
# File 'lib/nubank_sdk/client.rb', line 49

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)


36
37
38
39
40
41
# File 'lib/nubank_sdk/client.rb', line 36

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