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
116 117 118 |
# File 'lib/amazon/ecs.rb', line 116 def initialize(xml) @doc = Hpricot(xml) end |
Instance Method Details
#doc ⇒ Object
Return Hpricot object.
121 122 123 |
# File 'lib/amazon/ecs.rb', line 121 def doc @doc end |
#error ⇒ Object
Return error message.
136 137 138 |
# File 'lib/amazon/ecs.rb', line 136 def error Element.get(@doc, "error/message") end |
#error_code ⇒ Object
Return error code
141 142 143 |
# File 'lib/amazon/ecs.rb', line 141 def error_code Element.get(@doc, "error/code") end |
#first_item ⇒ Object
Return the first item (Amazon::Element)
154 155 156 |
# File 'lib/amazon/ecs.rb', line 154 def first_item items.first end |
#has_error? ⇒ Boolean
Return true if response has an error.
131 132 133 |
# File 'lib/amazon/ecs.rb', line 131 def has_error? !(error.nil? || error.empty?) end |
#is_valid_request? ⇒ Boolean
Return true if request is valid.
126 127 128 |
# File 'lib/amazon/ecs.rb', line 126 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.
159 160 161 162 163 164 |
# File 'lib/amazon/ecs.rb', line 159 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.
146 147 148 149 150 151 |
# File 'lib/amazon/ecs.rb', line 146 def items unless @items @items = (@doc/"item").collect {|item| Element.new(item)} end @items end |
#total_pages ⇒ Object
Return total pages.
175 176 177 178 179 180 |
# File 'lib/amazon/ecs.rb', line 175 def total_pages unless @total_pages @total_pages = (@doc/"totalpages").inner_html.to_i end @total_pages end |
#total_results ⇒ Object
Return total results.
167 168 169 170 171 172 |
# File 'lib/amazon/ecs.rb', line 167 def total_results unless @total_results @total_results = (@doc/"totalresults").inner_html.to_i end @total_results end |