Class: Amazon::Ecs::Response
- Inherits:
-
Object
- Object
- Amazon::Ecs::Response
- Defined in:
- lib/alexandria/book_providers/amazon_ecs_util.rb
Overview
Response object returned after a REST call to Amazon service.
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Return Hpricot object.
Instance Method Summary collapse
-
#error ⇒ Object
Return error message.
-
#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
132 133 134 |
# File 'lib/alexandria/book_providers/amazon_ecs_util.rb', line 132 def initialize(xml) @doc = Hpricot(xml) end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Return Hpricot object.
137 138 139 |
# File 'lib/alexandria/book_providers/amazon_ecs_util.rb', line 137 def doc @doc end |
Instance Method Details
#error ⇒ Object
Return error message.
150 151 152 |
# File 'lib/alexandria/book_providers/amazon_ecs_util.rb', line 150 def error Element.get(@doc, 'error/message') end |
#first_item ⇒ Object
Return the first item (Amazon::Element)
161 162 163 |
# File 'lib/alexandria/book_providers/amazon_ecs_util.rb', line 161 def first_item items.first end |
#has_error? ⇒ Boolean
Return true if response has an error.
145 146 147 |
# File 'lib/alexandria/book_providers/amazon_ecs_util.rb', line 145 def has_error? !(error.nil? || error.empty?) end |
#is_valid_request? ⇒ Boolean
Return true if request is valid.
140 141 142 |
# File 'lib/alexandria/book_providers/amazon_ecs_util.rb', line 140 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.
166 167 168 169 |
# File 'lib/alexandria/book_providers/amazon_ecs_util.rb', line 166 def item_page @item_page ||= (@doc / 'itemsearchrequest/itempage').inner_html.to_i @item_page end |
#items ⇒ Object
Return an array of Amazon::Element item objects.
155 156 157 158 |
# File 'lib/alexandria/book_providers/amazon_ecs_util.rb', line 155 def items @items ||= (@doc / 'item').map { |item| Element.new(item) } @items end |
#total_pages ⇒ Object
Return total pages.
178 179 180 181 |
# File 'lib/alexandria/book_providers/amazon_ecs_util.rb', line 178 def total_pages @total_pages ||= (@doc / 'totalpages').inner_html.to_i @total_pages end |
#total_results ⇒ Object
Return total results.
172 173 174 175 |
# File 'lib/alexandria/book_providers/amazon_ecs_util.rb', line 172 def total_results @total_results ||= (@doc / 'totalresults').inner_html.to_i @total_results end |