alandipert-ruby-aaws 0.7.1

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.
Files changed (60) hide show
  1. data/COPYING +340 -0
  2. data/INSTALL +260 -0
  3. data/NEWS +710 -0
  4. data/README +653 -0
  5. data/README.rdoc +145 -0
  6. data/Rakefile +35 -0
  7. data/VERSION +1 -0
  8. data/example/batch_operation +27 -0
  9. data/example/browse_node_lookup1 +46 -0
  10. data/example/customer_content_lookup1 +27 -0
  11. data/example/customer_content_search1 +21 -0
  12. data/example/example1 +87 -0
  13. data/example/help1 +25 -0
  14. data/example/item_lookup1 +56 -0
  15. data/example/item_lookup2 +56 -0
  16. data/example/item_search1 +30 -0
  17. data/example/item_search2 +37 -0
  18. data/example/item_search3 +23 -0
  19. data/example/list_lookup1 +29 -0
  20. data/example/list_search1 +30 -0
  21. data/example/multiple_operation1 +68 -0
  22. data/example/seller_listing_lookup1 +30 -0
  23. data/example/seller_listing_search1 +28 -0
  24. data/example/seller_lookup1 +45 -0
  25. data/example/shopping_cart1 +42 -0
  26. data/example/similarity_lookup1 +48 -0
  27. data/example/tag_lookup1 +34 -0
  28. data/example/transaction_lookup1 +26 -0
  29. data/example/vehicle_search +22 -0
  30. data/lib/amazon/aws/cache.rb +141 -0
  31. data/lib/amazon/aws/search.rb +342 -0
  32. data/lib/amazon/aws/shoppingcart.rb +504 -0
  33. data/lib/amazon/aws.rb +1217 -0
  34. data/lib/amazon/locale.rb +102 -0
  35. data/lib/amazon.rb +145 -0
  36. data/ruby-aaws.gemspec +117 -0
  37. data/setup.rb +1306 -0
  38. data/test/setup.rb +34 -0
  39. data/test/tc_amazon.rb +20 -0
  40. data/test/tc_aws.rb +151 -0
  41. data/test/tc_browse_node_lookup.rb +62 -0
  42. data/test/tc_customer_content_lookup.rb +64 -0
  43. data/test/tc_help.rb +60 -0
  44. data/test/tc_item_lookup.rb +60 -0
  45. data/test/tc_item_search.rb +106 -0
  46. data/test/tc_list_lookup.rb +55 -0
  47. data/test/tc_list_search.rb +55 -0
  48. data/test/tc_multiple_operation.rb +265 -0
  49. data/test/tc_operation_request.rb +58 -0
  50. data/test/tc_seller_listing_lookup.rb +58 -0
  51. data/test/tc_seller_listing_search.rb +70 -0
  52. data/test/tc_seller_lookup.rb +54 -0
  53. data/test/tc_serialisation.rb +103 -0
  54. data/test/tc_shopping_cart.rb +214 -0
  55. data/test/tc_similarity_lookup.rb +59 -0
  56. data/test/tc_tag_lookup.rb +35 -0
  57. data/test/tc_transaction_lookup.rb +35 -0
  58. data/test/tc_vehicle_operations.rb +106 -0
  59. data/test/ts_aws.rb +24 -0
  60. metadata +135 -0
