Sha256: 50257369d9529ec033876ebd28c8dc70a3770f2362fb3ac8b86e208cde16d5f0

Contents?: true

Size: 817 Bytes

Versions: 2

Compression:

Stored size: 817 Bytes

Contents

require 'hashie'

module AvaTax
  module Request

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

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

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

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

    def request(method, path, options)
      response = connection.send(method) do |request|
        case method
        when :get, :delete
          request.url(URI.encode(path), options)
        when :post, :put
          request.path = URI.encode(path)
          request.headers['Content-Type'] = 'application/json'
          request.body = options.to_json unless options.empty?
        end
      end

      ::Hashie::Mash.new response.body
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
avatax-17.8.1 lib/avatax/request.rb
avatax-17.7.3 lib/avatax/request.rb