Class: Amazon::Ecs
- Inherits:
-
Object
- Object
- Amazon::Ecs
- Defined in:
- lib/amazon/ecs.rb
Defined Under Namespace
Classes: Response
Constant Summary collapse
- VERSION =
'2.6.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', :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', :cn => 'http://webservices.amazon.cn/onca/xml', :es => 'http://webservices.amazon.es/onca/xml', :in => 'http://webservices.amazon.in/onca/xml', :br => 'http://webservices.amazon.com.br/onca/xml', :mx => 'http://webservices.amazon.com.mx/onca/xml', :au => 'http://webservices.amazon.com.au/onca/xml' }
- @@options =
{ :version => "2013-08-01", :service => "AWSECommerceService" }
- @@debug =
ENV['DEBUG_AMAZON_ECS'] || false
- @@hideAPIError =
Error response from Amazon API may contain Access key ID
ENV['HIDE_AMAZON_ECS_API_ERROR'] || false
Class Method Summary collapse
-
.browse_node_lookup(browse_node_id, opts = {}) ⇒ Object
Browse node lookup by node ID.
- .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.
-
.similarity_lookup(item_id, opts = {}) ⇒ Object
Similarity lookup by item ID.
- .validate_request(opts) ⇒ Object
Class Method Details
.browse_node_lookup(browse_node_id, opts = {}) ⇒ Object
Browse node lookup by node ID.
112 113 114 115 116 117 |
# File 'lib/amazon/ecs.rb', line 112 def self.browse_node_lookup(browse_node_id, opts = {}) opts[:operation] = 'BrowseNodeLookup' opts[:browse_node_id] = browse_node_id self.send_request(opts) end |
.configure {|@@options| ... } ⇒ Object
82 83 84 85 |
# File 'lib/amazon/ecs.rb', line 82 def self.configure(&proc) raise ArgumentError, "Block is required." unless block_given? yield @@options end |
.debug ⇒ Object
Get debug flag.
73 74 75 |
# File 'lib/amazon/ecs.rb', line 73 def self.debug @@debug end |
.debug=(dbg) ⇒ Object
Set debug flag to true or false.
78 79 80 |
# File 'lib/amazon/ecs.rb', line 78 def self.debug=(dbg) @@debug = dbg end |
.item_lookup(item_id, opts = {}) ⇒ Object
Search an item by ASIN no.
104 105 106 107 108 109 |
# File 'lib/amazon/ecs.rb', line 104 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].
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/amazon/ecs.rb', line 89 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
63 64 65 |
# File 'lib/amazon/ecs.rb', line 63 def self. @@options end |
.options=(opts) ⇒ Object
Set default search options
68 69 70 |
# File 'lib/amazon/ecs.rb', line 68 def self.(opts) @@options = opts end |
.send_request(opts) ⇒ Object
Generic send request to ECS REST service. You have to specify the :operation parameter.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/amazon/ecs.rb', line 128 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)) log("Response:\n#{res.body}\n\n") ecs_res = Response.new(res.body) unless res.kind_of? Net::HTTPSuccess err_msg = "HTTP Response: #{res.code} #{res.}" err_msg += " - #{ecs_res.error}" if ecs_res.error && !@@hideAPIError raise Amazon::RequestError, err_msg end ecs_res end |
.similarity_lookup(item_id, opts = {}) ⇒ Object
Similarity lookup by item ID.
120 121 122 123 124 125 |
# File 'lib/amazon/ecs.rb', line 120 def self.similarity_lookup(item_id, opts = {}) opts[:operation] = 'SimilarityLookup' opts[:item_id] = item_id self.send_request(opts) end |
.validate_request(opts) ⇒ Object
149 150 151 |
# File 'lib/amazon/ecs.rb', line 149 def self.validate_request(opts) raise Amazon::RequestError, "" if opts[:associate_tag] end |