Class: Amazon::Ecs::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/amazon/ecs.rb

Overview

Response object returned after a REST call to Amazon service.

Instance Method Summary collapse

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

#docObject

Return Hpricot object.



118
119
120
# File 'lib/amazon/ecs.rb', line 118

def doc
  @doc
end

#errorObject

Return error message.



133
134
135
# File 'lib/amazon/ecs.rb', line 133

def error
  Element.get(@doc, "error/message")
end

#error_codeObject

Return error code



138
139
140
# File 'lib/amazon/ecs.rb', line 138

def error_code
  Element.get(@doc, "error/code")
end

#first_itemObject

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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


123
124
125
# File 'lib/amazon/ecs.rb', line 123

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.



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

#itemsObject

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_pagesObject

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_resultsObject

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