Class: OpenSRS::Response
- Inherits:
-
Object
- Object
- OpenSRS::Response
- Defined in:
- lib/opensrs/response.rb
Instance Attribute Summary collapse
-
#request_xml ⇒ Object
readonly
Returns the value of attribute request_xml.
-
#response ⇒ Object
Returns the value of attribute response.
-
#response_xml ⇒ Object
readonly
Returns the value of attribute response_xml.
-
#success ⇒ Object
Returns the value of attribute success.
Instance Method Summary collapse
-
#errors ⇒ Object
We need to return the error message unless the response is successful.
-
#initialize(parsed_response, request_xml, response_xml) ⇒ Response
constructor
A new instance of Response.
-
#success? ⇒ Boolean
If ‘is_success’ is returned, the API is letting us know that they will explicitly tell us whether something has succeeded or not.
Constructor Details
#initialize(parsed_response, request_xml, response_xml) ⇒ Response
Returns a new instance of Response.
6 7 8 9 10 11 |
# File 'lib/opensrs/response.rb', line 6 def initialize(parsed_response, request_xml, response_xml) @response = parsed_response @request_xml = request_xml @response_xml = response_xml @success = success? end |
Instance Attribute Details
#request_xml ⇒ Object (readonly)
Returns the value of attribute request_xml.
3 4 5 |
# File 'lib/opensrs/response.rb', line 3 def request_xml @request_xml end |
#response ⇒ Object
Returns the value of attribute response.
4 5 6 |
# File 'lib/opensrs/response.rb', line 4 def response @response end |
#response_xml ⇒ Object (readonly)
Returns the value of attribute response_xml.
3 4 5 |
# File 'lib/opensrs/response.rb', line 3 def response_xml @response_xml end |
#success ⇒ Object
Returns the value of attribute success.
4 5 6 |
# File 'lib/opensrs/response.rb', line 4 def success @success end |
Instance Method Details
#errors ⇒ Object
We need to return the error message unless the response is successful.
15 16 17 18 19 20 21 22 |
# File 'lib/opensrs/response.rb', line 15 def errors unless success? msg = @response["response_text"] code = @response["response_code"] return msg && code ? "#{msg} (Code #{code})" : "Unknown error" end end |
#success? ⇒ Boolean
If ‘is_success’ is returned, the API is letting us know that they will explicitly tell us whether something has succeeded or not. Otherwise, just assume it is successful.
27 28 29 |
# File 'lib/opensrs/response.rb', line 27 def success? @response["is_success"] && @response["is_success"] == "1" ? true : false end |