Sha256: c2fff3a237b67d2877c1c134198ed7274a389ba67807f472d54b770451c604ae

Contents?: true

Size: 1.99 KB

Versions: 10

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: true

require "faraday"

module BeyondApi
  class Connection
    LOGGER = ::BeyondApi.logger
    LOGGER.level = Kernel.const_get("::Logger::#{BeyondApi.configuration.log_level.to_s.upcase}")

    def self.default
      Faraday.new(ssl: { verify: true }) do |faraday|
        faraday.options[:open_timeout] = BeyondApi.configuration.open_timeout.to_i
        faraday.options[:timeout] = BeyondApi.configuration.timeout.to_i
        faraday.response :logger, LOGGER, { headers: BeyondApi.configuration.log_headers,
                                            bodies: BeyondApi.configuration.log_bodies }
        faraday.headers["Accept"] = "application/json"
        faraday.headers["Content-Type"] = "application/json"
        faraday.request(:multipart)
        faraday.request(:url_encoded)
        faraday.adapter(:net_http)
      end
    end

    def self.token
      Faraday.new(ssl: { verify: true }) do |faraday|
        faraday.options[:open_timeout] = BeyondApi.configuration.open_timeout.to_i
        faraday.options[:timeout] = BeyondApi.configuration.timeout.to_i
        faraday.response :logger, LOGGER, { headers: BeyondApi.configuration.log_headers,
                                            bodies: BeyondApi.configuration.log_bodies } do |logger|
          logger.filter(/(code=)([a-zA-Z0-9]+)/, '\1[FILTERED]')
          logger.filter(/(refresh_token=)([a-zA-Z0-9.\-\_]+)/, '\1[FILTERED]')
        end
        faraday.headers['Accept'] = 'application/json'
        faraday.adapter(:net_http)
        faraday.request :basic_auth, BeyondApi.configuration.client_id, BeyondApi.configuration.client_secret
      end
    end

    def self.multipart
      Faraday.new(ssl: { verify: true }) do |faraday|
        faraday.options[:open_timeout] = BeyondApi.configuration.open_timeout.to_i
        faraday.options[:timeout] = BeyondApi.configuration.timeout.to_i
        faraday.request :multipart, { flat_encode: true }
        faraday.adapter Faraday.default_adapter
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
beyond_api-0.24.2.pre lib/beyond_api/connection.rb
beyond_api-0.24.1.pre lib/beyond_api/connection.rb
beyond_api-0.24.0.pre lib/beyond_api/connection.rb
beyond_api-0.23.0.pre lib/beyond_api/connection.rb
beyond_api-0.22.2.pre lib/beyond_api/connection.rb
beyond_api-0.22.1.pre lib/beyond_api/connection.rb
beyond_api-0.22.0.pre lib/beyond_api/connection.rb
beyond_api-0.21.0.pre lib/beyond_api/connection.rb
beyond_api-0.20.0.pre lib/beyond_api/connection.rb
beyond_api-0.19.0.pre lib/beyond_api/connection.rb