Class: Amazon::Ecs::Response

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#docObject (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

#errorObject

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_itemObject

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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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_pageObject

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

#itemsObject

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_pagesObject

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_resultsObject

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