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



134
135
136
137
138
139
# File 'lib/amazon/ecs.rb', line 134

def initialize(xml)
  @doc = Nokogiri::XML(xml)
  @doc.remove_namespaces!
  # @doc.xpath("//*").each { |elem| elem.name = elem.name.downcase }
  # @doc.xpath("//@*").each { |att| att.name = att.name.downcase }
end

Instance Method Details

#docObject

Return Nokogiri::XML::Document object.



142
143
144
# File 'lib/amazon/ecs.rb', line 142

def doc
  @doc
end

#errorObject

Return error message.



157
158
159
# File 'lib/amazon/ecs.rb', line 157

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

#error_codeObject

Return error code



162
163
164
# File 'lib/amazon/ecs.rb', line 162

def error_code
  Element.get(@doc, "//Error/Code")
end

#first_itemObject

Return the first item (Amazon::Element)



172
173
174
# File 'lib/amazon/ecs.rb', line 172

def first_item
  items.first
end

#has_error?Boolean

Return true if response has an error.

Returns:

  • (Boolean)


152
153
154
# File 'lib/amazon/ecs.rb', line 152

def has_error?
  !(error.nil? || error.empty?)
end

#is_valid_request?Boolean

Return true if request is valid.

Returns:

  • (Boolean)


147
148
149
# File 'lib/amazon/ecs.rb', line 147

def is_valid_request?
  Element.get(@doc, "//IsValid") == "True"
end

#item_pageObject

Return current page no if :item_page option is when initiating the request.



177
178
179
# File 'lib/amazon/ecs.rb', line 177

def item_page
  @item_page ||= Element.get(@doc, "//ItemPage").to_i
end

#itemsObject

Return an array of Amazon::Element item objects.



167
168
169
# File 'lib/amazon/ecs.rb', line 167

def items
  @items ||= (@doc/"Item").collect { |item| Element.new(item) }
end

#marshal_dumpObject



191
192
193
# File 'lib/amazon/ecs.rb', line 191

def marshal_dump
  @doc.to_s
end

#marshal_load(xml) ⇒ Object



195
196
197
# File 'lib/amazon/ecs.rb', line 195

def marshal_load(xml)
  initialize(xml)
end

#total_pagesObject

Return total pages.



187
188
189
# File 'lib/amazon/ecs.rb', line 187

def total_pages
  @total_pages ||= Element.get(@doc, "//TotalPages").to_i
end

#total_resultsObject

Return total results.



182
183
184
# File 'lib/amazon/ecs.rb', line 182

def total_results
  @total_results ||= Element.get(@doc, "//TotalResults").to_i
end