Sha256: 9101475ed35a74e7395e58a73fc72dac089aa2bffdac2e0b1aea54d3eef6c5ea

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

require 'faraday_middleware'

module AvaTax

  module Connection
    private
    AUTHORIZATION_FILTER_REGEX = /(Authorization\:\ \"Basic\ )(\w+)\=/
    REMOVED_LABEL = '\1[REMOVED]'

    def connection
      client_id = "#{app_name};#{app_version};RubySdk;API_VERSION;#{machine_name}"
      options = {
        :headers =>
          {
           'Accept' => "application/json; charset=utf-8",
           'User-Agent' => user_agent,
           'X-Avalara-Client' => client_id
          },
        :url => endpoint,
        :proxy => proxy
      }.merge(connection_options)

      Faraday.new(options) do |faraday|
        if Gem::Version.new(RUBY_VERSION) > Gem::Version.new('2.2.2') and response_big_decimal_conversion
          Oj.default_options = {
            bigdecimal_load: :bigdecimal
          }
        end

        faraday.response :json, content_type: /\bjson$/
        faraday.basic_auth(username, password)

        if logger
          faraday.response :logger do |logger|
            logger.filter(AUTHORIZATION_FILTER_REGEX, REMOVED_LABEL)
          end
        end

        if custom_logger
          faraday.response :logger, custom_logger, custom_logger_options do |logger|
            logger.filter(AUTHORIZATION_FILTER_REGEX, REMOVED_LABEL)
          end
        end

        faraday.adapter Faraday.default_adapter
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
avatax-22.3.0 lib/avatax/connection.rb
avatax-22.2.1 lib/avatax/connection.rb
avatax-22.2.0 lib/avatax/connection.rb