module Freshdesk::Request

Public Instance Methods

delete(path, options = {}, body = {}) click to toggle source
# File lib/freshdesk/api/v2/util/request.rb, line 15
def delete(path, options = {}, body = {})
  self.class.delete(prepare_path(path), prepare_options(options, body))
end
get(path, options = {}, body = {}) click to toggle source
# File lib/freshdesk/api/v2/util/request.rb, line 3
def get(path, options = {}, body = {})
  self.class.get(prepare_path(path), prepare_options(options, body))
end
post(path, options = {}, body = {}) click to toggle source
# File lib/freshdesk/api/v2/util/request.rb, line 11
def post(path, options = {}, body = {})
  handle_response self.class.post(prepare_path(path), prepare_options(options, body))
end
put(path, options = {}, body = {}) click to toggle source
# File lib/freshdesk/api/v2/util/request.rb, line 7
def put(path, options = {}, body = {})
  self.class.put(prepare_path(path), prepare_options(options, body))
end

Private Instance Methods

handle_response(response) click to toggle source
# File lib/freshdesk/api/v2/util/request.rb, line 37
def handle_response(response)
  !response.success? and raise UnsuccessfulRequestError, response.inspect
  response
end
prepare_options(options, body) click to toggle source
# File lib/freshdesk/api/v2/util/request.rb, line 20
def prepare_options(options, body)
  if body.empty?
    { :query => options, :basic_auth => credentials }
  else
    {
      :headers => {'content-type' => 'application/json'},
      :query => options,
      :body => body.to_json,
      :basic_auth => credentials
    }
  end
end
prepare_path(path) click to toggle source
# File lib/freshdesk/api/v2/util/request.rb, line 33
def prepare_path(path)
  "https://#{@domain}.freshdesk.com/api/v2/#{path}"
end