Sha256: f8eacad0faf1500b2fa54fcddaf7b936953bea6305c3f21c8d873cb60aea6805

Contents?: true

Size: 964 Bytes

Versions: 6

Compression:

Stored size: 964 Bytes

Contents

require 'hashie'
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|
        case method
        when :get, :delete
          request.url("#{URI.encode(path)}?#{URI.encode_www_form(options)}")
        when :post, :put
          request.path = ("#{URI.encode(path)}?#{URI.encode_www_form(options)}")
          request.headers['Content-Type'] = 'application/json'
          request.body = model.to_json unless model.empty?
        end
      end

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

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
avatax-18.4.0 lib/avatax/request.rb
avatax-18.3.0 lib/avatax/request.rb
avatax-18.2.0 lib/avatax/request.rb
avatax-18.1.2 lib/avatax/request.rb
avatax-17.12.0 lib/avatax/request.rb
avatax-17.9.1 lib/avatax/request.rb