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
113 114 115 |
# File 'lib/amazon/ecs.rb', line 113 def initialize(xml) @doc = Hpricot(xml) end |
Instance Method Details
#doc ⇒ Object
Return Hpricot object.
118 119 120 |
# File 'lib/amazon/ecs.rb', line 118 def doc @doc end |
#error ⇒ Object
Return error message.
133 134 135 |
# File 'lib/amazon/ecs.rb', line 133 def error Element.get(@doc, "error/message") end |
#error_code ⇒ Object
Return error code
138 139 140 |
# File 'lib/amazon/ecs.rb', line 138 def error_code Element.get(@doc, "error/code") end |
#first_item ⇒ Object
Return the first item (Amazon::Element)
151 152 153 |
# File 'lib/amazon/ecs.rb', line 151 def first_item items.first end |
#has_error? ⇒ Boolean
Return true if response has an error.
128 129 130 |
# File 'lib/amazon/ecs.rb', line 128 def has_error? !(error.nil? || error.empty?) end |
#is_valid_request? ⇒ Boolean
Return true if request is valid.
123 124 125 |
# File 'lib/amazon/ecs.rb', line 123 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.
156 157 158 159 160 161 |
# File 'lib/amazon/ecs.rb', line 156 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.
143 144 145 146 147 148 |
# File 'lib/amazon/ecs.rb', line 143 def items unless @items @items = (@doc/"item").collect {|item| Element.new(item)} end @items end |
#total_pages ⇒ Object
Return total pages.
172 173 174 175 176 177 |
# File 'lib/amazon/ecs.rb', line 172 def total_pages unless @total_pages @total_pages = (@doc/"totalpages").inner_html.to_i end @total_pages end |
#total_results ⇒ Object
Return total results.
164 165 166 167 168 169 |
# File 'lib/amazon/ecs.rb', line 164 def total_results unless @total_results @total_results = (@doc/"totalresults").inner_html.to_i end @total_results end |