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' }
- @@options =
{}
- @@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
68 69 70 71 |
# File 'lib/amazon/ecs.rb', line 68 def self.configure(&proc) raise ArgumentError, "Block is required." unless block_given? yield @@options end |
.debug ⇒ Object
Get debug flag.
59 60 61 |
# File 'lib/amazon/ecs.rb', line 59 def self.debug @@debug end |
.debug=(dbg) ⇒ Object
Set debug flag to true or false.
64 65 66 |
# File 'lib/amazon/ecs.rb', line 64 def self.debug=(dbg) @@debug = dbg end |
.item_lookup(item_id, opts = {}) ⇒ Object
Search an item by ASIN no.
90 91 92 93 94 95 |
# File 'lib/amazon/ecs.rb', line 90 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].
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/amazon/ecs.rb', line 75 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
49 50 51 |
# File 'lib/amazon/ecs.rb', line 49 def self. @@options end |
.options=(opts) ⇒ Object
Set default search options
54 55 56 |
# File 'lib/amazon/ecs.rb', line 54 def self.(opts) @@options = opts end |
.send_request(opts) ⇒ Object
Generic send request to ECS REST service. You have to specify the :operation parameter.
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/amazon/ecs.rb', line 98 def self.send_request(opts) opts = self..merge(opts) if self. 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 |