Sha256: 8cfdae6d51aea026d952a2aebd93344a881cdd3f19cff10e5f461560aa9f495e

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

require 'faraday'
require 'json'

module AvaTax
  module Request

    def get(path, options={})
      request(:get, path, nil, options)
    end

    def post(path, model, options={})
      request(:post, path, model, options)
    end

    def put(path, model, options={})
      request(:put, path, model, options)
    end

    def delete(path, options={})
      request(:delete, path, nil, options)
    end

    def request(method, path, model, options={})
      response = connection.send(method) do |request|
        # timeout in seconds
        request.options['timeout'] = 1200
        case method
        when :get, :delete
          request.url("#{URI.encode(path)}?#{URI.encode_www_form(options)}")
        when :post, :put
          request.url("#{URI.encode(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
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
avatax-20.12.1 lib/avatax/request.rb
avatax-20.9.0 lib/avatax/request.rb
avatax-20.7.1 lib/avatax/request.rb
avatax-20.7.0 lib/avatax/request.rb
avatax-20.6.0 lib/avatax/request.rb
avatax-20.5.0 lib/avatax/request.rb