Class: Amazon::Ecs::Response
- Inherits:
-
Object
- Object
- Amazon::Ecs::Response
- Defined in:
- lib/amazon/ecs.rb
Overview
Response object returned after a REST call to Amazon service.
Instance Method Summary collapse
-
#/(path) ⇒ Object
Return a Nokogiri::XML::NodeSet of elements matching the given path.
-
#doc ⇒ Object
Return Nokogiri::XML::Document object.
-
#error ⇒ Object
Return error message.
-
#error_code ⇒ Object
Return error code.
-
#first_item ⇒ Object
Return the first item (Amazon::Element).
-
#get_element(path) ⇒ Object
Return the first element found.
-
#get_elements(path) ⇒ Object
Return an array of Amazon::Element matching the given path.
-
#has_error? ⇒ Boolean
Return true if response has an error.
-
#initialize(xml) ⇒ Response
constructor
XML input is in string format.
-
#is_valid_request? ⇒ Boolean
Return true if request is valid.
-
#item_page ⇒ Object
Return current page no if :item_page option is when initiating the request.
-
#items ⇒ Object
Return an array of Amazon::Element item objects.
- #marshal_dump ⇒ Object
- #marshal_load(xml) ⇒ Object
-
#total_pages ⇒ Object
Return total pages.
-
#total_results ⇒ Object
Return total results.
Constructor Details
#initialize(xml) ⇒ Response
XML input is in string format
157 158 159 160 161 162 |
# File 'lib/amazon/ecs.rb', line 157 def initialize(xml) @doc = Nokogiri::XML(xml, nil, 'UTF-8') @doc.remove_namespaces! # @doc.xpath("//*").each { |elem| elem.name = elem.name.downcase } # @doc.xpath("//@*").each { |att| att.name = att.name.downcase } end |
Instance Method Details
#/(path) ⇒ Object
Return a Nokogiri::XML::NodeSet of elements matching the given path.
170 171 172 173 174 |
# File 'lib/amazon/ecs.rb', line 170 def /(path) elements = @doc/path return nil if elements.size == 0 elements end |
#doc ⇒ Object
Return Nokogiri::XML::Document object.
165 166 167 |
# File 'lib/amazon/ecs.rb', line 165 def doc @doc end |
#error ⇒ Object
Return error message.
200 201 202 |
# File 'lib/amazon/ecs.rb', line 200 def error Element.get(@doc, "//Error/Message") end |
#error_code ⇒ Object
Return error code
205 206 207 |
# File 'lib/amazon/ecs.rb', line 205 def error_code Element.get(@doc, "//Error/Code") end |
#first_item ⇒ Object
Return the first item (Amazon::Element)
215 216 217 |
# File 'lib/amazon/ecs.rb', line 215 def first_item items.first end |
#get_element(path) ⇒ Object
Return the first element found
184 185 186 187 |
# File 'lib/amazon/ecs.rb', line 184 def get_element(path) elements = get_elements(path) elements[0] if elements end |
#get_elements(path) ⇒ Object
Return an array of Amazon::Element matching the given path
177 178 179 180 181 |
# File 'lib/amazon/ecs.rb', line 177 def get_elements(path) elements = self./(path) return unless elements elements = elements.map{|element| Element.new(element)} end |
#has_error? ⇒ Boolean
Return true if response has an error.
195 196 197 |
# File 'lib/amazon/ecs.rb', line 195 def has_error? !(error.nil? || error.empty?) end |
#is_valid_request? ⇒ Boolean
Return true if request is valid.
190 191 192 |
# File 'lib/amazon/ecs.rb', line 190 def is_valid_request? Element.get(@doc, "//IsValid") == "True" end |
#item_page ⇒ Object
Return current page no if :item_page option is when initiating the request.
220 221 222 |
# File 'lib/amazon/ecs.rb', line 220 def item_page @item_page ||= Element.get(@doc, "//ItemPage").to_i end |
#items ⇒ Object
Return an array of Amazon::Element item objects.
210 211 212 |
# File 'lib/amazon/ecs.rb', line 210 def items @items ||= (@doc/"Item").collect { |item| Element.new(item) } end |
#marshal_dump ⇒ Object
234 235 236 |
# File 'lib/amazon/ecs.rb', line 234 def marshal_dump @doc.to_s end |
#marshal_load(xml) ⇒ Object
238 239 240 |
# File 'lib/amazon/ecs.rb', line 238 def marshal_load(xml) initialize(xml) end |