data/README.rdoc ADDED
@@ -0,0 +1,145 @@
1
+ #--
2
+ # $Id: README.rdoc,v 1.25 2009/06/15 23:51:11 ianmacd Exp $
3
+ #++
4
+ #
5
+ #
6
+ # = Ruby/AWS - A Ruby interface to the Amazon Associates Web Services API.
7
+ #
8
+ # == Introduction
9
+ #
10
+ # Ruby/AWS is a Ruby language library that allows programmatic access to
11
+ # the popular Amazon Web sites via the AWS v4 API. It is the successor to the
12
+ # now obsolete Ruby/Amazon.
13
+ #
14
+ # In addition to the original
15
+ # amazon.com[http://www.amazon.com/exec/obidos/redirect-home/calibanorg-20]
16
+ # site, the local sites
17
+ # amazon.co.uk[http://www.amazon.co.uk/exec/obidos/redirect-home/caliban-21],
18
+ # amazon.de[http://www.amazon.de/exec/obidos/redirect-home/calibanorg0a-21],
19
+ # amazon.fr[http://www.amazon.fr/exec/obidos/redirect-home/caliban08-21],
20
+ # amazon.ca[http://www.amazon.ca/exec/obidos/redirect-home/caliban-20] and
21
+ # amazon.co.jp[http://www.amazon.co.jp/exec/obidos/redirect-home/calibanorg-20]
22
+ # are also supported.
23
+ #
24
+ # Although the library is still in development, the AWS v4 API is now more or
25
+ # less fully supported, with only tiny gaps in the functionality of some
26
+ # operations.
27
+ #
28
+ # The following operations are supported:
29
+ #
30
+ # BrowseNodeLookup
31
+ # CustomerContentLookup
32
+ # CustomerContentSearch
33
+ # Help
34
+ # ItemLookup
35
+ # ItemSearch
36
+ # ListLookup
37
+ # ListSearch
38
+ # SellerListingLookup
39
+ # SellerListingSearch
40
+ # SellerLookup
41
+ # SimilarityLookup
42
+ # TagLookup
43
+ # TransactionLookup
44
+ # VehiclePartLookup
45
+ # VehiclePartSearch
46
+ # VehicleSearch
47
+ #
48
+ # Remote shopping-carts are also supported. This adds the following operations:
49
+ #
50
+ # CartCreate
51
+ # CartAdd
52
+ # CartModify
53
+ # CartClear
54
+ # CartGet
55
+ #
56
+ # Finally, multiple operations and batch requests are also supported.
57
+ #
58
+ # Ruby/AWS supports request authentication, using your secret key to sign your
59
+ # requests to AWS.
60
+ #
61
+ # Beyond wrapping features readily available in the AWS API, Ruby/AWS also
62
+ # offers advanced features not directly supported by the AWS API, such as the
63
+ # ability to retrieve *all* results pages for a particular search, rather than
64
+ # having to manually deal with multiple AWS responses of 10 results per page.
65
+ #
66
+ # You can also retrieve product images and optionally overlay them with
67
+ # percentage discount icons.
68
+ #
69
+ # Another advanced feature is the ability to cache responses returned by AWS.
70
+ # If the cache is used (as it is by default), the results of each unique
71
+ # search will be cached and used for 24 hours. The cache can be manually
72
+ # flushed of all or just the expired entries.
73
+ #
74
+ # One other useful advanced feature is the ability to determine the
75
+ # appropriate Amazon locale for a given client, based on its IP address or
76
+ # host name. This allows you to perform AWS operations using the correct
77
+ # geographical Amazon site for any given client. German and Austrian clients
78
+ # can be made to interact with amazon.de, British and Irish clients with
79
+ # amazon.co.uk, etc.
80
+ #
81
+ #
82
+ # == Installation
83
+ #
84
+ # Please see the +INSTALL+ file supplied with the software for details of how
85
+ # to install Ruby/AWS. You can choose between an installation script and a
86
+ # RubyGems[http://www.rubygems.org/] installation.
87
+ #
88
+ # Note, however, if opting for the gem installation, that Ruby/AWS's RubyForge
89
+ # UNIX name is now ruby-aaws. The ruby-aws name was taken by {another
90
+ # project}[http://rubyforge.org/projects/ruby-aws/] and this namespace clash
91
+ # prevented remote installation of the Ruby/AWS gem.
92
+ #
93
+ #
94
+ # == Prerequisites
95
+ #
96
+ # Before you can use this library, you need to obtain an Amazon Web Services
97
+ # {access key
98
+ # ID}[https://aws-portal.amazon.com/gp/aws/developer/registration/index.html].
99
+ #
100
+ # You should also apply for an {Associates
101
+ # account}[http://docs.amazonwebservices.com/AWSECommerceService/2009-03-31/GSG/BecominganAssociate.html],
102
+ # although this isn't strictly necessary. If you do not explicitly provide an
103
+ # Associates tag in the operations you conduct via Ruby/AWS, the tag of the
104
+ # Ruby/AWS author will be used by default.
105
+ #
106
+ #
107
+ # == See Also
108
+ #
109
+ # Ultimately, the way to get the most from Ruby/AWS is to read the AWS
110
+ # documentation to get a feel for what is possible, and then experiment with
111
+ # the library to see how the calls to AWS are mapped to the Ruby world. You
112
+ # should also review this library's
113
+ # RDoc[http://www.ruby-doc.org/core/classes/RDoc.html]
114
+ # documentation[http://www.caliban.org/ruby/ruby-aws/] as well as the
115
+ # plain-text +README+ file that came with the archive.
116
+ #
117
+ # Additionally, there's a
118
+ # {mailing-list}[http://www.caliban.org/mailman/listinfo/ruby-aws] available,
119
+ # where you can discuss any Ruby/AWS-related subjects and issues.
120
+ #
121
+ # Please see the AWS Developer Resources {home
122
+ # page}[https://affiliate-program.amazon.com/gp/advertising/api/detail/main.html],
123
+ # the Amazon Web Services API
124
+ # documentation[http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=5],
125
+ # and, in particular, the {release
126
+ # notes}[http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=17]
127
+ # for definitive information on the capabilities and inner workings of the AWS
128
+ # API.
129
+ #
130
+ #
131
+ # == Download
132
+ #
133
+ # Version 0.7.0
134
+ # === {gzip'ed tar archive}[http://www.caliban.org/files/ruby/ruby-aws-0.7.0.tar.gz]
135
+ # === {Ruby Gem}[http://www.caliban.org/files/ruby/ruby-aaws-0.7.0.gem]
136
+ # === {Fedora 9 RPM}[http://www.caliban.org/files/redhat/RPMS/noarch/ruby-aws-0.7.0-1.fc9.noarch.rpm]
137
+ # === {Fedora 9 doc RPM}[http://www.caliban.org/files/redhat/RPMS/noarch/ruby-aws-doc-0.7.0-1.fc9.noarch.rpm]
138
+ # === {Fedora 9 source RPM}[http://www.caliban.org/files/redhat/SRPMS/ruby-aws-0.7.0-1.fc9.src.rpm]
139
+ #
140
+ #
141
+ # ---
142
+ # Author:: Ian Macdonald <mailto:ian@caliban.org>
143
+ # Version:: 0.7.0
144
+ # Copyright:: (C) 2008-2009 Ian Macdonald
145
+ # Licence:: GPL[http://www.gnu.org/copyleft/gpl.html]
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ # $Id: Rakefile,v 1.15 2009/06/15 12:07:14 ianmacd Exp $
2
+ #
3
+
4
+ require 'rubygems'
5
+
6
+ begin
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |gemspec|
9
+ gemspec.name = "ruby-aaws"
10
+ gemspec.summary = "Ruby interface to Amazon Associates Web Services"
11
+ gemspec.description = "Ruby interface to Amazon Associates Web Services"
12
+ gemspec.email = "ian@caliban.org"
13
+ gemspec.homepage = "http://www.caliban.org/ruby/ruby-aws/"
14
+ gemspec.authors = ["Ian Macdonald", "Jamie Dyer"]
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
18
+ end
19
+
20
+
21
+ desc 'Produce HTML documentation in ./doc'
22
+ task :doc do
23
+ system( *%w[ rdoc -SUx CVS lib ] )
24
+
25
+ # In-place edit to change page of main frame to the one with the most
26
+ # relevant documentation.
27
+ #
28
+ $-i = ''
29
+ ARGV[0] = 'doc/index.html'
30
+ ARGF.each_line do |l|
31
+ l.sub!( Regexp.new( 'files/lib/.+?\.html' ),
32
+ 'files/lib/amazon/aws_rb.html' )
33
+ puts l
34
+ end
35
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.7.1
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: batch_operation,v 1.2 2009/02/20 00:37:15 ianmacd Exp $
4
+
5
+ require 'amazon/aws/search'
6
+
7
+ include Amazon::AWS
8
+ include Amazon::AWS::Search
9
+
10
+ rg = ResponseGroup.new( :Small )
11
+ req = Request.new
12
+ req.locale = 'uk'
13
+ req.cache = false
14
+
15
+ is = ItemSearch.new( 'Books', { 'Title' => 'ruby programming' } )
16
+ is2 = ItemSearch.new( 'Music', { 'Title' => 'stranglers' } )
17
+ #more_is = [ ItemSearch.new( 'Music', { 'Title' => 'stranglers' } ),
18
+ # ItemSearch.new( 'DVD', { 'Director' => 'scorsese' } ) ]
19
+
20
+ more_is = [ ItemSearch.new( 'Music', { 'Artist' => 'stranglers' } ) ]
21
+
22
+ is.batch( more_is )
23
+
24
+ batched_response = req.search( is, rg )
25
+ itemsearch = batched_response.item_search_response[0].items
26
+
27
+ puts itemsearch
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: browse_node_lookup1,v 1.3 2008/04/11 19:24:24 ianmacd Exp $
4
+
5
+ require 'amazon/aws/search'
6
+
7
+ include Amazon::AWS
8
+ include Amazon::AWS::Search
9
+
10
+ # This is the node for Social Sciences.
11
+ #
12
+ START_NODE = '11232'
13
+
14
+ def follow_node(id)
15
+
16
+ req ||= Request.new
17
+ req.locale = 'us'
18
+
19
+ bnl = BrowseNodeLookup.new( id, {} )
20
+ bnl_rg ||= ResponseGroup.new( 'BrowseNodeInfo' )
21
+ resp = req.search( bnl, bnl_rg )
22
+
23
+ #items = resp.browse_node_sets.browse_nodes
24
+ nodes = resp.browse_node_lookup_response[0].browse_nodes[0].browse_node
25
+
26
+ nodes.each do |bn|
27
+
28
+ if bn.children
29
+ puts '%s (%s) has the following children:' % [ bn.name, id ]
30
+
31
+ bn.children[0].browse_node.each do |child_node|
32
+ puts ' %s' % [ child_node.name ]
33
+ end
34
+ puts
35
+
36
+ bn.children[0].browse_node.each do |child_node|
37
+ follow_node( child_node.browse_node_id )
38
+ end
39
+
40
+ else
41
+ puts '%s (%s) has no children.' % [ bn.name, id ]
42
+ end
43
+ end
44
+ end
45
+
46
+ follow_node( START_NODE )
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: customer_content_lookup1,v 1.3 2008/04/28 09:59:52 ianmacd Exp $
4
+
5
+ require 'amazon/aws/search'
6
+
7
+ include Amazon::AWS
8
+ include Amazon::AWS::Search
9
+
10
+ ccl = CustomerContentLookup.new( 'AJDWXANG1SYZP' )
11
+ rg = ResponseGroup.new( 'CustomerReviews' )
12
+
13
+ req = Request.new
14
+ req.locale = 'us'
15
+
16
+ resp = req.search( ccl, rg )
17
+
18
+ review = resp.customer_content_lookup_response.customers.customer.customer_reviews.review[0]
19
+
20
+ printf( "Customer's name is %s.\n", review.reviewer.name )
21
+ printf( "Customer's location is %s.\n", review.reviewer.location )
22
+ printf( "Review date is %s.\n", review.date )
23
+ printf( "Review has received %s votes.\n", review.total_votes )
24
+ printf( "Of these, %d deemed the review helpful.\n", review.helpful_votes )
25
+ printf( "Product reviewed has ASIN '%s'.\n", review.asin )
26
+ printf( "Review summary is: %s.\n", review.summary )
27
+ printf( "Review content is:\n%s.\n", review.content )
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: customer_content_search1,v 1.1 2008/04/27 21:58:54 ianmacd Exp $
4
+
5
+ require 'amazon/aws/search'
6
+
7
+ include Amazon::AWS
8
+ include Amazon::AWS::Search
9
+
10
+ ccs = CustomerContentSearch.new( 'ian@caliban.org' )
11
+ rg = ResponseGroup.new( 'CustomerInfo' )
12
+
13
+ req = Request.new
14
+ req.locale = 'us'
15
+
16
+ resp = req.search( ccs, rg )
17
+ cust = resp.customer_content_search_response.customers.customer
18
+
19
+ printf( "Customer's ID is %s.\n", cust.customer_id )
20
+ printf( "Customer's nickname is %s.\n", cust.nickname )
21
+ printf( "Customer's location is %s.\n", cust.location.user_defined_location )
data/example/example1 ADDED
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: example1,v 1.5 2009/06/02 01:09:51 ianmacd Exp $
4
+
5
+ require 'amazon/aws'
6
+ require 'amazon/aws/search'
7
+
8
+ # We don't want to have to fully qualify identifiers.
9
+ #
10
+ include Amazon::AWS
11
+ include Amazon::AWS::Search
12
+
13
+ # If you don't have one of these, don't pass the second argument to
14
+ # Request.new.
15
+ #
16
+ ASSOCIATES_ID = "webservices-20"
17
+
18
+ # Your access key ID.
19
+ #
20
+ KEY_ID = "0Y44V8FAFNM119C6PTR2"
21
+
22
+ request = Request.new( KEY_ID, ASSOCIATES_ID )
23
+
24
+ # Create an item search object.
25
+ #
26
+ # is = ItemSearch.new( 'Books', { 'Keywords' => 'ruby programming' } )
27
+ is = ItemSearch.new( 'Books', { 'Title' => 'ruby programming' } )
28
+
29
+ # Create a response group object. Examples of response groups are 'Small',
30
+ # 'Medium' and 'Large'. 'Large' returns all data about an item.
31
+ #
32
+ rg = ResponseGroup.new( 'Large' )
33
+
34
+ # Search for the items, passing the result into a block.
35
+ #
36
+ nr_items = 0
37
+ page_nr = 0
38
+ response = request.search( is, rg, :ALL_PAGES ) do |page|
39
+ # page.item_search_response[0].items.each do |item_set|
40
+ # item_set.item.each do |item|
41
+ # puts 'Found a product:'
42
+ # item.instance_variables.each do |iv|
43
+ # printf( "%s = %s\n", iv, item.instance_variable_get( iv ) )
44
+ # end
45
+ # end
46
+ # end
47
+ printf( "Page %d had unique request ID %s.\n",
48
+ page_nr += 1,
49
+ page.item_search_response[0].operation_request[0].request_id )
50
+ printf( "Page %d contained %d result(s).\n",
51
+ page_nr,
52
+ page.item_search_response[0].items[0].item.size )
53
+ end
54
+
55
+ # You don't have to access the items through a block.
56
+ #
57
+ nr_items = 0
58
+ response.each do |page|
59
+ page.item_search_response[0].items.each do |item_set|
60
+ nr_items += item_set.item.size
61
+ end
62
+ end
63
+ printf( "Search returned %d items.\n", nr_items )
64
+
65
+ # The first item in the list.
66
+ #
67
+ items = response[0].item_search_response[0].items[0].item
68
+ product1 = items[0]
69
+ puts "\nProperties available for the first product returned:",
70
+ product1.properties.sort
71
+ puts
72
+
73
+ # There are three ways to retrieve the property of a product:
74
+ #
75
+
76
+ # Instance variable:
77
+ #
78
+ p product1.asin
79
+ p product1.item_attributes[0].title
80
+
81
+ # Feels more like a Hash:
82
+ #
83
+ p product1.item_attributes[0]['list_price'][0]['formatted_price']
84
+
85
+ # A variation on the hash theme:
86
+ #
87
+ p product1.item_attributes[0][:author]
data/example/help1 ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: help1,v 1.1 2008/04/27 22:21:52 ianmacd Exp $
4
+
5
+ require 'amazon/aws/search'
6
+
7
+ include Amazon::AWS
8
+ include Amazon::AWS::Search
9
+
10
+ h = Help.new( 'ResponseGroup', 'Large' )
11
+
12
+ rg = ResponseGroup.new( 'Help' )
13
+
14
+ req = Request.new
15
+ req.locale = 'uk'
16
+
17
+ resp = req.search( h, rg )
18
+ help = resp.help_response[0].information.response_group_information
19
+
20
+ printf( "The response group 'Large' was created on %s\n", help.creation_date )
21
+ puts 'It can be used with the following operations:'
22
+ puts help.valid_operations.operation.join( ', ' )
23
+ puts
24
+ puts "and causes the following elements to be returned:\n\n"
25
+ puts help.elements.element
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: item_lookup1,v 1.6 2009/02/20 00:13:38 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' => 'B000AE4QEC',
18
+ 'MerchantId' => 'Amazon' } )
19
+ il2 = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000051WBE',
20
+ 'MerchantId' => 'Amazon' } )
21
+ il.batch( il2 )
22
+
23
+ # You can have multiple response groups.
24
+ #
25
+ rg = ResponseGroup.new( 'Medium', 'Offers', 'Reviews' )
26
+
27
+ req = Request.new
28
+ req.locale = 'uk'
29
+
30
+ resp = req.search( il, rg )
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,56 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: item_lookup2,v 1.4 2009/02/20 00:13:38 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
+ rg = ResponseGroup.new( 'Medium', 'Offers', 'Reviews' )
26
+
27
+ req = Request.new
28
+ req.locale = 'us'
29
+
30
+ resp = req.search( il, rg )
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.4 2008/04/11 19:24:24 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
+ rg = ResponseGroup.new( 'Large' )
12
+
13
+ req = Request.new
14
+ req.locale = 'uk'
15
+
16
+ resp = req.search( is, rg )
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.4 2008/04/28 09:59:39 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
+ rg = ResponseGroup.new( :Medium )
14
+
15
+ req = Request.new
16
+ req.locale = 'uk'
17
+
18
+ resp = req.search( is, rg, :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.3 2008/04/11 19:24:24 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
+ rg = ResponseGroup.new( 'Small' )
14
+
15
+ req = Request.new
16
+ req.locale = 'us'
17
+
18
+ resp = req.search( is, rg )
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.1 2008/04/27 16:36:14 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_rg = ResponseGroup.new( 'ListInfo', 'Small' )
12
+
13
+ req = Request.new
14
+ req.locale = 'us'
15
+
16
+ resp = req.search( ll, ll_rg )
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.3 2008/04/11 19:24:24 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_rg = ResponseGroup.new( 'ListInfo' )
14
+
15
+ req = Request.new
16
+ req.locale = 'us'
17
+
18
+ resp = req.search( ls, ls_rg )
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