Class: SantanderChile::ApiClient::Client::Connection
- Inherits:
-
Object
- Object
- SantanderChile::ApiClient::Client::Connection
- Defined in:
- lib/santander_chile/api_client/client/connection.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#host ⇒ Object
Returns the value of attribute host.
Instance Method Summary collapse
- #faraday(login) ⇒ Object
-
#initialize(client:, host:) ⇒ Connection
constructor
A new instance of Connection.
- #post(path, body:, headers: {}, login: false) ⇒ Object
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
#client ⇒ Object
Returns the value of attribute client.
10 11 12 |
# File 'lib/santander_chile/api_client/client/connection.rb', line 10 def client @client end |
#host ⇒ Object
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(login) Faraday.new(url: host) do |config| config.request :url_encoded if login 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: login).post(path, body, headers) do |request| if !login request.headers = { "access-token" => @client.token.tokenJWT }.merge(headers) end end end |