Class: AcceptOn::Request
- Inherits:
-
Object
- Object
- AcceptOn::Request
- Defined in:
- lib/accepton/request.rb
Constant Summary collapse
- URLS =
{ development: 'http://checkout.accepton.dev', staging: 'https://staging-checkout.accepton.com', production: 'https://checkout.accepton.com' }.freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#options ⇒ Object
Returns the value of attribute options.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #initialize(client, request_method, path, options = {}) ⇒ Accepton::Request constructor
-
#perform ⇒ Hashie::Mash
If the request reutrns a success code.
Constructor Details
#initialize(client, request_method, path, options = {}) ⇒ Accepton::Request
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/accepton/request.rb', line 21 def initialize(client, request_method, path, = {}) = .merge() url = URLS[.delete(:environment).to_sym] @client = client @request_method = request_method @uri = Addressable::URI.parse(path.start_with?('http') ? path : url + path) = @path = @uri.path @headers = AcceptOn::Headers.new(@client).request_headers end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
14 15 16 |
# File 'lib/accepton/request.rb', line 14 def client @client end |
#headers ⇒ Object
Returns the value of attribute headers.
14 15 16 |
# File 'lib/accepton/request.rb', line 14 def headers @headers end |
#options ⇒ Object
Returns the value of attribute options.
14 15 16 |
# File 'lib/accepton/request.rb', line 14 def end |
#path ⇒ Object
Returns the value of attribute path.
14 15 16 |
# File 'lib/accepton/request.rb', line 14 def path @path end |
Instance Method Details
#perform ⇒ Hashie::Mash
Returns if the request reutrns a success code.
34 35 36 37 38 39 |
# File 'lib/accepton/request.rb', line 34 def perform = @request_method == :get ? :params : :form response = HTTP.with(@headers).public_send(@request_method, @uri.to_s, => ) response_body = Hashie::Mash.new(response.parse) fail_or_return_response_body(response_body, response.code) end |