class AcceptOn::Request
Constants
- URLS
Attributes
client[RW]
headers[RW]
options[RW]
path[RW]
Public Class Methods
new(client, request_method, path, options = {})
click to toggle source
@param client [AcceptOn::Client] @param request_method [String, Symbol] @param path [String] @param options [Hash] @return [Accepton::Request]
# File lib/accepton/request.rb, line 21 def initialize(client, request_method, path, options = {}) options = default_options.merge(options) url = URLS[options.delete(:environment).to_sym] @client = client @request_method = request_method @uri = Addressable::URI.parse(path.start_with?('http') ? path : url + path) @options = options @path = @uri.path @headers = AcceptOn::Headers.new(@client).request_headers end
Public Instance Methods
perform()
click to toggle source
@return [Hashie::Mash] if the request reutrns a success code @raise [AcceptOn::Error] if the request returns a failure code
# File lib/accepton/request.rb, line 34 def perform options_key = @request_method == :get ? :params : :form response = HTTP.with(@headers).public_send(@request_method, @uri.to_s, options_key => @options) response_body = Hashie::Mash.new(response.parse) fail_or_return_response_body(response_body, response.code) end
Private Instance Methods
default_options()
click to toggle source
@return [Hash]
# File lib/accepton/request.rb, line 50 def default_options {environment: :production} end
fail_or_return_response_body(body, status_code)
click to toggle source
# File lib/accepton/request.rb, line 43 def fail_or_return_response_body(body, status_code) error = AcceptOn::Error.from_response(body, status_code) fail(error) if error body end