Class | Amazon::Ecs |
In: |
lib/amazon/ecs.rb
|
Parent: | Object |
SERVICE_URLS | = | {:us => 'http://webservices.amazon.com/onca/xml?', :uk => 'http://webservices.amazon.co.uk/onca/xml?', :ca => 'http://webservices.amazon.ca/onca/xml?', :de => 'http://webservices.amazon.de/onca/xml?', :jp => 'http://webservices.amazon.co.jp/onca/xml?', :fr => 'http://webservices.amazon.fr/onca/xml?' |
OPENSSL_DIGEST_SUPPORT | = | OpenSSL::Digest.constants.include?( 'SHA256' ) || OpenSSL::Digest.constants.include?( :SHA256 ) |
OPENSSL_DIGEST | = | OpenSSL::Digest::Digest.new( 'sha256' ) if OPENSSL_DIGEST_SUPPORT |
# File lib/amazon/ecs.rb, line 75 def self.configure(&proc) raise ArgumentError, "Block is required." unless block_given? yield @@options end
Search an item by ASIN no.
# File lib/amazon/ecs.rb, line 97 def self.item_lookup(item_id, opts = {}) opts[:operation] = 'ItemLookup' opts[:item_id] = item_id self.send_request(opts) end
Search amazon items with search terms. Default search index option is ‘Books’. For other search type other than keywords, please specify :type => [search type param name].
# File lib/amazon/ecs.rb, line 82 def self.item_search(terms, opts = {}) opts[:operation] = 'ItemSearch' opts[:search_index] = opts[:search_index] || 'Books' type = opts.delete(:type) if type opts[type.to_sym] = terms else opts[:keywords] = terms end self.send_request(opts) end
Generic send request to ECS REST service. You have to specify the :operation parameter.
# File lib/amazon/ecs.rb, line 105 def self.send_request(opts) opts = self.options.merge(opts) if self.options # Include other required options opts[:timestamp] = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ") request_url = prepare_url(opts) log "Request URL: #{request_url}" res = Net::HTTP.get_response(URI::parse(request_url)) unless res.kind_of? Net::HTTPSuccess raise Amazon::RequestError, "HTTP Response: #{res.code} #{res.message}" end Response.new(res.body) end