Sha256: ea880397f6b2c7e15816a57dde35de54f9f3ce9c2fbf43a529be248fe2e93aeb

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

module Avatax
  module RequestDecorator
    include ::SpreeAvataxOfficial::HttpHelper

    def request(method, path, model, options = {})
      max_retries                  ||= ::SpreeAvataxOfficial::Config.max_retries
      uri_encoded_path               = URI.parse(path).to_s
      response                       = connection.send(method) do |request|
        request.options['timeout'] ||= 1_200
        case method
        when :get, :delete
          request.url("#{uri_encoded_path}?#{URI.encode_www_form(options)}")
        when :post, :put
          request.url("#{uri_encoded_path}?#{URI.encode_www_form(options)}")
          request.headers['Content-Type'] = 'application/json'
          request.body                    = model.to_json unless model.empty?
        end
      end

      if faraday_response
        response
      else
        response.body
      end
    rescue *::SpreeAvataxOfficial::HttpHelper::CONNECTION_ERRORS => e
      retry unless (max_retries -= 1).zero?

      mock_error_response(e) # SpreeAvataxOfficial::HttpHelper method
    end
  end
end

# This is correct class to prepend because of: https://github.com/avadev/AvaTax-REST-V2-Ruby-SDK/blob/eb7c20b8e925a3d682f6414207e298e519e0a549/lib/avatax/api.rb#L25
::AvaTax::API.prepend ::Avatax::RequestDecorator

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spree_avatax_official-1.8.0 app/models/avatax/request_decorator.rb
spree_avatax_official-1.7.1 app/models/avatax/request_decorator.rb