module Shopkit::Request

Public Instance Methods

delete(path, options={}, version=api_version) click to toggle source
# File lib/shopkit/request.rb, line 3
def delete(path, options={}, version=api_version)
  request(:delete, path, options, version)
end
get(path, options={}, version=api_version) click to toggle source
# File lib/shopkit/request.rb, line 7
def get(path, options={}, version=api_version)
  request(:get, path, options, version)
end
post(path, options={}, version=api_version) click to toggle source
# File lib/shopkit/request.rb, line 11
def post(path, options={}, version=api_version)
  request(:post, path, options, version)
end
put(path, options={}, version=api_version) click to toggle source
# File lib/shopkit/request.rb, line 15
def put(path, options={}, version=api_version)
  request(:put, path, options, version)
end

Private Instance Methods

request(method, path, options, version) click to toggle source
# File lib/shopkit/request.rb, line 21
def request(method, path, options, version)
  path = "/api#{path}" unless path.start_with?('/api')
  path = "#{path}.json" unless path.end_with?('.json')
  response = connection.send(method) do |request|
    case method
    when :delete, :get
      request.url(path, options)
    when :post, :put
      request.path = path
      request.body = options unless options.empty?
    end
  end


  response.body
end