Sha256: 3babb28f51952b7d757bc9a00942b120c91d753c5572850e5b452e10d4438561

Contents?: true

Size: 1.35 KB

Versions: 23

Compression:

Stored size: 1.35 KB

Contents

require 'faraday_middleware/parse_oj'

module AvaTax

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

    def connection
      client_id = "#{app_name};#{app_version};RubySdk;#{AvaTax::VERSION.dup};#{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 :oj, 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

23 entries across 23 versions & 1 rubygems

Version Path
avatax-20.1.0 lib/avatax/connection.rb
avatax-19.12.1 lib/avatax/connection.rb
avatax-19.12.0 lib/avatax/connection.rb
avatax-19.11.1 lib/avatax/connection.rb
avatax-19.10.0 lib/avatax/connection.rb
avatax-19.9.1 lib/avatax/connection.rb
avatax-19.9.0 lib/avatax/connection.rb
avatax-19.8.0 lib/avatax/connection.rb
avatax-19.7.0 lib/avatax/connection.rb
avatax-19.6.0 lib/avatax/connection.rb
avatax-19.5.0 lib/avatax/connection.rb
avatax-19.4.0 lib/avatax/connection.rb
avatax-19.3.0 lib/avatax/connection.rb
avatax-19.2.0 lib/avatax/connection.rb
avatax-19.1.1 lib/avatax/connection.rb
avatax-18.12.0 lib/avatax/connection.rb
avatax-18.10.4 lib/avatax/connection.rb
avatax-18.10.3 lib/avatax/connection.rb
avatax-18.9.0 lib/avatax/connection.rb
avatax-18.7.1 lib/avatax/connection.rb