Class: ZipMoney::Response
- Inherits:
-
Object
- Object
- ZipMoney::Response
- Defined in:
- lib/zipMoney/response.rb
Instance Attribute Summary collapse
-
#_response ⇒ Object
Returns the value of attribute _response.
-
#_responseBody ⇒ Object
Returns the value of attribute _responseBody.
-
#_responseHeader ⇒ Object
Returns the value of attribute _responseHeader.
-
#_statusCode ⇒ Object
Returns the value of attribute _statusCode.
Instance Method Summary collapse
-
#getError ⇒ Object
Returns error string.
-
#getRedirectUrl ⇒ Object
Returns the redirect_url from the checkout and quote calls.
-
#getStatusCode ⇒ Object
Returns the http status code.
-
#initialize(response) ⇒ Object
constructor
Initializes a new api response object.
-
#isSuccess ⇒ Object
Returns if the api call was a success or failure.
-
#toHash ⇒ Object
Converts the response body to Hash.
-
#toObject ⇒ Object
Converts the response body to Object.
Constructor Details
#initialize(response) ⇒ Object
Initializes a new api response object
11 12 13 14 15 16 |
# File 'lib/zipMoney/response.rb', line 11 def initialize(response) raise ArgumentError, "Response doesnot exist" if ((response.nil? || response.empty?) && response.code.nil? && response.code.empty?) @_response = response @_statusCode = response.code @_responseBody = response.body end |
Instance Attribute Details
#_response ⇒ Object
Returns the value of attribute _response.
4 5 6 |
# File 'lib/zipMoney/response.rb', line 4 def _response @_response end |
#_responseBody ⇒ Object
Returns the value of attribute _responseBody.
4 5 6 |
# File 'lib/zipMoney/response.rb', line 4 def _responseBody @_responseBody end |
#_responseHeader ⇒ Object
Returns the value of attribute _responseHeader.
4 5 6 |
# File 'lib/zipMoney/response.rb', line 4 def _responseHeader @_responseHeader end |
#_statusCode ⇒ Object
Returns the value of attribute _statusCode.
4 5 6 |
# File 'lib/zipMoney/response.rb', line 4 def _statusCode @_statusCode end |
Instance Method Details
#getError ⇒ Object
Returns error string
62 63 64 65 66 |
# File 'lib/zipMoney/response.rb', line 62 def getError raise ArgumentError, "Response body doesnot exist" if @_responseBody.nil? || @_responseBody.empty? resObj = toObject resObj.Message end |
#getRedirectUrl ⇒ Object
Returns the redirect_url from the checkout and quote calls
38 39 40 41 42 43 |
# File 'lib/zipMoney/response.rb', line 38 def getRedirectUrl raise ArgumentError, "Response body doesnot exist" if @_responseBody.nil? || @_responseBody.empty? resObj = toObject return false if resObj.redirect_url.nil? || resObj.redirect_url.empty? resObj.redirect_url end |
#getStatusCode ⇒ Object
Returns the http status code
48 49 50 |
# File 'lib/zipMoney/response.rb', line 48 def getStatusCode @_statusCode end |
#isSuccess ⇒ Object
Returns if the api call was a success or failure
55 56 57 |
# File 'lib/zipMoney/response.rb', line 55 def isSuccess return @_statusCode == 200 || @_statusCode == 201? true : false end |
#toHash ⇒ Object
Converts the response body to Hash
21 22 23 24 |
# File 'lib/zipMoney/response.rb', line 21 def toHash raise ResponseError, "Response body doesnot exist" if @_responseBody.nil? || @_responseBody.empty? JSON.parse(@_responseBody) end |
#toObject ⇒ Object
Converts the response body to Object
29 30 31 32 33 |
# File 'lib/zipMoney/response.rb', line 29 def toObject raise ResponseError, "Response body doesnot exist" if @_responseBody.nil? || @_responseBody.empty? responseObject = JSON.parse(@_responseBody, object_class: OpenStruct) responseObject end |