Class: OpenSRS::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/opensrs/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_xmlObject (readonly)

Returns the value of attribute request_xml.



3
4
5
# File 'lib/opensrs/response.rb', line 3

def request_xml
  @request_xml
end

#responseObject

Returns the value of attribute response.



4
5
6
# File 'lib/opensrs/response.rb', line 4

def response
  @response
end

#response_xmlObject (readonly)

Returns the value of attribute response_xml.



3
4
5
# File 'lib/opensrs/response.rb', line 3

def response_xml
  @response_xml
end

#successObject

Returns the value of attribute success.



4
5
6
# File 'lib/opensrs/response.rb', line 4

def success
  @success
end

Instance Method Details

#errorsObject

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.

Returns:

  • (Boolean)


27
28
29
# File 'lib/opensrs/response.rb', line 27

def success?
  @response["is_success"] && @response["is_success"] == "1" ? true : false
end