Class: SantanderChile::ApiClient::Client::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/santander_chile/api_client/client/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, host:) ⇒ Connection

Returns a new instance of Connection.



5
6
7
8
# File 'lib/santander_chile/api_client/client/connection.rb', line 5

def initialize(client:, host:)
  @client = client
  @host = host
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



10
11
12
# File 'lib/santander_chile/api_client/client/connection.rb', line 10

def client
  @client
end

#hostObject

Returns the value of attribute host.



10
11
12
# File 'lib/santander_chile/api_client/client/connection.rb', line 10

def host
  @host
end

Instance Method Details

#faraday(login) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/santander_chile/api_client/client/connection.rb', line 20

def faraday()
  Faraday.new(url: host) do |config|
    config.request :url_encoded if 
    config.request :oauth2, client.token.access_token, token_type: :bearer if client.token # TODO check token timeout
    config.request :json
    config.response :raise_error
    config.response :json, content_type: "application/json"
    client.config.faraday.call(config)
    config.adapter Faraday.default_adapter
  end
end

#post(path, body:, headers: {}, login: false) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/santander_chile/api_client/client/connection.rb', line 12

def post(path, body:, headers: {}, login: false)
  response = faraday(login: ).post(path, body, headers) do |request|
    if !
      request.headers = { "access-token" => @client.token.tokenJWT }.merge(headers)
    end
  end
end