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
- #children_browse_nodes ⇒ Object
-
#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).
-
#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
154 155 156 157 158 159 |
# File 'lib/amazon/ecs.rb', line 154 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
#children_browse_nodes ⇒ Object
196 197 198 |
# File 'lib/amazon/ecs.rb', line 196 def children_browse_nodes @children_browse_nodes ||= (@doc/"BrowseNodes/BrowseNode/Children/BrowseNode").collect { |item| Element.new(item) } end |
#doc ⇒ Object
Return Nokogiri::XML::Document object.
162 163 164 |
# File 'lib/amazon/ecs.rb', line 162 def doc @doc end |
#error ⇒ Object
Return error message.
177 178 179 |
# File 'lib/amazon/ecs.rb', line 177 def error Element.get(@doc, "//Error/Message") end |
#error_code ⇒ Object
Return error code
182 183 184 |
# File 'lib/amazon/ecs.rb', line 182 def error_code Element.get(@doc, "//Error/Code") end |
#first_item ⇒ Object
Return the first item (Amazon::Element)
192 193 194 |
# File 'lib/amazon/ecs.rb', line 192 def first_item items.first end |
#has_error? ⇒ Boolean
Return true if response has an error.
172 173 174 |
# File 'lib/amazon/ecs.rb', line 172 def has_error? !(error.nil? || error.empty?) end |
#is_valid_request? ⇒ Boolean
Return true if request is valid.
167 168 169 |
# File 'lib/amazon/ecs.rb', line 167 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.
201 202 203 |
# File 'lib/amazon/ecs.rb', line 201 def item_page @item_page ||= Element.get(@doc, "//ItemPage").to_i end |
#items ⇒ Object
Return an array of Amazon::Element item objects.
187 188 189 |
# File 'lib/amazon/ecs.rb', line 187 def items @items ||= (@doc/"Item").collect { |item| Element.new(item) } end |
#marshal_dump ⇒ Object
215 216 217 |
# File 'lib/amazon/ecs.rb', line 215 def marshal_dump @doc.to_s end |
#marshal_load(xml) ⇒ Object
219 220 221 |
# File 'lib/amazon/ecs.rb', line 219 def marshal_load(xml) initialize(xml) end |