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
23
# File 'lib/opensrs/response.rb', line 15

def errors
  if !success?
    if response["response_text"] and response["response_code"]
      "#{response["response_text"]} (Code #{response["response_code"]})"
    else
      "Unknown error"
    end
  end
end

#success?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/opensrs/response.rb', line 25

def success?
  response["is_success"] ? response["is_success"].to_s == "1" : true
end