Class: QuickPay::API::Request
- Inherits:
-
Object
- Object
- QuickPay::API::Request
- Includes:
- HTTMultiParty
- Defined in:
- lib/quickpay/api/request.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
Instance Method Summary collapse
- #create_response(raw, res) ⇒ Object
-
#initialize(options = {}) ⇒ Request
constructor
A new instance of Request.
- #raise_error(body, status) ⇒ Object
- #request(method, path, data = {}) ⇒ Object
Constructor Details
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/quickpay/api/request.rb', line 8 def @options end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
8 9 10 |
# File 'lib/quickpay/api/request.rb', line 8 def secret @secret end |
Instance Method Details
#create_response(raw, res) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/quickpay/api/request.rb', line 39 def create_response raw, res if raw [res.code, res.body, res.headers] else response = res.parsed_response raise_error(response, res.code) if res.code >= 400 response end end |
#raise_error(body, status) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/quickpay/api/request.rb', line 49 def raise_error body, status code = API_STATUS_CODES[status].to_s args = [code, status, body] klass = begin require "quickpay/api/errors/#{code}" class_name = code.split('_').map(&:capitalize).join('') QuickPay::API.const_get(class_name) rescue LoadError, NameError QuickPay::API::Error end fail klass.new(*args), error_description(body) end |
#request(method, path, data = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/quickpay/api/request.rb', line 16 def request method, path, data = {} raw = data.delete(:raw) req_headers = headers.merge(data.delete(:headers) || {}) = .dup if data.any? { |_key, value| value.is_a?(File) } [:body] = data [:detect_mime_type] = true else case method when :get, :delete [:query] = data when :post, :patch, :put [:body] = data.to_json req_headers["Content-Type"] = "application/json" end end [:headers] = headers.merge(req_headers) QuickPay.logger.debug { "#{method.to_s.upcase} #{base_uri}#{path} #{}" } create_response(raw, self.class.send(method, path, )) end |