class Amazon::Ecs::Response

Response object returned after a REST call to Amazon service.

Public Class Methods

new(xml) click to toggle source

XML input is in string format

# File lib/amazon/ecs.rb, line 154
def initialize(xml)
  @doc = Nokogiri::XML(xml, nil, 'UTF-8')
  @doc.remove_namespaces!
  # @doc.xpath("//*").each { |elem| elem.name = elem.name.downcase }
  # @doc.xpath("//@*").each { |att| att.name = att.name.downcase }
end

Public Instance Methods

/(path) click to toggle source

Return a Nokogiri::XML::NodeSet of elements matching the given path.

# File lib/amazon/ecs.rb, line 167
def /(path)
  elements = @doc/path
  return nil if elements.size == 0
  elements
end
doc() click to toggle source

Return Nokogiri::XML::Document object.

# File lib/amazon/ecs.rb, line 162
def doc
  @doc
end
error() click to toggle source

Return error message.

# File lib/amazon/ecs.rb, line 197
def error
  Element.get(@doc, "//Error/Message")
end
error_code() click to toggle source

Return error code

# File lib/amazon/ecs.rb, line 202
def error_code
  Element.get(@doc, "//Error/Code")
end
first_item() click to toggle source

Return the first item (Amazon::Element)

# File lib/amazon/ecs.rb, line 212
def first_item
  items.first
end
get_element(path) click to toggle source

Return the first element found

# File lib/amazon/ecs.rb, line 181
def get_element(path)
  elements = get_elements(path)
  elements[0] if elements
end
get_elements(path) click to toggle source

Return an array of Amazon::Element matching the given path

# File lib/amazon/ecs.rb, line 174
def get_elements(path)
  elements = self./(path)
  return unless elements
  elements = elements.map{|element| Element.new(element)}
end
has_error?() click to toggle source

Return true if response has an error.

# File lib/amazon/ecs.rb, line 192
def has_error?
  !(error.nil? || error.empty?)
end
is_valid_request?() click to toggle source

Return true if request is valid.

# File lib/amazon/ecs.rb, line 187
def is_valid_request?
  Element.get(@doc, "//IsValid") == "True"
end
item_page() click to toggle source

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

# File lib/amazon/ecs.rb, line 217
def item_page
  @item_page ||= Element.get(@doc, "//ItemPage").to_i
end
items() click to toggle source

Return an array of Amazon::Element item objects.

# File lib/amazon/ecs.rb, line 207
def items
  @items ||= (@doc/"Item").collect { |item| Element.new(item) }
end
marshal_dump() click to toggle source
# File lib/amazon/ecs.rb, line 231
def marshal_dump
  @doc.to_s
end
marshal_load(xml) click to toggle source
# File lib/amazon/ecs.rb, line 235
def marshal_load(xml)
  initialize(xml)
end
total_pages() click to toggle source

Return total pages.

# File lib/amazon/ecs.rb, line 227
def total_pages
  @total_pages ||= Element.get(@doc, "//TotalPages").to_i
end
total_results() click to toggle source

Return total results.

# File lib/amazon/ecs.rb, line 222
def total_results
  @total_results ||= Element.get(@doc, "//TotalResults").to_i
end