module Genability::Request
Defines HTTP request methods
Public Instance Methods
delete(path, options={}, raw=false, unformatted=false)
click to toggle source
Perform an HTTP DELETE request
# File lib/genability/request.rb, line 20 def delete(path, options={}, raw=false, unformatted=false) request(:delete, path, options, raw, unformatted) end
get(path, options={}, raw=false, unformatted=false)
click to toggle source
Perform an HTTP GET request
# File lib/genability/request.rb, line 5 def get(path, options={}, raw=false, unformatted=false) request(:get, path, options, raw, unformatted) end
post(path, options={}, raw=false, unformatted=false)
click to toggle source
Perform an HTTP POST request
# File lib/genability/request.rb, line 10 def post(path, options={}, raw=false, unformatted=false) request(:post, path, options, raw, unformatted) end
put(path, options={}, raw=false, unformatted=false)
click to toggle source
Perform an HTTP PUT request
# File lib/genability/request.rb, line 15 def put(path, options={}, raw=false, unformatted=false) request(:put, path, options, raw, unformatted) end
Private Instance Methods
default_request?()
click to toggle source
# File lib/genability/request.rb, line 53 def default_request? format.to_sym == :json end
formatted_path(path)
click to toggle source
# File lib/genability/request.rb, line 49 def formatted_path(path) [path, format].compact.join('.') end
request(method, path, options, raw=false, unformatted=false)
click to toggle source
Perform an HTTP request
# File lib/genability/request.rb, line 27 def request(method, path, options, raw=false, unformatted=false) response = connection(raw).send(method) do |request| path = formatted_path(path) unless unformatted || default_request? case method when :get, :delete request.url(path, options) request.params['appId'] = application_id request.params['appKey'] = application_key when :post, :put request.path = path if options['fileData'] request.headers['Content-type'] = 'multipart/form-data' request.body = options else request.headers['Content-Type'] = 'application/json;charset=utf-8' request.body = options unless options.empty? end end end raw ? response : response.body end