lib/amazon/ecs.rb in amazon-ecs-2.3.2 vs lib/amazon/ecs.rb in amazon-ecs-2.4.0

- old
+ new

@@ -30,11 +30,11 @@ module Amazon class RequestError < StandardError; end class Ecs - VERSION = '2.3.2' + VERSION = '2.4.0' SERVICE_URLS = { :us => 'http://webservices.amazon.com/onca/xml', :uk => 'http://webservices.amazon.co.uk/onca/xml', :ca => 'http://webservices.amazon.ca/onca/xml', @@ -53,11 +53,11 @@ OpenSSL::Digest.constants.include?( :SHA256 ) OPENSSL_DIGEST = OpenSSL::Digest.new( 'sha256' ) if OPENSSL_DIGEST_SUPPORT @@options = { - :version => "2011-08-01", + :version => "2013-08-01", :service => "AWSECommerceService" } @@debug = false @@ -108,18 +108,26 @@ opts[:item_id] = item_id self.send_request(opts) end - # Search a browse node by BrowseNodeId + # Browse node lookup by node ID. def self.browse_node_lookup(browse_node_id, opts = {}) opts[:operation] = 'BrowseNodeLookup' opts[:browse_node_id] = browse_node_id self.send_request(opts) end + # Similarity lookup by item ID. + def self.similarity_lookup(item_id, opts = {}) + opts[:operation] = 'SimilarityLookup' + opts[:item_id] = item_id + + self.send_request(opts) + end + # Generic send request to ECS REST service. You have to specify the :operation parameter. def self.send_request(opts) opts = self.options.merge(opts) if self.options # Include other required options @@ -153,10 +161,30 @@ # Return Nokogiri::XML::Document object. def doc @doc end + # Return a Nokogiri::XML::NodeSet of elements matching the given path. + def /(path) + elements = @doc/path + return nil if elements.size == 0 + elements + end + + # Return an array of Amazon::Element matching the given path + def get_elements(path) + elements = self./(path) + return unless elements + elements = elements.map{|element| Element.new(element)} + end + + # Return the first element found + def get_element(path) + elements = get_elements(path) + elements[0] if elements + end + # Return true if request is valid. def is_valid_request? Element.get(@doc, "//IsValid") == "True" end @@ -332,15 +360,15 @@ # Pass Nokogiri::XML::Element object def initialize(element) @element = element end - # Returns Nokogiri::XML::Element object + # Return Nokogiri::XML::Element object def elem @element end - # Returns a Nokogiri::XML::NodeSet of elements matching the given path. Example: element/"author". + # Return a Nokogiri::XML::NodeSet of elements matching the given path. Example: element/"author". def /(path) elements = @element/path return nil if elements.size == 0 elements end