ruby-paa 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/example/batch_operation +28 -0
  2. data/example/browse_node_lookup1 +46 -0
  3. data/example/customer_content_lookup1 +27 -0
  4. data/example/customer_content_search1 +21 -0
  5. data/example/example1 +78 -0
  6. data/example/help1 +24 -0
  7. data/example/item_lookup1 +54 -0
  8. data/example/item_lookup2 +56 -0
  9. data/example/item_search1 +30 -0
  10. data/example/item_search2 +37 -0
  11. data/example/item_search3 +23 -0
  12. data/example/list_lookup1 +29 -0
  13. data/example/list_search1 +31 -0
  14. data/example/multiple_operation1 +69 -0
  15. data/example/seller_listing_lookup1 +30 -0
  16. data/example/seller_listing_search1 +29 -0
  17. data/example/seller_lookup1 +45 -0
  18. data/example/shopping_cart1 +42 -0
  19. data/example/similarity_lookup1 +48 -0
  20. data/example/tag_lookup1 +34 -0
  21. data/example/transaction_lookup1 +25 -0
  22. data/example/vehicle_search +22 -0
  23. data/lib/ruby-paa.rb +165 -0
  24. data/lib/ruby-paa/aws.rb +1489 -0
  25. data/lib/ruby-paa/aws/cache.rb +141 -0
  26. data/lib/ruby-paa/aws/search.rb +463 -0
  27. data/lib/ruby-paa/aws/shoppingcart.rb +536 -0
  28. data/lib/ruby-paa/locale.rb +102 -0
  29. data/test/setup.rb +56 -0
  30. data/test/tc_amazon.rb +20 -0
  31. data/test/tc_aws.rb +160 -0
  32. data/test/tc_browse_node_lookup.rb +49 -0
  33. data/test/tc_customer_content_lookup.rb +49 -0
  34. data/test/tc_help.rb +44 -0
  35. data/test/tc_item_lookup.rb +47 -0
  36. data/test/tc_item_search.rb +105 -0
  37. data/test/tc_list_lookup.rb +60 -0
  38. data/test/tc_list_search.rb +44 -0
  39. data/test/tc_multiple_operation.rb +375 -0
  40. data/test/tc_operation_request.rb +64 -0
  41. data/test/tc_seller_listing_lookup.rb +47 -0
  42. data/test/tc_seller_listing_search.rb +55 -0
  43. data/test/tc_seller_lookup.rb +44 -0
  44. data/test/tc_serialisation.rb +107 -0
  45. data/test/tc_shopping_cart.rb +214 -0
  46. data/test/tc_similarity_lookup.rb +48 -0
  47. data/test/tc_tag_lookup.rb +24 -0
  48. data/test/tc_transaction_lookup.rb +24 -0
  49. data/test/tc_vehicle_operations.rb +118 -0
  50. data/test/ts_aws.rb +24 -0
  51. metadata +132 -0
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: batch_operation,v 1.3 2010/02/20 16:49:11 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
+ is.response_group = rg
24
+
25
+ batched_response = req.search( is )
26
+ itemsearch = batched_response.item_search_response[0].items
27
+
28
+ puts itemsearch
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: browse_node_lookup1,v 1.4 2010/02/20 16:49:11 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.response_group ||= ResponseGroup.new( 'BrowseNodeInfo' )
21
+ resp = req.search( bnl )
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.4 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
+ ccl = CustomerContentLookup.new( 'AJDWXANG1SYZP' )
11
+ ccl.response_group = ResponseGroup.new( 'CustomerReviews' )
12
+
13
+ req = Request.new
14
+ req.locale = 'us'
15
+
16
+ resp = req.search( ccl )
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.2 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
+ ccs = CustomerContentSearch.new( 'ian@caliban.org' )
11
+ ccs.response_group = ResponseGroup.new( 'CustomerInfo' )
12
+
13
+ req = Request.new
14
+ req.locale = 'us'
15
+
16
+ resp = req.search( ccs )
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 )
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: example1,v 1.6 2010/02/20 16:49:12 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', { 'Title' => 'ruby programming' } )
27
+
28
+ # Create a response group object. Examples of response groups are 'Small',
29
+ # 'Medium' and 'Large'. 'Large' returns all data about an item.
30
+ #
31
+ is.response_group = ResponseGroup.new( 'Large' )
32
+
33
+ # Search for the items, passing the result into a block.
34
+ #
35
+ nr_items = 0
36
+ page_nr = 0
37
+ response = request.search( is, :ALL_PAGES ) do |page|
38
+ printf( "Page %d had unique request ID %s.\n",
39
+ page_nr += 1,
40
+ page.item_search_response[0].operation_request[0].request_id )
41
+ printf( "Page %d contained %d result(s).\n",
42
+ page_nr,
43
+ page.item_search_response[0].items[0].item.size )
44
+ end
45
+
46
+ # You don't have to access the items through a block.
47
+ #
48
+ nr_items = 0
49
+ response.each do |page|
50
+ page.item_search_response[0].items.each do |item_set|
51
+ nr_items += item_set.item.size
52
+ end
53
+ end
54
+ printf( "Search returned %d items.\n", nr_items )
55
+
56
+ # The first item in the list.
57
+ #
58
+ items = response[0].item_search_response[0].items[0].item
59
+ product1 = items[0]
60
+ puts "\nProperties available for the first product returned:",
61
+ product1.properties.sort
62
+ puts
63
+
64
+ # There are three ways to retrieve the property of a product:
65
+ #
66
+
67
+ # Instance variable:
68
+ #
69
+ p product1.asin
70
+ p product1.item_attributes[0].title
71
+
72
+ # Feels more like a Hash:
73
+ #
74
+ p product1.item_attributes[0]['list_price'][0]['formatted_price']
75
+
76
+ # A variation on the hash theme:
77
+ #
78
+ p product1.item_attributes[0][:author]
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: help1,v 1.2 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
+ h = Help.new( 'ResponseGroup', 'Large' )
11
+ h.response_group = ResponseGroup.new( 'Help' )
12
+
13
+ req = Request.new
14
+ req.locale = 'uk'
15
+
16
+ resp = req.search( h )
17
+ help = resp.help_response[0].information.response_group_information
18
+
19
+ printf( "The response group 'Large' was created on %s\n", help.creation_date )
20
+ puts 'It can be used with the following operations:'
21
+ puts help.valid_operations.operation.join( ', ' )
22
+ puts
23
+ puts "and causes the following elements to be returned:\n\n"
24
+ puts help.elements.element
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: item_lookup1,v 1.7 2010/02/20 16:49:12 ianmacd Exp $
4
+
5
+ require 'rubygems'
6
+ require 'ruby-paa/aws'
7
+ require 'ruby-paa/aws/search'
8
+ require 'active_support/all'
9
+
10
+ include Amazon::AWS
11
+ include Amazon::AWS::Search
12
+
13
+ # Example of a batch operation.
14
+ #
15
+ # The MerchantId restriction is to ensure that we retrieve only items that
16
+ # are for sale by Amazon. This is important when we later want to retrieve the
17
+ # availability status.
18
+ #
19
+ il = ItemLookup.new( 'ASIN', { 'ItemId' => 'B001LJCCC8' } )
20
+
21
+ #il2 = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000051WBE',
22
+ # 'MerchantId' => 'Amazon' } )
23
+ #il.batch( il2 )
24
+
25
+ # You can have multiple response groups.
26
+ #
27
+ il.response_group = ResponseGroup.new( 'Medium', 'Offers' )
28
+
29
+ req = Request.new
30
+ req.locale = 'us'
31
+
32
+ resp = req.search( il )
33
+ item_sets = resp.item_lookup_response[0].items
34
+
35
+ item_sets.each do |item_set|
36
+ item_set.item.each do |item|
37
+
38
+ puts item.to_json
39
+ puts
40
+
41
+ #attribs = item.item_attributes[0]
42
+ #puts attribs.label
43
+ #if attribs.list_price
44
+ # puts attribs.title, attribs.list_price[0].formatted_price
45
+ #end
46
+
47
+ # Availability has become a cumbersome thing to retrieve in AWSv4.
48
+ #
49
+ #puts 'Availability: %s' %
50
+ # [ item.offers[0].offer[0].offer_listing[0].availability ]
51
+
52
+ # puts
53
+ end
54
+ end
@@ -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