module Besepa::Utils::Request
Defines HTTP request methods
Constants
- END_POINT_URL_PREFIX
Public Instance Methods
delete(path, params={}, options={})
click to toggle source
Perform an HTTP DELETE request
# File lib/besepa/utils/request.rb, line 11 def delete(path, params={}, options={}) request(:delete, path, params, options) end
get(path, params={}, options={})
click to toggle source
Perform an HTTP GET request
# File lib/besepa/utils/request.rb, line 16 def get(path, params={}, options={}) request(:get, path, params, options) end
post(path, params={}, options={})
click to toggle source
Perform an HTTP POST request
# File lib/besepa/utils/request.rb, line 21 def post(path, params={}, options={}) request(:post, path, params, options) end
put(path, params={}, options={})
click to toggle source
Perform an HTTP PUT request
# File lib/besepa/utils/request.rb, line 26 def put(path, params={}, options={}) request(:put, path, params, options) end
Protected Instance Methods
handle_response(response)
click to toggle source
# File lib/besepa/utils/request.rb, line 47 def handle_response(response) body = response.body if response.status >= 400 || body['error'] handle_errors(response.status, body) else body end end
request(method, path, params, options)
click to toggle source
Perform an HTTP request
# File lib/besepa/utils/request.rb, line 33 def request(method, path, params, options) response = connection(options).run_request(method, nil, nil, nil) do |request| request.options[:raw] = true if options[:raw] case method.to_sym when :delete, :get request.url(END_POINT_URL_PREFIX + path, params) when :post, :put request.path = END_POINT_URL_PREFIX + path request.body = params unless params.empty? end end options[:raw] ? response : handle_response(response) end