ruby-aaws 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/INSTALL +260 -0
- data/NEWS +116 -1
- data/README +13 -7
- data/README.rdoc +12 -10
- data/example/example1 +3 -3
- data/lib/amazon.rb +9 -7
- data/lib/amazon/aws.rb +212 -65
- data/lib/amazon/aws/search.rb +62 -16
- data/test/setup.rb +4 -2
- data/test/tc_aws.rb +2 -2
- data/test/tc_browse_node_lookup.rb +62 -0
- data/test/tc_customer_content_lookup.rb +64 -0
- data/test/tc_help.rb +60 -0
- data/test/tc_item_lookup.rb +60 -0
- data/test/tc_item_search.rb +54 -6
- data/test/tc_list_lookup.rb +55 -0
- data/test/tc_list_search.rb +55 -0
- data/test/tc_multiple_operation.rb +201 -2
- data/test/tc_seller_listing_lookup.rb +58 -0
- data/test/tc_seller_listing_search.rb +70 -0
- data/test/tc_seller_lookup.rb +54 -0
- data/test/tc_similarity_lookup.rb +59 -0
- data/test/tc_tag_lookup.rb +35 -0
- data/test/tc_transaction_lookup.rb +35 -0
- data/test/ts_aws.rb +16 -5
- metadata +29 -3
@@ -0,0 +1,55 @@
|
|
1
|
+
# $Id: tc_list_lookup.rb,v 1.2 2009/06/03 22:33:04 ianmacd Exp $
|
2
|
+
#
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require './setup'
|
6
|
+
|
7
|
+
class TestListLookup < AWSTest
|
8
|
+
|
9
|
+
def test_list_lookup
|
10
|
+
|
11
|
+
@req.locale = 'us'
|
12
|
+
rg = ResponseGroup.new( :ListInfo )
|
13
|
+
ll = ListLookup.new( '3TV12MGLOJI4R', :WishList )
|
14
|
+
response = @req.search( ll, rg )
|
15
|
+
|
16
|
+
list = response.kernel
|
17
|
+
|
18
|
+
assert_equal( '2008-06-30', list.date_created )
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_list_lookup_no_response_group
|
23
|
+
|
24
|
+
@req.locale = 'us'
|
25
|
+
ll = ListLookup.new( '3P722DU4KUPCP', 'Listmania' )
|
26
|
+
ll.response_group = ResponseGroup.new( :ListInfo, :Small )
|
27
|
+
response = @req.search( ll, nil )
|
28
|
+
|
29
|
+
list = response.kernel
|
30
|
+
|
31
|
+
assert_equal( 'Computer History', list.list_name )
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_list_lookup_class_method
|
36
|
+
|
37
|
+
response = Amazon::AWS.list_lookup( 'R35BA7X0YD3YP', 'Listmania' )
|
38
|
+
|
39
|
+
list = response.kernel
|
40
|
+
|
41
|
+
assert_equal( 'examples of perfection', list.list_name )
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_item_search_class_method_block
|
46
|
+
|
47
|
+
Amazon::AWS.list_lookup( 'R35BA7X0YD3YP', :Listmania ) do |r|
|
48
|
+
|
49
|
+
list = r.kernel
|
50
|
+
|
51
|
+
assert_equal( 'examples of perfection', list.list_name )
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# $Id: tc_list_search.rb,v 1.2 2009/06/03 22:32:42 ianmacd Exp $
|
2
|
+
#
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require './setup'
|
6
|
+
|
7
|
+
class TestListSearch < AWSTest
|
8
|
+
|
9
|
+
def test_list_search
|
10
|
+
|
11
|
+
@req.locale = 'us'
|
12
|
+
rg = ResponseGroup.new( :ListInfo )
|
13
|
+
ls = ListSearch.new( 'WishList', { 'Name' => 'Peter Duff' } )
|
14
|
+
response = @req.search( ls, rg )
|
15
|
+
|
16
|
+
lists = response.kernel
|
17
|
+
|
18
|
+
assert( lists.collect { |l| l.list_id }.include?( '18Y9QEW3A4SRY' ) )
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_list_search_no_response_group
|
23
|
+
|
24
|
+
@req.locale = 'us'
|
25
|
+
ls = ListSearch.new( 'WishList', { 'Name' => 'Peter Duff' } )
|
26
|
+
ls.response_group = ResponseGroup.new( :ListMinimum )
|
27
|
+
response = @req.search( ls, nil )
|
28
|
+
|
29
|
+
lists = response.kernel
|
30
|
+
|
31
|
+
assert( lists.collect { |l| l.list_id }.include?( '18Y9QEW3A4SRY' ) )
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_list_search_class_method
|
36
|
+
|
37
|
+
response = Amazon::AWS.list_search( 'WishList', { :Name => 'Peter Duff' } )
|
38
|
+
|
39
|
+
lists = response.kernel
|
40
|
+
|
41
|
+
assert( lists.size > 5 )
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_item_search_class_method_block
|
46
|
+
|
47
|
+
Amazon::AWS.list_search( 'WishList', { 'Name' => 'Peter Duff' } ) do |r|
|
48
|
+
|
49
|
+
lists = r.kernel
|
50
|
+
|
51
|
+
assert( lists.size > 5 )
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: tc_multiple_operation.rb,v 1.
|
1
|
+
# $Id: tc_multiple_operation.rb,v 1.3 2009/06/15 21:21:02 ianmacd Exp $
|
2
2
|
#
|
3
3
|
|
4
4
|
require 'test/unit'
|
@@ -6,11 +6,166 @@ require './setup'
|
|
6
6
|
|
7
7
|
class TestMultipleOperation < AWSTest
|
8
8
|
|
9
|
-
def
|
9
|
+
def test_unbatched_multiple_same_class_with_separate_response_groups
|
10
10
|
il = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000AE4QEC',
|
11
11
|
'MerchantId' => 'Amazon' } )
|
12
12
|
il2 = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000051WBE',
|
13
|
+
'MerchantId' => 'Amazon' } )
|
14
|
+
|
15
|
+
il.response_group = ResponseGroup.new( :Large )
|
16
|
+
il2.response_group = ResponseGroup.new( :Small )
|
17
|
+
|
18
|
+
# Create a multiple operation of the ItemSearch operation and the two
|
19
|
+
# batched ItemLookup operations.
|
20
|
+
#
|
21
|
+
mo = MultipleOperation.new( il, il2 )
|
22
|
+
response = @req.search( mo, nil )
|
23
|
+
mor = response.multi_operation_response[0]
|
24
|
+
|
25
|
+
# Ensure our separate response groups were used.
|
26
|
+
#
|
27
|
+
arguments = mor.operation_request.arguments.argument
|
28
|
+
|
29
|
+
il_rg = arguments.select do |arg|
|
30
|
+
arg.attrib['name'] == 'ItemLookup.1.ResponseGroup'
|
31
|
+
end[0]
|
32
|
+
|
33
|
+
il2_rg = arguments.select do |arg|
|
34
|
+
arg.attrib['name'] == 'ItemLookup.2.ResponseGroup'
|
35
|
+
end[0]
|
36
|
+
|
37
|
+
assert_equal( 'Large', il_rg.attrib['value'] )
|
38
|
+
assert_equal( 'Small', il2_rg.attrib['value'] )
|
39
|
+
|
40
|
+
# Ensure we received a MultiOperationResponse.
|
41
|
+
#
|
42
|
+
assert_instance_of( Amazon::AWS::AWSObject::MultiOperationResponse, mor )
|
43
|
+
|
44
|
+
# Ensure response contains an ItemLookupResponse.
|
45
|
+
#
|
46
|
+
assert_instance_of( Amazon::AWS::AWSObject::ItemLookupResponse,
|
47
|
+
mor.item_lookup_response[0] )
|
48
|
+
|
49
|
+
il_set = mor.item_lookup_response[0].items
|
50
|
+
il_arr1 = il_set[0].item
|
51
|
+
il_arr2 = il_set[1].item
|
52
|
+
|
53
|
+
# Ensure that there are two <ItemSet>s for the ItemLookup, because it was
|
54
|
+
# a batched operation.
|
55
|
+
#
|
56
|
+
assert_equal( 2, il_set.size )
|
57
|
+
|
58
|
+
# Assure that all item sets have some results.
|
59
|
+
#
|
60
|
+
assert( il_arr1.size > 0 )
|
61
|
+
assert( il_arr2.size > 0 )
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_batched_multiple_with_separate_response_groups
|
65
|
+
il = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000AE4QEC',
|
13
66
|
'MerchantId' => 'Amazon' } )
|
67
|
+
il2 = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000051WBE',
|
68
|
+
'MerchantId' => 'Amazon' } )
|
69
|
+
il3 = ItemLookup.new( 'ASIN', { 'ItemId' => 'B00061F8LO',
|
70
|
+
'MerchantId' => 'Amazon' } )
|
71
|
+
|
72
|
+
il.response_group = ResponseGroup.new( :Large )
|
73
|
+
il2.response_group = ResponseGroup.new( :Small )
|
74
|
+
|
75
|
+
# Create a batch request of the two ItemLookup operations.
|
76
|
+
#
|
77
|
+
il.batch( il2 )
|
78
|
+
|
79
|
+
is = ItemSearch.new( 'Books', { 'Title' => 'Ruby' } )
|
80
|
+
is.response_group = ResponseGroup.new( :Medium, :Tags )
|
81
|
+
|
82
|
+
# Create a multiple operation of the ItemSearch operation and the two
|
83
|
+
# batched ItemLookup operations.
|
84
|
+
#
|
85
|
+
mo = MultipleOperation.new( is, il )
|
86
|
+
response = @req.search( mo, nil )
|
87
|
+
mor = response.multi_operation_response[0]
|
88
|
+
|
89
|
+
# Batch a third ItemLookup operation.
|
90
|
+
#
|
91
|
+
il.batch( il3 )
|
92
|
+
mo = MultipleOperation.new( is, il )
|
93
|
+
|
94
|
+
# Because exception classes aren't created until an exception occurs, we
|
95
|
+
# need to create the one we wish to test for now, otherwise we can't refer
|
96
|
+
# to it in our code without causing an 'uninitialized constant' error.
|
97
|
+
#
|
98
|
+
Amazon::AWS::Error.const_set( 'ExceededMaxBatchRequestsPerOperation',
|
99
|
+
Class.new( Amazon::AWS::Error::AWSError ) )
|
100
|
+
|
101
|
+
# Attempt to perform the search.
|
102
|
+
#
|
103
|
+
assert_raise( Amazon::AWS::Error::ExceededMaxBatchRequestsPerOperation ) do
|
104
|
+
@req.search( mo, nil )
|
105
|
+
end
|
106
|
+
|
107
|
+
# Ensure our separate response groups were used.
|
108
|
+
#
|
109
|
+
arguments = mor.operation_request.arguments.argument
|
110
|
+
|
111
|
+
il_rg = arguments.select do |arg|
|
112
|
+
arg.attrib['name'] == 'ItemLookup.1.ResponseGroup'
|
113
|
+
end[0]
|
114
|
+
|
115
|
+
il2_rg = arguments.select do |arg|
|
116
|
+
arg.attrib['name'] == 'ItemLookup.2.ResponseGroup'
|
117
|
+
end[0]
|
118
|
+
|
119
|
+
is_rg = arguments.select do |arg|
|
120
|
+
arg.attrib['name'] == 'ItemSearch.1.ResponseGroup'
|
121
|
+
end[0]
|
122
|
+
|
123
|
+
assert_equal( 'Large', il_rg.attrib['value'] )
|
124
|
+
assert_equal( 'Small', il2_rg.attrib['value'] )
|
125
|
+
assert_equal( 'Medium,Tags', is_rg.attrib['value'] )
|
126
|
+
|
127
|
+
# Ensure we received a MultiOperationResponse.
|
128
|
+
#
|
129
|
+
assert_instance_of( Amazon::AWS::AWSObject::MultiOperationResponse, mor )
|
130
|
+
|
131
|
+
# Ensure response contains an ItemSearchResponse.
|
132
|
+
#
|
133
|
+
assert_instance_of( Amazon::AWS::AWSObject::ItemSearchResponse,
|
134
|
+
mor.item_search_response[0] )
|
135
|
+
|
136
|
+
# Ensure response also contains an ItemLookupResponse.
|
137
|
+
#
|
138
|
+
assert_instance_of( Amazon::AWS::AWSObject::ItemLookupResponse,
|
139
|
+
mor.item_lookup_response[0] )
|
140
|
+
|
141
|
+
is_set = mor.item_search_response[0].items
|
142
|
+
il_set = mor.item_lookup_response[0].items
|
143
|
+
is_arr = is_set.item
|
144
|
+
il_arr1 = il_set[0].item
|
145
|
+
il_arr2 = il_set[1].item
|
146
|
+
|
147
|
+
# Ensure that there's one <ItemSet> for the ItemSearch.
|
148
|
+
#
|
149
|
+
assert_equal( 1, is_set.size )
|
150
|
+
|
151
|
+
# Ensure that there are two <ItemSet>s for the ItemLookup, because it was
|
152
|
+
# a batched operation.
|
153
|
+
#
|
154
|
+
assert_equal( 2, il_set.size )
|
155
|
+
|
156
|
+
# Assure that all item sets have some results.
|
157
|
+
#
|
158
|
+
assert( is_arr.size > 0 )
|
159
|
+
assert( il_arr1.size > 0 )
|
160
|
+
assert( il_arr2.size > 0 )
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
def test_batched_multiple_with_shared_response_group
|
165
|
+
il = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000AE4QEC',
|
166
|
+
'MerchantId' => 'Amazon' } )
|
167
|
+
il2 = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000051WBE',
|
168
|
+
'MerchantId' => 'Amazon' } )
|
14
169
|
|
15
170
|
# Create a batch request of the two ItemLookup operations.
|
16
171
|
#
|
@@ -63,4 +218,48 @@ class TestMultipleOperation < AWSTest
|
|
63
218
|
assert( il_arr2.size > 0 )
|
64
219
|
end
|
65
220
|
|
221
|
+
def test_multiple_class_method
|
222
|
+
il = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000AE4QEC',
|
223
|
+
'MerchantId' => 'Amazon' } )
|
224
|
+
il.response_group = ResponseGroup.new( :Large )
|
225
|
+
|
226
|
+
is = ItemSearch.new( 'Books', { 'Title' => 'Ruby' } )
|
227
|
+
is.response_group = ResponseGroup.new( :Medium, :Tags )
|
228
|
+
|
229
|
+
response = Amazon::AWS.multiple_operation( is, il )
|
230
|
+
mor = response.multi_operation_response[0]
|
231
|
+
|
232
|
+
# Ensure we received a MultiOperationResponse.
|
233
|
+
#
|
234
|
+
assert_instance_of( Amazon::AWS::AWSObject::MultiOperationResponse, mor )
|
235
|
+
|
236
|
+
# Ensure response contains an ItemSearchResponse.
|
237
|
+
#
|
238
|
+
assert_instance_of( Amazon::AWS::AWSObject::ItemSearchResponse,
|
239
|
+
mor.item_search_response[0] )
|
240
|
+
|
241
|
+
# Ensure response also contains an ItemLookupResponse.
|
242
|
+
#
|
243
|
+
assert_instance_of( Amazon::AWS::AWSObject::ItemLookupResponse,
|
244
|
+
mor.item_lookup_response[0] )
|
245
|
+
|
246
|
+
is_set = response.multi_operation_response.item_search_response[0].items
|
247
|
+
il_set = response.multi_operation_response.item_lookup_response[0].items
|
248
|
+
is_arr = is_set.item
|
249
|
+
il_arr = il_set[0].item
|
250
|
+
|
251
|
+
# Ensure that there's one <ItemSet> for the ItemSearch.
|
252
|
+
#
|
253
|
+
assert_equal( 1, is_set.size )
|
254
|
+
|
255
|
+
# Ensure that there's one <ItemSet> for the ItemLookup.
|
256
|
+
#
|
257
|
+
assert_equal( 1, il_set.size )
|
258
|
+
|
259
|
+
# Assure that all item sets have some results.
|
260
|
+
#
|
261
|
+
assert( is_arr.size > 0 )
|
262
|
+
assert( il_arr.size > 0 )
|
263
|
+
end
|
264
|
+
|
66
265
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# $Id: tc_seller_listing_lookup.rb,v 1.1 2009/06/03 08:46:31 ianmacd Exp $
|
2
|
+
#
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require './setup'
|
6
|
+
|
7
|
+
class TestSellerListingLookup < AWSTest
|
8
|
+
|
9
|
+
def test_seller_listing_lookup
|
10
|
+
|
11
|
+
sll = SellerListingLookup.new( 'AP8U6Y3PYQ9VO', :ASIN,
|
12
|
+
{ :Id => 'B0009RRRC8' } )
|
13
|
+
rg = ResponseGroup.new( 'SellerListing' )
|
14
|
+
response = @req.search( sll, rg )
|
15
|
+
|
16
|
+
item = response.kernel
|
17
|
+
|
18
|
+
assert_equal( 'actionrecords', item.seller.nickname )
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_seller_listing_lookup_no_response_group
|
23
|
+
|
24
|
+
sll = SellerListingLookup.new( 'AP8U6Y3PYQ9VO', :ASIN,
|
25
|
+
{ :Id => 'B0009RRRC8' } )
|
26
|
+
sll.response_group = ResponseGroup.new( :SellerListing )
|
27
|
+
response = @req.search( sll )
|
28
|
+
|
29
|
+
item = response.kernel
|
30
|
+
|
31
|
+
assert_equal( 'actionrecords', item.seller.nickname )
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_seller_listing_lookup_class_method
|
36
|
+
|
37
|
+
response = Amazon::AWS.seller_listing_lookup( 'AP8U6Y3PYQ9VO', :ASIN,
|
38
|
+
{ :Id => 'B0009RRRC8' } )
|
39
|
+
|
40
|
+
item = response.kernel
|
41
|
+
|
42
|
+
assert_equal( 'actionrecords', item.seller.nickname )
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_seller_listing_lookup_class_method_block
|
47
|
+
|
48
|
+
Amazon::AWS.seller_listing_lookup( 'AP8U6Y3PYQ9VO', :ASIN,
|
49
|
+
{ :Id => 'B0009RRRC8' } ) do |r|
|
50
|
+
|
51
|
+
item = r.kernel
|
52
|
+
|
53
|
+
assert_equal( 'actionrecords', item.seller.nickname )
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# $Id: tc_seller_listing_search.rb,v 1.1 2009/05/30 23:27:47 ianmacd Exp $
|
2
|
+
#
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require './setup'
|
6
|
+
|
7
|
+
class TestSellerListingSearch < AWSTest
|
8
|
+
|
9
|
+
def test_seller_listing_search
|
10
|
+
|
11
|
+
sl = SellerListingSearch.new( 'AP8U6Y3PYQ9VO',
|
12
|
+
{ 'Keywords' => 'Killing Joke' } )
|
13
|
+
rg = ResponseGroup.new( 'SellerListing' )
|
14
|
+
response = @req.search( sl, rg )
|
15
|
+
|
16
|
+
items = response.seller_listing_search_response[0].seller_listings[0].
|
17
|
+
seller_listing
|
18
|
+
|
19
|
+
|
20
|
+
# Ensure we got some actual items back.
|
21
|
+
#
|
22
|
+
assert( items.size > 0 )
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_seller_listing_search_no_response_group
|
27
|
+
|
28
|
+
sl = SellerListingSearch.new( 'AP8U6Y3PYQ9VO',
|
29
|
+
{ 'Keywords' => 'Killing Joke' } )
|
30
|
+
sl.response_group = ResponseGroup.new( :SellerListing )
|
31
|
+
response = @req.search( sl )
|
32
|
+
|
33
|
+
items = response.seller_listing_search_response[0].seller_listings[0].
|
34
|
+
seller_listing
|
35
|
+
|
36
|
+
# Ensure we got some actual items back.
|
37
|
+
#
|
38
|
+
assert( items.size > 0 )
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_seller_listing_search_class_method
|
43
|
+
|
44
|
+
response = Amazon::AWS.seller_listing_search( 'AP8U6Y3PYQ9VO',
|
45
|
+
{ 'Keywords' => 'Killing Joke' } )
|
46
|
+
|
47
|
+
items = response.seller_listing_search_response[0].seller_listings[0].
|
48
|
+
seller_listing
|
49
|
+
|
50
|
+
# Ensure we got some actual items back.
|
51
|
+
#
|
52
|
+
assert( items.size > 0 )
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_seller_listing_search_class_method_block
|
57
|
+
|
58
|
+
Amazon::AWS.seller_listing_search( 'AP8U6Y3PYQ9VO',
|
59
|
+
{ 'Keywords' => 'Killing Joke' } ) do |r|
|
60
|
+
|
61
|
+
items = r.seller_listing_search_response[0].seller_listings[0].
|
62
|
+
seller_listing
|
63
|
+
|
64
|
+
# Ensure we got some actual items back.
|
65
|
+
#
|
66
|
+
assert( items.size > 0 )
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|