dkam-amazon-ecs 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README ADDED
@@ -0,0 +1,107 @@
1
+ == amazon-ecs
2
+
3
+ Generic Amazon E-commerce REST API using Hpricot with configurable
4
+ default options and method call options. Uses Response and
5
+ Element wrapper classes for easy access to REST XML output. It supports ECS 4.0.
6
+
7
+ It is generic, so you can easily extend <tt>Amazon::Ecs</tt> to support
8
+ other not implemented REST operations; and it is also generic because it just wraps around
9
+ Hpricot element object, instead of providing one-to-one object/attributes to XML elements map.
10
+
11
+ If in the future, there is a change in REST XML output structure,
12
+ no changes will be required on <tt>amazon-ecs</tt> library,
13
+ instead you just need to change the element path.
14
+
15
+ Version: 0.5.4
16
+
17
+ == INSTALLATION
18
+
19
+ $ gem install amazon-ecs
20
+
21
+ == EXAMPLE
22
+
23
+ require 'amazon/ecs'
24
+
25
+ # set the default options; options will be camelized and converted to REST request parameters.
26
+ Amazon::Ecs.options = {:aWS_access_key_id => [your access key]}
27
+
28
+ # to generate signed requests include your secret key:
29
+ Amazon::Ecs.options = {:aWS_access_key_id => [your developer token], :aWS_secret_key => [your secret access key]}
30
+
31
+ # alternatively,
32
+ Amazon::Ecs.configure do |options|
33
+ options[:aWS_access_key_id] = [your access key]
34
+ options[:aWS_secret_key] = [you secret key]
35
+ end
36
+
37
+
38
+ # options provided on method call will merge with the default options
39
+ res = Amazon::Ecs.item_search('ruby', {:response_group => 'Medium', :sort => 'salesrank'})
40
+
41
+ # some common response object methods
42
+ res.is_valid_request? # return true if request is valid
43
+ res.has_error? # return true if there is an error
44
+ res.error # return error message if there is any
45
+ res.total_pages # return total pages
46
+ res.total_results # return total results
47
+ res.item_page # return current page no if :item_page option is provided
48
+
49
+ # traverse through each item (Amazon::Element)
50
+ res.items.each do |item|
51
+ # retrieve string value using XML path
52
+ item.get('asin')
53
+ item.get('itemattributes/title')
54
+
55
+ # or return Amazon::Element instance
56
+ atts = item.search_and_convert('itemattributes')
57
+ atts.get('title')
58
+
59
+ # return first author or a string array of authors
60
+ atts.get('author') # 'Author 1'
61
+ atts.get_array('author') # ['Author 1', 'Author 2', ...]
62
+
63
+ # return an hash of children text values with the element names as the keys
64
+ item.get_hash('smallimage') # {:url => ..., :width => ..., :height => ...}
65
+
66
+ # note that '/' returns Hpricot::Elements array object, nil if not found
67
+ reviews = item/'editorialreview'
68
+
69
+ # traverse through Hpricot elements
70
+ reviews.each do |review|
71
+ # Getting hash value out of Hpricot element
72
+ Amazon::Element.get_hash(review) # [:source => ..., :content ==> ...]
73
+
74
+ # Or to get unescaped HTML values
75
+ Amazon::Element.get_unescaped(review, 'source')
76
+ Amazon::Element.get_unescaped(review, 'content')
77
+
78
+ # Or this way
79
+ el = Amazon::Element.new(review)
80
+ el.get_unescaped('source')
81
+ el.get_unescaped('content')
82
+ end
83
+
84
+ # returns Amazon::Element instead of string
85
+ item.search_and_convert('itemattributes').
86
+ end
87
+
88
+ Refer to Amazon ECS documentation for more information on Amazon REST request parameters and XML output:
89
+ http://docs.amazonwebservices.com/AWSEcommerceService/2006-09-13/
90
+
91
+ To get a sample of Amazon REST response XML output, use AWSZone.com scratch pad:
92
+ http://www.awszone.com/scratchpads/aws/ecs.us/index.aws
93
+
94
+ == SOURCE CODES
95
+
96
+ * http://github.com/jugend/amazon-ecs/tree/master
97
+
98
+ == LINKS
99
+
100
+ * http://amazon-ecs.rubyforge.org
101
+ * http://www.pluitsolutions.com/amazon-ecs
102
+
103
+ == LICENSE
104
+
105
+ (The MIT License)
106
+
107
+ Copyright (c) 2006 Herryanto Siatono, Pluit Solutions
@@ -0,0 +1,338 @@
1
+ #--
2
+ # Copyright (c) 2006 Herryanto Siatono, Pluit Solutions
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require 'net/http'
25
+ require 'hpricot'
26
+ require 'cgi'
27
+ require 'openssl'
28
+ require 'base64'
29
+
30
+ module Amazon
31
+ class RequestError < StandardError; end
32
+
33
+ class Ecs
34
+ SERVICE_URLS = {:us => 'http://webservices.amazon.com/onca/xml?',
35
+ :uk => 'http://webservices.amazon.co.uk/onca/xml?',
36
+ :ca => 'http://webservices.amazon.ca/onca/xml?',
37
+ :de => 'http://webservices.amazon.de/onca/xml?',
38
+ :jp => 'http://webservices.amazon.co.jp/onca/xml?',
39
+ :fr => 'http://webservices.amazon.fr/onca/xml?'
40
+ }
41
+
42
+ @@options = {}
43
+ @@debug = false
44
+
45
+ # Default search options
46
+ def self.options
47
+ @@options
48
+ end
49
+
50
+ # Set default search options
51
+ def self.options=(opts)
52
+ @@options = opts
53
+ end
54
+
55
+ # Get debug flag.
56
+ def self.debug
57
+ @@debug
58
+ end
59
+
60
+ # Set debug flag to true or false.
61
+ def self.debug=(dbg)
62
+ @@debug = dbg
63
+ end
64
+
65
+ def self.configure(&proc)
66
+ raise ArgumentError, "Block is required." unless block_given?
67
+ yield @@options
68
+ end
69
+
70
+ # Search amazon items with search terms. Default search index option is 'Books'.
71
+ # For other search type other than keywords, please specify :type => [search type param name].
72
+ def self.item_search(terms, opts = {})
73
+ opts[:operation] = 'ItemSearch'
74
+ opts[:search_index] = opts[:search_index] || 'Books'
75
+
76
+ type = opts.delete(:type)
77
+ if type
78
+ opts[type.to_sym] = terms
79
+ else
80
+ opts[:keywords] = terms
81
+ end
82
+
83
+ self.send_request(opts)
84
+ end
85
+
86
+ # Search an item by ASIN no.
87
+ def self.item_lookup(item_id, opts = {})
88
+ opts[:operation] = 'ItemLookup'
89
+ opts[:item_id] = item_id
90
+
91
+ self.send_request(opts)
92
+ end
93
+
94
+ # Generic send request to ECS REST service. You have to specify the :operation parameter.
95
+ def self.send_request(opts)
96
+ opts = self.options.merge(opts) if self.options
97
+
98
+ # Include other required options
99
+ opts['Timestamp'] = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
100
+ opts['Version'] = "2009-01-06"
101
+ opts['Service'] = "AWSECommerceService"
102
+
103
+ request_url = prepare_url(opts)
104
+ log "Request URL: #{request_url}"
105
+
106
+ res = Net::HTTP.get_response(URI::parse(request_url))
107
+ unless res.kind_of? Net::HTTPSuccess
108
+ raise Amazon::RequestError, "HTTP Response: #{res.code} #{res.message}"
109
+ end
110
+ Response.new(res.body)
111
+ end
112
+
113
+ # Response object returned after a REST call to Amazon service.
114
+ class Response
115
+ # XML input is in string format
116
+ def initialize(xml)
117
+ @doc = Hpricot(xml)
118
+ end
119
+
120
+ # Return Hpricot object.
121
+ def doc
122
+ @doc
123
+ end
124
+
125
+ # Return true if request is valid.
126
+ def is_valid_request?
127
+ (@doc/"isvalid").inner_html == "True"
128
+ end
129
+
130
+ # Return true if response has an error.
131
+ def has_error?
132
+ !(error.nil? || error.empty?)
133
+ end
134
+
135
+ # Return error message.
136
+ def error
137
+ Element.get(@doc, "error/message")
138
+ end
139
+
140
+ # Return error code
141
+ def error_code
142
+ Element.get(@doc, "error/code")
143
+ end
144
+
145
+ # Return an array of Amazon::Element item objects.
146
+ def items
147
+ unless @items
148
+ @items = (@doc/"item").collect {|item| Element.new(item)}
149
+ end
150
+ @items
151
+ end
152
+
153
+ # Return the first item (Amazon::Element)
154
+ def first_item
155
+ items.first
156
+ end
157
+
158
+ # Return current page no if :item_page option is when initiating the request.
159
+ def item_page
160
+ unless @item_page
161
+ @item_page = (@doc/"itemsearchrequest/itempage").inner_html.to_i
162
+ end
163
+ @item_page
164
+ end
165
+
166
+ # Return total results.
167
+ def total_results
168
+ unless @total_results
169
+ @total_results = (@doc/"totalresults").inner_html.to_i
170
+ end
171
+ @total_results
172
+ end
173
+
174
+ # Return total pages.
175
+ def total_pages
176
+ unless @total_pages
177
+ @total_pages = (@doc/"totalpages").inner_html.to_i
178
+ end
179
+ @total_pages
180
+ end
181
+ end
182
+
183
+ protected
184
+ def self.log(s)
185
+ return unless self.debug
186
+ if defined? RAILS_DEFAULT_LOGGER
187
+ RAILS_DEFAULT_LOGGER.error(s)
188
+ elsif defined? LOGGER
189
+ LOGGER.error(s)
190
+ else
191
+ puts s
192
+ end
193
+ end
194
+
195
+ private
196
+ def self.prepare_url(opts)
197
+ country = opts.delete(:country)
198
+ country = (country.nil?) ? 'us' : country
199
+ request_url = SERVICE_URLS[country.to_sym]
200
+ raise Amazon::RequestError, "Invalid country '#{country}'" unless request_url
201
+
202
+ secret_key = opts.delete(:aWS_secret_key)
203
+ request_host = URI.parse(request_url).host
204
+
205
+ qs = ''
206
+ opts.collect {|a,b| [camelize(a.to_s), b.to_s] }.sort {|c,d| c[0].to_s <=> d[0].to_s}.each {|e|
207
+ log "Adding #{e[0]}=#{e[1]}"
208
+ next unless e[1]
209
+ e[1] = e[1].join(',') if e[1].is_a? Array
210
+ v=URI.encode(e[1].to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
211
+ qs << "&" unless qs.length == 0
212
+ qs << "#{e[0]}=#{v}"
213
+ }
214
+
215
+ signature = ''
216
+ unless secret_key.nil?
217
+ request_to_sign="GET
218
+ #{request_host}
219
+ /onca/xml
220
+ #{qs}"
221
+ signature = "&Signature=#{sign_request(request_to_sign, secret_key)}"
222
+ end
223
+
224
+ "#{request_url}#{qs}#{signature}"
225
+ end
226
+
227
+ def self.camelize(s)
228
+ s.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
229
+ end
230
+
231
+ def self.sign_request(url, key)
232
+ return nil if key.nil?
233
+ sha_digest=OpenSSL::Digest::Digest.new('sha256')
234
+ signature = URI.escape( Base64.encode64( OpenSSL::HMAC.digest(sha_digest, key, url) ).strip, Regexp.new("[+=]") )
235
+ return signature
236
+ end
237
+
238
+ end
239
+
240
+ # Internal wrapper class to provide convenient method to access Hpricot element value.
241
+ class Element
242
+ # Pass Hpricot::Elements object
243
+ def initialize(element)
244
+ @element = element
245
+ end
246
+
247
+ # Returns Hpricot::Elments object
248
+ def elem
249
+ @element
250
+ end
251
+
252
+ # Find Hpricot::Elements matching the given path. Example: element/"author".
253
+ def /(path)
254
+ elements = @element/path
255
+ return nil if elements.size == 0
256
+ elements
257
+ end
258
+
259
+ # Find Hpricot::Elements matching the given path, and convert to Amazon::Element.
260
+ # Returns an array Amazon::Elements if more than Hpricot::Elements size is greater than 1.
261
+ def search_and_convert(path)
262
+ elements = self./(path)
263
+ return unless elements
264
+ elements = elements.map{|element| Element.new(element)}
265
+ return elements.first if elements.size == 1
266
+ elements
267
+ end
268
+
269
+ # Get the text value of the given path, leave empty to retrieve current element value.
270
+ def get(path='')
271
+ Element.get(@element, path)
272
+ end
273
+
274
+ # Get the unescaped HTML text of the given path.
275
+ def get_unescaped(path='')
276
+ Element.get_unescaped(@element, path)
277
+ end
278
+
279
+ # Get the array values of the given path.
280
+ def get_array(path='')
281
+ Element.get_array(@element, path)
282
+ end
283
+
284
+ # Get the children element text values in hash format with the element names as the hash keys.
285
+ def get_hash(path='')
286
+ Element.get_hash(@element, path)
287
+ end
288
+
289
+ # Similar to #get, except an element object must be passed-in.
290
+ def self.get(element, path='')
291
+ return unless element
292
+ result = element.at(path)
293
+ result = result.inner_html if result
294
+ result
295
+ end
296
+
297
+ # Similar to #get_unescaped, except an element object must be passed-in.
298
+ def self.get_unescaped(element, path='')
299
+ result = get(element, path)
300
+ CGI::unescapeHTML(result) if result
301
+ end
302
+
303
+ # Similar to #get_array, except an element object must be passed-in.
304
+ def self.get_array(element, path='')
305
+ return unless element
306
+
307
+ result = element/path
308
+ if (result.is_a? Hpricot::Elements) || (result.is_a? Array)
309
+ parsed_result = []
310
+ result.each {|item|
311
+ parsed_result << Element.get(item)
312
+ }
313
+ parsed_result
314
+ else
315
+ [Element.get(result)]
316
+ end
317
+ end
318
+
319
+ # Similar to #get_hash, except an element object must be passed-in.
320
+ def self.get_hash(element, path='')
321
+ return unless element
322
+
323
+ result = element.at(path)
324
+ if result
325
+ hash = {}
326
+ result = result.children
327
+ result.each do |item|
328
+ hash[item.name.to_sym] = item.inner_html
329
+ end
330
+ hash
331
+ end
332
+ end
333
+
334
+ def to_s
335
+ elem.to_s if elem
336
+ end
337
+ end
338
+ end
@@ -0,0 +1,117 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class Amazon::EcsTest < Test::Unit::TestCase
4
+
5
+ AWS_ACCESS_KEY_ID = ''
6
+ AWS_SECRET_KEY = ''
7
+
8
+ raise "Please specify set your AWS_ACCESS_KEY_ID" if AWS_ACCESS_KEY_ID.empty?
9
+ raise "Please specify set your AWS_SECRET_KEY" if AWS_SECRET_KEY.empty?
10
+
11
+ Amazon::Ecs.configure do |options|
12
+ options[:response_group] = 'Large'
13
+ options[:aWS_access_key_id] = AWS_ACCESS_KEY_ID
14
+ options[:aWS_secret_key] = AWS_SECRET_KEY
15
+ end
16
+
17
+ ## Test item_search
18
+
19
+ def test_item_search
20
+ resp = Amazon::Ecs.item_search('ruby')
21
+ assert(resp.is_valid_request?)
22
+ assert(resp.total_results >= 3600)
23
+ assert(resp.total_pages >= 360)
24
+
25
+ signature_elements = (resp.doc/"arguments/argument").select {|ele| ele.attributes['Name'] =~ /Signature/ }.length
26
+ assert(signature_elements == 1 )
27
+ end
28
+
29
+ def test_item_search_with_paging
30
+ resp = Amazon::Ecs.item_search('ruby', :item_page => 2)
31
+ assert resp.is_valid_request?
32
+ assert 2, resp.item_page
33
+ end
34
+
35
+ def test_item_search_with_invalid_request
36
+ resp = Amazon::Ecs.item_search(nil)
37
+ assert !resp.is_valid_request?
38
+ end
39
+
40
+ def test_item_search_with_no_result
41
+ resp = Amazon::Ecs.item_search('afdsafds')
42
+
43
+ assert resp.is_valid_request?
44
+ assert_equal "We did not find any matches for your request.",
45
+ resp.error
46
+ end
47
+
48
+ def test_item_search_uk
49
+ resp = Amazon::Ecs.item_search('ruby', :country => :uk)
50
+ assert resp.is_valid_request?
51
+ end
52
+
53
+ def test_item_search_by_author
54
+ resp = Amazon::Ecs.item_search('dave', :type => :author)
55
+ assert resp.is_valid_request?
56
+ end
57
+
58
+ def test_item_get
59
+ resp = Amazon::Ecs.item_search("0974514055")
60
+ item = resp.first_item
61
+
62
+ # test get
63
+ assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition",
64
+ item.get("itemattributes/title")
65
+
66
+ # test get_array
67
+ assert_equal ['Dave Thomas', 'Chad Fowler', 'Andy Hunt'],
68
+ item.get_array("author")
69
+
70
+ # test get_hash
71
+ small_image = item.get_hash("smallimage")
72
+
73
+ assert_equal 3, small_image.keys.size
74
+ assert_match ".jpg", small_image[:url]
75
+ assert_equal "75", small_image[:height]
76
+ assert_equal "59", small_image[:width]
77
+
78
+ # test /
79
+ reviews = item/"editorialreview"
80
+ reviews.each do |review|
81
+ # returns unescaped HTML content, Hpricot escapes all text values
82
+ assert Amazon::Element.get_unescaped(review, 'source')
83
+ assert Amazon::Element.get_unescaped(review, 'content')
84
+ end
85
+ end
86
+
87
+ ## Test item_lookup
88
+ def test_item_lookup
89
+ resp = Amazon::Ecs.item_lookup('0974514055')
90
+ assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition",
91
+ resp.first_item.get("itemattributes/title")
92
+ end
93
+
94
+ def test_item_lookup_with_invalid_request
95
+ resp = Amazon::Ecs.item_lookup(nil)
96
+ assert resp.has_error?
97
+ assert resp.error
98
+ end
99
+
100
+ def test_item_lookup_with_no_result
101
+ resp = Amazon::Ecs.item_lookup('abc')
102
+
103
+ assert resp.is_valid_request?
104
+ assert_match(/ABC is not a valid value for ItemId/, resp.error)
105
+ end
106
+
107
+ def test_search_and_convert
108
+ resp = Amazon::Ecs.item_lookup('0974514055')
109
+ title = resp.first_item.get("itemattributes/title")
110
+ authors = resp.first_item.search_and_convert("author")
111
+
112
+ assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition", title
113
+ assert authors.is_a?(Array)
114
+ assert 3, authors.size
115
+ assert_equal "Dave Thomas", authors.first.get
116
+ end
117
+ end
@@ -0,0 +1,110 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class Amazon::EcsTest < Test::Unit::TestCase
4
+
5
+ AWS_ACCESS_KEY_ID = ''
6
+ raise "Please specify set your AWS_ACCESS_KEY_ID" if AWS_ACCESS_KEY_ID.empty?
7
+
8
+ Amazon::Ecs.configure do |options|
9
+ options[:response_group] = 'Large'
10
+ options[:aWS_access_key_id] = AWS_ACCESS_KEY_ID
11
+ end
12
+
13
+ ## Test item_search
14
+
15
+ def test_item_search
16
+ resp = Amazon::Ecs.item_search('ruby')
17
+ assert(resp.is_valid_request?)
18
+ assert(resp.total_results >= 3600)
19
+ assert(resp.total_pages >= 360)
20
+ end
21
+
22
+ def test_item_search_with_paging
23
+ resp = Amazon::Ecs.item_search('ruby', :item_page => 2)
24
+ assert resp.is_valid_request?
25
+ assert 2, resp.item_page
26
+ end
27
+
28
+ def test_item_search_with_invalid_request
29
+ resp = Amazon::Ecs.item_search(nil)
30
+ assert !resp.is_valid_request?
31
+ end
32
+
33
+ def test_item_search_with_no_result
34
+ resp = Amazon::Ecs.item_search('afdsafds')
35
+
36
+ assert resp.is_valid_request?
37
+ assert_equal "We did not find any matches for your request.",
38
+ resp.error
39
+ end
40
+
41
+ def test_item_search_uk
42
+ resp = Amazon::Ecs.item_search('ruby', :country => :uk)
43
+ assert resp.is_valid_request?
44
+ end
45
+
46
+ def test_item_search_by_author
47
+ resp = Amazon::Ecs.item_search('dave', :type => :author)
48
+ assert resp.is_valid_request?
49
+ end
50
+
51
+ def test_item_get
52
+ resp = Amazon::Ecs.item_search("0974514055")
53
+ item = resp.first_item
54
+
55
+ # test get
56
+ assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition",
57
+ item.get("itemattributes/title")
58
+
59
+ # test get_array
60
+ assert_equal ['Dave Thomas', 'Chad Fowler', 'Andy Hunt'],
61
+ item.get_array("author")
62
+
63
+ # test get_hash
64
+ small_image = item.get_hash("smallimage")
65
+
66
+ assert_equal 3, small_image.keys.size
67
+ assert_match ".jpg", small_image[:url]
68
+ assert_equal "75", small_image[:height]
69
+ assert_equal "59", small_image[:width]
70
+
71
+ # test /
72
+ reviews = item/"editorialreview"
73
+ reviews.each do |review|
74
+ # returns unescaped HTML content, Hpricot escapes all text values
75
+ assert Amazon::Element.get_unescaped(review, 'source')
76
+ assert Amazon::Element.get_unescaped(review, 'content')
77
+ end
78
+ end
79
+
80
+ ## Test item_lookup
81
+ def test_item_lookup
82
+ resp = Amazon::Ecs.item_lookup('0974514055')
83
+ assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition",
84
+ resp.first_item.get("itemattributes/title")
85
+ end
86
+
87
+ def test_item_lookup_with_invalid_request
88
+ resp = Amazon::Ecs.item_lookup(nil)
89
+ assert resp.has_error?
90
+ assert resp.error
91
+ end
92
+
93
+ def test_item_lookup_with_no_result
94
+ resp = Amazon::Ecs.item_lookup('abc')
95
+
96
+ assert resp.is_valid_request?
97
+ assert_match(/ABC is not a valid value for ItemId/, resp.error)
98
+ end
99
+
100
+ def test_search_and_convert
101
+ resp = Amazon::Ecs.item_lookup('0974514055')
102
+ title = resp.first_item.get("itemattributes/title")
103
+ authors = resp.first_item.search_and_convert("author")
104
+
105
+ assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition", title
106
+ assert authors.is_a?(Array)
107
+ assert 3, authors.size
108
+ assert_equal "Dave Thomas", authors.first.get
109
+ end
110
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/amazon/ecs'
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dkam-amazon-ecs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.5
5
+ platform: ruby
6
+ authors:
7
+ - Herryanto Siatono
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-21 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Generic Amazon E-commerce Service (ECS) REST API. Supports ECS 4.0.
17
+ email: herryanto@pluitsolutions.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - lib/amazon
26
+ - lib/amazon/ecs.rb
27
+ - test/amazon
28
+ - test/amazon/ecs_test.rb
29
+ - test/amazon/ecs_signature_test.rb
30
+ - test/test_helper.rb
31
+ - README
32
+ has_rdoc: true
33
+ homepage: http://amazon-ecs.rubyforge.net/
34
+ post_install_message:
35
+ rdoc_options:
36
+ - --inline-source
37
+ - --charset=UTF-8
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ requirements: []
53
+
54
+ rubyforge_project:
55
+ rubygems_version: 1.2.0
56
+ signing_key:
57
+ specification_version: 2
58
+ summary: Generic Amazon E-commerce Service (ECS) REST API. Supports ECS 4.0.
59
+ test_files: []
60
+