Sha256: 59d724cd0db5fa189ff9e84cab74ff0af409cd770d97721247e014a0fbc6d841

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

module SantanderChile
  module ApiClient
    class Client
      class Connection
        def initialize(client:, host:)
          @client = client
          @host = host
        end

        attr_accessor :client, :host

        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

        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
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
santander_chile-api_client-1.1.1 lib/santander_chile/api_client/client/connection.rb
santander_chile-api_client-1.1.0 lib/santander_chile/api_client/client/connection.rb