papercavalier-ruby-aaws 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/.gitignore +3 -0
  2. data/COPYING +340 -0
  3. data/INSTALL +260 -0
  4. data/NEWS +808 -0
  5. data/README +679 -0
  6. data/README.rdoc +140 -0
  7. data/Rakefile +17 -0
  8. data/VERSION.yml +5 -0
  9. data/example/batch_operation +28 -0
  10. data/example/browse_node_lookup1 +46 -0
  11. data/example/customer_content_lookup1 +27 -0
  12. data/example/customer_content_search1 +21 -0
  13. data/example/example1 +78 -0
  14. data/example/help1 +24 -0
  15. data/example/item_lookup1 +56 -0
  16. data/example/item_lookup2 +56 -0
  17. data/example/item_search1 +30 -0
  18. data/example/item_search2 +37 -0
  19. data/example/item_search3 +23 -0
  20. data/example/list_lookup1 +29 -0
  21. data/example/list_search1 +30 -0
  22. data/example/multiple_operation1 +69 -0
  23. data/example/seller_listing_lookup1 +30 -0
  24. data/example/seller_listing_search1 +29 -0
  25. data/example/seller_lookup1 +45 -0
  26. data/example/shopping_cart1 +42 -0
  27. data/example/similarity_lookup1 +48 -0
  28. data/example/tag_lookup1 +34 -0
  29. data/example/transaction_lookup1 +25 -0
  30. data/example/vehicle_search +22 -0
  31. data/lib/amazon.rb +165 -0
  32. data/lib/amazon/aws.rb +1493 -0
  33. data/lib/amazon/aws/cache.rb +141 -0
  34. data/lib/amazon/aws/search.rb +464 -0
  35. data/lib/amazon/aws/shoppingcart.rb +537 -0
  36. data/lib/amazon/locale.rb +102 -0
  37. data/test/setup.rb +56 -0
  38. data/test/tc_amazon.rb +20 -0
  39. data/test/tc_aws.rb +160 -0
  40. data/test/tc_browse_node_lookup.rb +49 -0
  41. data/test/tc_customer_content_lookup.rb +49 -0
  42. data/test/tc_help.rb +44 -0
  43. data/test/tc_item_lookup.rb +47 -0
  44. data/test/tc_item_search.rb +105 -0
  45. data/test/tc_list_lookup.rb +60 -0
  46. data/test/tc_list_search.rb +44 -0
  47. data/test/tc_multiple_operation.rb +375 -0
  48. data/test/tc_operation_request.rb +64 -0
  49. data/test/tc_seller_listing_lookup.rb +47 -0
  50. data/test/tc_seller_listing_search.rb +55 -0
  51. data/test/tc_seller_lookup.rb +44 -0
  52. data/test/tc_serialisation.rb +107 -0
  53. data/test/tc_shopping_cart.rb +214 -0
  54. data/test/tc_similarity_lookup.rb +48 -0
  55. data/test/tc_tag_lookup.rb +24 -0
  56. data/test/tc_transaction_lookup.rb +24 -0
  57. data/test/tc_vehicle_operations.rb +118 -0
  58. data/test/ts_aws.rb +24 -0
  59. metadata +141 -0
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: item_lookup2,v 1.5 2010/02/20 16:49:12 ianmacd Exp $
4
+
5
+ require 'amazon/aws'
6
+ require 'amazon/aws/search'
7
+
8
+ include Amazon::AWS
9
+ include Amazon::AWS::Search
10
+
11
+ # Example of a batch operation.
12
+ #
13
+ # The MerchantId restriction is to ensure that we retrieve only items that
14
+ # are for sale by Amazon. This is important when we later want to retrieve the
15
+ # availability status.
16
+ #
17
+ il = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000065RSW',
18
+ 'MerchantId' => 'Amazon' } )
19
+ il2 = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000A1INIU',
20
+ 'MerchantId' => 'Amazon' } )
21
+ il.batch( il2 )
22
+
23
+ # You can have multiple response groups.
24
+ #
25
+ il.response_group = ResponseGroup.new( 'Medium', 'Offers', 'Reviews' )
26
+
27
+ req = Request.new
28
+ req.locale = 'us'
29
+
30
+ resp = req.search( il )
31
+ item_sets = resp.item_lookup_response[0].items
32
+
33
+ item_sets.each do |item_set|
34
+ item_set.item.each do |item|
35
+ attribs = item.item_attributes[0]
36
+ puts attribs.label
37
+ if attribs.list_price
38
+ puts attribs.title, attribs.list_price[0].formatted_price
39
+ end
40
+
41
+ # Availability has become a cumbersome thing to retrieve in AWSv4.
42
+ #
43
+ puts 'Availability: %s' %
44
+ [ item.offers[0].offer[0].offer_listing[0].availability ]
45
+ puts 'Average rating: %s' % [ item.customer_reviews[0].average_rating ]
46
+ puts 'Reviewed by %s customers.' %
47
+ [ item.customer_reviews[0].total_reviews ]
48
+
49
+ puts 'Customers said:'
50
+ item.customer_reviews[0].review.each do |review|
51
+ puts ' %s (%s votes)' % [ review.summary, review.total_votes ]
52
+ end
53
+
54
+ puts
55
+ end
56
+ end
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: item_search1,v 1.5 2010/02/20 16:49:12 ianmacd Exp $
4
+
5
+ require 'amazon/aws/search'
6
+
7
+ include Amazon::AWS
8
+ include Amazon::AWS::Search
9
+
10
+ is = ItemSearch.new( 'Books', { 'Title' => 'Ruby' } )
11
+ is.response_group = ResponseGroup.new( 'Large' )
12
+
13
+ req = Request.new
14
+ req.locale = 'uk'
15
+
16
+ resp = req.search( is )
17
+
18
+ items = resp.item_search_response[0].items[0].item
19
+
20
+ # Available properties for first item:
21
+ #
22
+ puts items[0].properties
23
+
24
+ items.each do |item|
25
+ attribs = item.item_attributes[0]
26
+ puts attribs.label
27
+ if attribs.list_price
28
+ puts attribs.title, attribs.list_price[0].formatted_price, ''
29
+ end
30
+ end
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: item_search2,v 1.5 2010/02/20 16:49:13 ianmacd Exp $
4
+
5
+ require 'amazon/aws/search'
6
+
7
+ include Amazon::AWS
8
+ include Amazon::AWS::Search
9
+
10
+ # We can use symbols instead of string.
11
+ #
12
+ is = ItemSearch.new( :Music, { :Artist => 'Stranglers' } )
13
+ is.response_group = ResponseGroup.new( :Medium )
14
+
15
+ req = Request.new
16
+ req.locale = 'uk'
17
+
18
+ resp = req.search( is, :ALL_PAGES )
19
+
20
+ # Use of :ALL_PAGES means an array of responses is returned, one per page.
21
+ #
22
+ items = resp.collect { |r| r.item_search_response[0].items[0].item }.flatten
23
+
24
+ printf( "Search returned %d items.\n", items.size )
25
+
26
+ items.each do |item|
27
+ attribs = item.item_attributes[0]
28
+ puts '%s %s' % [ attribs.title, ( attribs.format ?
29
+ "(#{attribs.format})" : '' ) ]
30
+ puts '%s (%s)' % [ attribs.manufacturer, attribs.binding ]
31
+ puts 'Release date: %s' % [ attribs.release_date ]
32
+ puts attribs.list_price[0].formatted_price if attribs.list_price
33
+ if item.editorial_reviews
34
+ puts item.editorial_reviews[0].editorial_review[0].content
35
+ end
36
+ puts
37
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: item_search3,v 1.4 2010/02/20 16:49:13 ianmacd Exp $
4
+
5
+ require 'amazon/aws/search'
6
+
7
+ include Amazon::AWS
8
+ include Amazon::AWS::Search
9
+
10
+ is = ItemSearch.new( 'Baby', { 'Keywords' => 'pants',
11
+ 'MinimumPrice' => '2500',
12
+ 'MaximumPrice' => '4999' } )
13
+ is.response_group = ResponseGroup.new( 'Small' )
14
+
15
+ req = Request.new
16
+ req.locale = 'us'
17
+
18
+ resp = req.search( is )
19
+ items = resp.item_search_response[0].items[0].item
20
+
21
+ printf( "Search returned %d items.\n", items.size )
22
+
23
+ items.each { |item| puts item, '' }
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: list_lookup1,v 1.2 2010/02/20 16:49:13 ianmacd Exp $
4
+
5
+ require 'amazon/aws/search'
6
+
7
+ include Amazon::AWS
8
+ include Amazon::AWS::Search
9
+
10
+ ll = ListLookup.new( '3P722DU4KUPCP', 'Listmania' )
11
+ ll.response_group = ResponseGroup.new( 'ListInfo', 'Small' )
12
+
13
+ req = Request.new
14
+ req.locale = 'us'
15
+
16
+ resp = req.search( ll )
17
+ list = resp.list_lookup_response[0].lists[0].list
18
+
19
+ puts 'List Title: %s' % [ list.list_name ]
20
+ puts 'List created: %s' % [ list.date_created ]
21
+ puts 'List ID: %s' % [ list.list_id ]
22
+ puts 'URL: %s' % [ list.list_url ]
23
+ puts '%s items on list.' % [ list.total_items ]
24
+ puts
25
+
26
+ list.list_item.each_with_index do |it, idx|
27
+ att = it.item.item_attributes
28
+ printf( "%d. %s (%s)\n", idx + 1, att.title, att.product_group )
29
+ end
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: list_search1,v 1.4 2010/02/20 16:49:13 ianmacd Exp $
4
+
5
+ require 'amazon/aws/search'
6
+
7
+ include Amazon::AWS
8
+ include Amazon::AWS::Search
9
+
10
+ person = 'Peter Duff'
11
+
12
+ ls = ListSearch.new( 'WishList', { 'Name' => person } )
13
+ ls.response_group = ResponseGroup.new( 'ListInfo' )
14
+
15
+ req = Request.new
16
+ req.locale = 'us'
17
+
18
+ resp = req.search( ls )
19
+ lists = resp.list_search_response[0].lists[0].list
20
+
21
+ puts '%s returns the following lists:' % [ person ]
22
+
23
+ lists.each do |list|
24
+ puts ' %s' % [ list.customer_name ]
25
+ puts ' List created: %s' % [ list.date_created ]
26
+ puts ' List ID: %s' % [ list.list_id ]
27
+ puts ' URL: %s' % [ list.list_url ]
28
+ puts ' %s items on list.' % [ list.total_items ]
29
+ puts
30
+ end
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: multiple_operation1,v 1.3 2010/02/20 16:49:13 ianmacd Exp $
4
+
5
+ require 'amazon/aws/search'
6
+
7
+ include Amazon::AWS
8
+ include Amazon::AWS::Search
9
+
10
+ # Example of a batch operation, using the ASIN as the shared ID.
11
+ #
12
+ # The MerchantId restriction is to ensure that we retrieve only items that
13
+ # are for sale by Amazon. This is important when we later want to retrieve the
14
+ # availability status.
15
+ #
16
+ il = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000AE4QEC',
17
+ 'MerchantId' => 'Amazon' } )
18
+ il2 = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000051WBE',
19
+ 'MerchantId' => 'Amazon' } )
20
+ il.batch( il2 )
21
+ is = ItemSearch.new( 'Books', { 'Title' => 'Ruby' } )
22
+
23
+ mo = MultipleOperation.new( is, il )
24
+
25
+ # You can have multiple response groups and apply them to all encapsulated
26
+ # operations.
27
+ #
28
+ mo.response_group = ResponseGroup.new( 'Medium', 'Offers', 'Reviews' )
29
+
30
+ req = Request.new
31
+ req.locale = 'uk'
32
+ resp = req.search( mo )
33
+
34
+ # Items returned by the ItemSearch.
35
+ #
36
+ is_item_sets = resp.multi_operation_response.item_search_response[0].items
37
+
38
+ # Items returned by the ItemLookup.
39
+ #
40
+ il_item_sets = resp.multi_operation_response.item_lookup_response[0].items
41
+
42
+ item_sets = is_item_sets + il_item_sets
43
+
44
+ item_sets.each do |item_set|
45
+ item_set.item.each do |item|
46
+ attribs = item.item_attributes[0]
47
+ puts attribs.label
48
+ if attribs.list_price
49
+ puts attribs.title, attribs.list_price[0].formatted_price
50
+ end
51
+
52
+ # Availability has become a cumbersome thing to retrieve in AWSv4.
53
+ #
54
+ puts 'Availability: %s' %
55
+ [ item.offers[0].offer[0].offer_listing[0].availability ]
56
+
57
+ if item.customer_reviews
58
+ puts 'Average rating: %s' % [ item.customer_reviews[0].average_rating ]
59
+ puts 'Reviewed by %s customers.' %
60
+ [ item.customer_reviews[0].total_reviews ]
61
+ puts 'Customers said:'
62
+ item.customer_reviews[0].review.each do |review|
63
+ puts ' %s (%s votes)' % [ review.summary, review.total_votes ]
64
+ end
65
+ end
66
+
67
+ puts
68
+ end
69
+ end
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: seller_listing_lookup1,v 1.2 2010/02/20 16:49:13 ianmacd Exp $
4
+
5
+ require 'amazon/aws/search'
6
+
7
+ include Amazon::AWS
8
+ include Amazon::AWS::Search
9
+
10
+ seller_id = 'AP8U6Y3PYQ9VO'
11
+ artist = 'Killing Joke'
12
+ sll = SellerListingLookup.new( seller_id, 'ASIN',
13
+ { 'Id' => 'B0009RRRC8' } )
14
+ sll.response_group = ResponseGroup.new( 'SellerListing' )
15
+
16
+ req = Request.new
17
+ req.locale = 'uk'
18
+
19
+ resp = req.search( sll )
20
+
21
+ # Yawn. This is verbose.
22
+ #
23
+
24
+ seller_id = resp.seller_listing_lookup_response[0].seller_listings[0].
25
+ request[0].seller_listing_lookup_request[0].seller_id
26
+ item = resp.seller_listing_lookup_response[0].seller_listings[0].
27
+ seller_listing[0]
28
+
29
+ puts 'Seller %s is selling the following item by %s:' % [ seller_id, artist ]
30
+ puts item
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: seller_listing_search1,v 1.5 2010/02/20 16:49:13 ianmacd Exp $
4
+
5
+ require 'amazon/aws/search'
6
+
7
+ include Amazon::AWS
8
+ include Amazon::AWS::Search
9
+
10
+ seller_id = 'AP8U6Y3PYQ9VO'
11
+ artist = 'Killing Joke'
12
+
13
+ sls = SellerListingSearch.new( seller_id, { 'Keywords' => artist } )
14
+ sls.response_group = ResponseGroup.new( 'SellerListing' )
15
+
16
+ req = Request.new
17
+ req.locale = 'uk'
18
+
19
+ resp = req.search( sls )
20
+
21
+ # Yawn. This is verbose.
22
+ #
23
+ seller_id = resp.seller_listing_search_response[0].seller_listings[0].
24
+ request[0].seller_listing_search_request[0].seller_id
25
+ items = resp.seller_listing_search_response[0].seller_listings[0].
26
+ seller_listing
27
+
28
+ puts 'Seller %s is selling the following items by %s:' % [ seller_id, artist ]
29
+ items.each { |item| puts item, '-' * 80 }
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: seller_lookup1,v 1.2 2010/02/20 16:49:13 ianmacd Exp $
4
+
5
+ require 'amazon/aws/search'
6
+
7
+ include Amazon::AWS
8
+ include Amazon::AWS::Search
9
+
10
+ def display_properties(root, indent=0)
11
+ if root[0].respond_to? :properties
12
+ printf( 'Property %s =', root[0] )
13
+ root[0].properties.each do |pr|
14
+ display_properties( pr, indent + 2 )
15
+ end
16
+ else
17
+ printf( "Property %s = %s.\n", root, root.to_h[root] )
18
+ end
19
+ end
20
+
21
+ sl = SellerLookup.new( 'A3QFR0K2KCB7EG' )
22
+ sl.response_group = ResponseGroup.new( 'Seller' )
23
+
24
+ req = Request.new
25
+ req.locale = 'us'
26
+
27
+ resp = req.search( sl ).seller_lookup_response
28
+
29
+ seller = resp.sellers.seller
30
+
31
+ seller.properties.each do |pr|
32
+ if seller[0][pr][0].properties.empty?
33
+ printf( "%s = %s.\n", pr, seller[0][pr] )
34
+ else
35
+ seller[0][pr][0].properties.each do |nest1|
36
+ if seller[0][pr][0][nest1][0].properties.empty?
37
+ printf( "%s = %s.\n", nest1, seller[0][pr][0][nest1][0] )
38
+ else
39
+ seller[0][pr][0][nest1][0].properties.each do |nest2|
40
+ printf( "%s = %s.\n", nest2, seller[0][pr][0][nest1][0][nest2] )
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: shopping_cart1,v 1.3 2010/02/20 16:49:13 ianmacd Exp $
4
+
5
+ require 'amazon/aws/search'
6
+ require 'amazon/aws/shoppingcart'
7
+
8
+ include Amazon::AWS
9
+ #include Amazon::AWS::Search
10
+ include Amazon::AWS::ShoppingCart
11
+
12
+ cart = Cart.new
13
+ cart.locale = 'uk'
14
+
15
+ cart.cart_create( :ASIN, 'B00151HZA6', 3, false,
16
+ { 'B000WC4AH0' => 2 ,
17
+ 'B00004U9MS' => 8 } )
18
+
19
+ puts cart.cart_id
20
+ puts cart.hmac
21
+ puts cart.purchase_url
22
+ puts
23
+
24
+ cart.cart_add( :ASIN, 'B0014C2BL4', 1,
25
+ { 'B0006L16N8' => 5 },
26
+ { 'B000QRI5RM' => 4 } )
27
+ cart.cart_add( :ASIN, 'B0013F2M52', 3 )
28
+ cart.cart_add( :ASIN, 'B000HCPSR6', 5 )
29
+ cart.cart_modify( :ASIN, 'B00151HZA6', 2, true,
30
+ { 'B0013F2M52' => 1 },
31
+ { 'B000HCPSR6' => 3 } )
32
+
33
+ puts 'Cart contents:'
34
+ cart.each do |it|
35
+ puts "ASIN: %s, item Id: %-14s, quantity: %d" %
36
+ [ it.asin, it.cart_item_id, it.quantity ]
37
+ end
38
+ puts
39
+
40
+ puts cart.items
41
+
42
+ cart.cart_clear
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: similarity_lookup1,v 1.2 2010/02/20 16:49:14 ianmacd Exp $
4
+
5
+ require 'amazon/aws'
6
+ require 'amazon/aws/search'
7
+
8
+ include Amazon::AWS
9
+ include Amazon::AWS::Search
10
+
11
+ # Example of a batch operation, using the ASIN as the shared ID.
12
+ #
13
+ sl = SimilarityLookup.new( [ 'B000AE4QEC', 'B000051WBE' ] )
14
+
15
+ # You can have multiple response groups.
16
+ #
17
+ sl.response_group = ResponseGroup.new( 'Medium', 'Offers', 'Reviews' )
18
+
19
+ req = Request.new
20
+ req.locale = 'uk'
21
+
22
+ resp = req.search( sl )
23
+ item_sets = resp.similarity_lookup_response[0].items
24
+
25
+ item_sets.each do |item_set|
26
+ item_set.item.each do |item|
27
+ attribs = item.item_attributes[0]
28
+ puts attribs.label
29
+ if attribs.list_price
30
+ puts attribs.title, attribs.list_price[0].formatted_price
31
+ end
32
+
33
+ # Availability has become a cumbersome thing to retrieve in AWSv4.
34
+ #
35
+ puts 'Availability: %s' %
36
+ [ item.offers[0].offer[0].offer_listing[0].availability ]
37
+ puts 'Average rating: %s' % [ item.customer_reviews[0].average_rating ]
38
+ puts 'Reviewed by %s customers.' %
39
+ [ item.customer_reviews[0].total_reviews ]
40
+
41
+ puts 'Customers said:'
42
+ item.customer_reviews[0].review.each do |review|
43
+ puts ' %s (%s votes)' % [ review.summary, review.total_votes ]
44
+ end
45
+
46
+ puts
47
+ end
48
+ end