Class: Amazon::Ecs
- Inherits:
-
Object
- Object
- Amazon::Ecs
- Defined in:
- lib/amazon/ecs.rb
Defined Under Namespace
Classes: Response
Constant Summary collapse
- 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?', :it => 'http://webservices.amazon.it/onca/xml?' }
- OPENSSL_DIGEST_SUPPORT =
OpenSSL::Digest.constants.include?( 'SHA256' ) || OpenSSL::Digest.constants.include?( :SHA256 )
- OPENSSL_DIGEST =
OpenSSL::Digest::Digest.new( 'sha256' )
- @@options =
{ :version => "2010-10-01", :service => "AWSECommerceService" }
- @@debug =
false
Class Method Summary collapse
- .configure {|@@options| ... } ⇒ Object
-
.debug ⇒ Object
Get debug flag.
-
.debug=(dbg) ⇒ Object
Set debug flag to true or false.
-
.item_lookup(item_id, opts = {}) ⇒ Object
Search an item by ASIN no.
-
.item_search(terms, opts = {}) ⇒ Object
Search amazon items with search terms.
-
.options ⇒ Object
Default search options.
-
.options=(opts) ⇒ Object
Set default search options.
-
.send_request(opts) ⇒ Object
Generic send request to ECS REST service.
Class Method Details
.configure {|@@options| ... } ⇒ Object
76 77 78 79 |
# File 'lib/amazon/ecs.rb', line 76 def self.configure(&proc) raise ArgumentError, "Block is required." unless block_given? yield @@options end |
.debug ⇒ Object
Get debug flag.
67 68 69 |
# File 'lib/amazon/ecs.rb', line 67 def self.debug @@debug end |
.debug=(dbg) ⇒ Object
Set debug flag to true or false.
72 73 74 |
# File 'lib/amazon/ecs.rb', line 72 def self.debug=(dbg) @@debug = dbg end |
.item_lookup(item_id, opts = {}) ⇒ Object
Search an item by ASIN no.
98 99 100 101 102 103 |
# File 'lib/amazon/ecs.rb', line 98 def self.item_lookup(item_id, opts = {}) opts[:operation] = 'ItemLookup' opts[:item_id] = item_id self.send_request(opts) end |
.item_search(terms, opts = {}) ⇒ Object
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].
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/amazon/ecs.rb', line 83 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 |
.options ⇒ Object
Default search options
57 58 59 |
# File 'lib/amazon/ecs.rb', line 57 def self. @@options end |
.options=(opts) ⇒ Object
Set default search options
62 63 64 |
# File 'lib/amazon/ecs.rb', line 62 def self.(opts) @@options = opts end |
.send_request(opts) ⇒ Object
Generic send request to ECS REST service. You have to specify the :operation parameter.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/amazon/ecs.rb', line 106 def self.send_request(opts) opts = self..merge(opts) if self. # 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.}" end Response.new(res.body) end |