Class: JasperClient::RepositoryService::Response
- Inherits:
-
Object
- Object
- JasperClient::RepositoryService::Response
- Defined in:
- lib/jasper-client/jasper_client.rb
Overview
A response subclass exists for each type of response. There is a response type for each type of request (list, get, runReport). Code common to all response types is put into the Response class, otherwise responses are named CamelizedRequestNameResponse. So for example ListResponse, GetResponse, RunReportResponse.
Direct Known Subclasses
Defined Under Namespace
Classes: GetResponse, ListResponse, RunReportResponse
Instance Attribute Summary collapse
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
-
#xml_doc ⇒ Object
readonly
Returns the value of attribute xml_doc.
Instance Method Summary collapse
-
#collect_resources ⇒ Object
Extract resourceDescriptors from the response and drop them into @resources.
-
#message ⇒ Object
return “OK” on success, since successful responses don’t seem to have messages.
-
#return_code ⇒ Object
“0” if the request was successfully processed by the server.
-
#search(path) ⇒ Object
Search the response using xpath.
-
#success? ⇒ Boolean
return true if the response is successful.
Instance Attribute Details
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
132 133 134 |
# File 'lib/jasper-client/jasper_client.rb', line 132 def resources @resources end |
#xml_doc ⇒ Object (readonly)
Returns the value of attribute xml_doc.
132 133 134 |
# File 'lib/jasper-client/jasper_client.rb', line 132 def xml_doc @xml_doc end |
Instance Method Details
#collect_resources ⇒ Object
Extract resourceDescriptors from the response and drop them into @resources.
173 174 175 |
# File 'lib/jasper-client/jasper_client.rb', line 173 def collect_resources @resources = @xml_doc.search('./operationResult/resourceDescriptor').map { |r| Resource.new(r) } end |
#message ⇒ Object
return “OK” on success, since successful responses don’t seem to have messages. When the response is not successful, the message is pulled from the response xml.
147 148 149 150 151 152 153 |
# File 'lib/jasper-client/jasper_client.rb', line 147 def if success? "OK" else xml_doc.search('//returnMessage/node()').inner_text end end |
#return_code ⇒ Object
“0” if the request was successfully processed by the server.
135 136 137 |
# File 'lib/jasper-client/jasper_client.rb', line 135 def return_code xml_doc.search('//returnCode').inner_text end |
#search(path) ⇒ Object
Search the response using xpath. When this Responses xml_doc does not have a search method, a string with inner_text and inner_html methods are added. The reson for this is so unwitting callers won’t need to have the extra logic to make sure that that this response has a valid xml_doc.
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/jasper-client/jasper_client.rb', line 160 def search(path) return xml_doc.search(path) if xml_doc.respond_to?(:search) # return something that acts like a dom element (nokogiri) x = "" class << x def inner_text; ""; end alias inner_html inner_text end x end |
#success? ⇒ Boolean
return true if the response is successful.
140 141 142 |
# File 'lib/jasper-client/jasper_client.rb', line 140 def success? "0" == return_code end |