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
-
#doc ⇒ Object
Return Hpricot 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.
-
#total_pages ⇒ Object
Return total pages.
-
#total_results ⇒ Object
Return total results.
Constructor Details
#initialize(xml) ⇒ Response
XML input is in string format
124 125 126 |
# File 'lib/amazon/ecs.rb', line 124 def initialize(xml) @doc = Hpricot(xml) end |
Instance Method Details
#doc ⇒ Object
Return Hpricot object.
129 130 131 |
# File 'lib/amazon/ecs.rb', line 129 def doc @doc end |
#error ⇒ Object
Return error message.
144 145 146 |
# File 'lib/amazon/ecs.rb', line 144 def error Element.get(@doc, "error/message") end |
#error_code ⇒ Object
Return error code
149 150 151 |
# File 'lib/amazon/ecs.rb', line 149 def error_code Element.get(@doc, "error/code") end |
#first_item ⇒ Object
Return the first item (Amazon::Element)
162 163 164 |
# File 'lib/amazon/ecs.rb', line 162 def first_item items.first end |
#has_error? ⇒ Boolean
Return true if response has an error.
139 140 141 |
# File 'lib/amazon/ecs.rb', line 139 def has_error? !(error.nil? || error.empty?) end |
#is_valid_request? ⇒ Boolean
Return true if request is valid.
134 135 136 |
# File 'lib/amazon/ecs.rb', line 134 def is_valid_request? (@doc/"isvalid").inner_html == "True" end |
#item_page ⇒ Object
Return current page no if :item_page option is when initiating the request.
167 168 169 170 171 172 |
# File 'lib/amazon/ecs.rb', line 167 def item_page unless @item_page @item_page = (@doc/"itemsearchrequest/itempage").inner_html.to_i end @item_page end |
#items ⇒ Object
Return an array of Amazon::Element item objects.
154 155 156 157 158 159 |
# File 'lib/amazon/ecs.rb', line 154 def items unless @items @items = (@doc/"item").collect {|item| Element.new(item)} end @items end |
#total_pages ⇒ Object
Return total pages.
183 184 185 186 187 188 |
# File 'lib/amazon/ecs.rb', line 183 def total_pages unless @total_pages @total_pages = (@doc/"totalpages").inner_html.to_i end @total_pages end |
#total_results ⇒ Object
Return total results.
175 176 177 178 179 180 |
# File 'lib/amazon/ecs.rb', line 175 def total_results unless @total_results @total_results = (@doc/"totalresults").inner_html.to_i end @total_results end |