papercavalier-ruby-aaws 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/COPYING +340 -0
- data/INSTALL +260 -0
- data/NEWS +808 -0
- data/README +679 -0
- data/README.rdoc +140 -0
- data/Rakefile +17 -0
- data/VERSION.yml +5 -0
- data/example/batch_operation +28 -0
- data/example/browse_node_lookup1 +46 -0
- data/example/customer_content_lookup1 +27 -0
- data/example/customer_content_search1 +21 -0
- data/example/example1 +78 -0
- data/example/help1 +24 -0
- data/example/item_lookup1 +56 -0
- data/example/item_lookup2 +56 -0
- data/example/item_search1 +30 -0
- data/example/item_search2 +37 -0
- data/example/item_search3 +23 -0
- data/example/list_lookup1 +29 -0
- data/example/list_search1 +30 -0
- data/example/multiple_operation1 +69 -0
- data/example/seller_listing_lookup1 +30 -0
- data/example/seller_listing_search1 +29 -0
- data/example/seller_lookup1 +45 -0
- data/example/shopping_cart1 +42 -0
- data/example/similarity_lookup1 +48 -0
- data/example/tag_lookup1 +34 -0
- data/example/transaction_lookup1 +25 -0
- data/example/vehicle_search +22 -0
- data/lib/amazon.rb +165 -0
- data/lib/amazon/aws.rb +1493 -0
- data/lib/amazon/aws/cache.rb +141 -0
- data/lib/amazon/aws/search.rb +464 -0
- data/lib/amazon/aws/shoppingcart.rb +537 -0
- data/lib/amazon/locale.rb +102 -0
- data/test/setup.rb +56 -0
- data/test/tc_amazon.rb +20 -0
- data/test/tc_aws.rb +160 -0
- data/test/tc_browse_node_lookup.rb +49 -0
- data/test/tc_customer_content_lookup.rb +49 -0
- data/test/tc_help.rb +44 -0
- data/test/tc_item_lookup.rb +47 -0
- data/test/tc_item_search.rb +105 -0
- data/test/tc_list_lookup.rb +60 -0
- data/test/tc_list_search.rb +44 -0
- data/test/tc_multiple_operation.rb +375 -0
- data/test/tc_operation_request.rb +64 -0
- data/test/tc_seller_listing_lookup.rb +47 -0
- data/test/tc_seller_listing_search.rb +55 -0
- data/test/tc_seller_lookup.rb +44 -0
- data/test/tc_serialisation.rb +107 -0
- data/test/tc_shopping_cart.rb +214 -0
- data/test/tc_similarity_lookup.rb +48 -0
- data/test/tc_tag_lookup.rb +24 -0
- data/test/tc_transaction_lookup.rb +24 -0
- data/test/tc_vehicle_operations.rb +118 -0
- data/test/ts_aws.rb +24 -0
- metadata +141 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
# $Id: tc_item_lookup.rb,v 1.3 2010/02/20 17:15:17 ianmacd Exp $
|
2
|
+
#
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require './setup'
|
6
|
+
|
7
|
+
class TestItemLookup < AWSTest
|
8
|
+
|
9
|
+
def test_item_lookup
|
10
|
+
|
11
|
+
is = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000AE4QEC' } )
|
12
|
+
is.response_group = @rg
|
13
|
+
response = @req.search( is )
|
14
|
+
|
15
|
+
results = response.kernel
|
16
|
+
|
17
|
+
# Ensure we got some actual results back.
|
18
|
+
#
|
19
|
+
assert( results.size > 0 )
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_item_lookup_class_method
|
24
|
+
|
25
|
+
response = Amazon::AWS.item_lookup( 'ASIN', { 'ItemId' => 'B000AE4QEC' } )
|
26
|
+
|
27
|
+
results = response.kernel
|
28
|
+
|
29
|
+
# Ensure we got some actual results back.
|
30
|
+
#
|
31
|
+
assert( results.size > 0 )
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_item_search_class_method_block
|
36
|
+
|
37
|
+
Amazon::AWS.item_lookup( 'ASIN', { 'ItemId' => 'B000AE4QEC' } ) do |r|
|
38
|
+
|
39
|
+
results = r.kernel
|
40
|
+
|
41
|
+
# Ensure we got some actual results back.
|
42
|
+
#
|
43
|
+
assert( results.size > 0 )
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# encoding: ASCII-8BIT
|
2
|
+
#
|
3
|
+
# $Id: tc_item_search.rb,v 1.8 2010/02/20 23:57:26 ianmacd Exp $
|
4
|
+
#
|
5
|
+
# The encoding at the top of this file is necessary for Ruby 1.9, which will
|
6
|
+
# otherwise choke with 'invalid multibyte char (US-ASCII)' when it reads the
|
7
|
+
# ISO-8859-1 encoded accented 'e' in the test_item_search_iso_8859_15 method.
|
8
|
+
|
9
|
+
require 'test/unit'
|
10
|
+
require './setup'
|
11
|
+
|
12
|
+
class TestItemSearch < AWSTest
|
13
|
+
|
14
|
+
def test_item_search_iso_8859_15
|
15
|
+
|
16
|
+
# Ensure that character set encoding works properly by manually trying
|
17
|
+
# ISO-8859-15, a.k.a. Latin-15.
|
18
|
+
#
|
19
|
+
@req.encoding = 'iso-8859-15'
|
20
|
+
|
21
|
+
str = 'Caf�'
|
22
|
+
is = ItemSearch.new( 'Books', { 'Title' => str } )
|
23
|
+
response = @req.search( is )
|
24
|
+
|
25
|
+
results = response.kernel
|
26
|
+
|
27
|
+
# Ensure we got some actual results back.
|
28
|
+
#
|
29
|
+
assert( results.size > 0 )
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_item_search_utf8
|
34
|
+
|
35
|
+
# Manually set UTF-8 encoding.
|
36
|
+
#
|
37
|
+
@req.encoding = 'utf-8'
|
38
|
+
|
39
|
+
str = 'Café'
|
40
|
+
is = ItemSearch.new( 'Books', { 'Title' => str } )
|
41
|
+
response = @req.search( is )
|
42
|
+
|
43
|
+
results = response.kernel
|
44
|
+
|
45
|
+
# Ensure we got some actual results back.
|
46
|
+
#
|
47
|
+
assert( results.size > 0 )
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_item_search_obsolete_rg_passing
|
52
|
+
|
53
|
+
# Manually set UTF-8 encoding.
|
54
|
+
#
|
55
|
+
@req.encoding = 'utf-8'
|
56
|
+
|
57
|
+
str = 'Café'
|
58
|
+
is = ItemSearch.new( 'Books', { 'Title' => str } )
|
59
|
+
|
60
|
+
assert_raise( Amazon::AWS::ObsolescenceError ) do
|
61
|
+
response = @req.search( is, @rg )
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_item_search_multiple_pages
|
67
|
+
|
68
|
+
@req.encoding = 'utf-8'
|
69
|
+
is = ItemSearch.new( 'Books', { 'Title' => 'programming' } )
|
70
|
+
responses = @req.search( is, 5 )
|
71
|
+
|
72
|
+
results = []
|
73
|
+
responses.each { |response| results += response.kernel }
|
74
|
+
|
75
|
+
# Ensure we got more than 10 results back.
|
76
|
+
#
|
77
|
+
assert( results.size > 10 )
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_item_search_class_method
|
82
|
+
|
83
|
+
response = Amazon::AWS.item_search( 'Books', { 'Title' => 'programming' } )
|
84
|
+
|
85
|
+
results = response.kernel
|
86
|
+
|
87
|
+
# Ensure we got some actual results back.
|
88
|
+
#
|
89
|
+
assert( results.size > 0 )
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_item_search_class_method_block
|
94
|
+
|
95
|
+
Amazon::AWS.item_search( 'Books', { 'Title' => 'programming' } ) do |r|
|
96
|
+
|
97
|
+
results = r.kernel
|
98
|
+
|
99
|
+
# Ensure we got some actual results back.
|
100
|
+
#
|
101
|
+
assert( results.size > 0 )
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# $Id: tc_list_lookup.rb,v 1.4 2010/02/20 17:15:17 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
|
+
ll = ListLookup.new( '3TV12MGLOJI4R', :WishList )
|
13
|
+
ll_rg = ResponseGroup.new( :ListInfo )
|
14
|
+
ll.response_group = ll_rg
|
15
|
+
|
16
|
+
response = @req.search( ll )
|
17
|
+
|
18
|
+
list = response.kernel
|
19
|
+
|
20
|
+
assert_equal( '2008-06-30', list.date_created )
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_list_lookup_all_pages
|
25
|
+
|
26
|
+
@req.locale = 'uk'
|
27
|
+
ll = ListLookup.new( '1OPRRUVZVU9BE', 'WishList' )
|
28
|
+
ll_rg = ResponseGroup.new( 'ListInfo', 'Small' )
|
29
|
+
ll.response_group = ll_rg
|
30
|
+
|
31
|
+
response = @req.search( ll, :ALL_PAGES )
|
32
|
+
|
33
|
+
list = response.collect { |r| r.list_lookup_response[0].lists[0].list }
|
34
|
+
reported_items = list[0].total_items.to_i
|
35
|
+
items = list.collect { |page| page.list_item }.flatten
|
36
|
+
|
37
|
+
assert_equal( reported_items, items.size )
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_list_lookup_class_method
|
41
|
+
|
42
|
+
response = Amazon::AWS.list_lookup( 'R35BA7X0YD3YP', 'Listmania' )
|
43
|
+
|
44
|
+
list = response.kernel
|
45
|
+
|
46
|
+
assert_equal( 'examples of perfection', list.list_name )
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_item_search_class_method_block
|
51
|
+
|
52
|
+
Amazon::AWS.list_lookup( 'R35BA7X0YD3YP', :Listmania ) do |r|
|
53
|
+
|
54
|
+
list = r.kernel
|
55
|
+
|
56
|
+
assert_equal( 'examples of perfection', list.list_name )
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# $Id: tc_list_search.rb,v 1.3 2010/02/20 17:15:18 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
|
+
ls = ListSearch.new( 'WishList', { 'Name' => 'Peter Duff' } )
|
13
|
+
ls_rg = ResponseGroup.new( :ListInfo )
|
14
|
+
ls.response_group = ls_rg
|
15
|
+
|
16
|
+
response = @req.search( ls )
|
17
|
+
|
18
|
+
lists = response.kernel
|
19
|
+
|
20
|
+
assert( lists.collect { |l| l.list_id }.flatten.include?( '1L88A4AXYF5QR' ) )
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_list_search_class_method
|
25
|
+
|
26
|
+
response = Amazon::AWS.list_search( 'WishList', { :Name => 'Peter Duff' } )
|
27
|
+
|
28
|
+
lists = response.kernel
|
29
|
+
|
30
|
+
assert( lists.size > 5 )
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_item_search_class_method_block
|
35
|
+
|
36
|
+
Amazon::AWS.list_search( 'WishList', { 'Name' => 'Peter Duff' } ) do |r|
|
37
|
+
|
38
|
+
lists = r.kernel
|
39
|
+
|
40
|
+
assert( lists.size > 5 )
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,375 @@
|
|
1
|
+
# $Id: tc_multiple_operation.rb,v 1.4 2010/02/20 17:32:12 ianmacd Exp $
|
2
|
+
#
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require './setup'
|
6
|
+
|
7
|
+
class TestMultipleOperation < AWSTest
|
8
|
+
|
9
|
+
# Because exception classes aren't created until an exception occurs, we
|
10
|
+
# need to create the ones we wish to test for now, otherwise we can't refer
|
11
|
+
# to them in our code without causing an 'uninitialized constant' error.
|
12
|
+
#
|
13
|
+
Amazon::AWS::Error.const_set( 'ExceededMaxBatchRequestsPerOperation',
|
14
|
+
Class.new( Amazon::AWS::Error::AWSError ) )
|
15
|
+
Amazon::AWS::Error.const_set( 'ExceededMaxMultiOpOperations',
|
16
|
+
Class.new( Amazon::AWS::Error::AWSError ) )
|
17
|
+
|
18
|
+
def test_unbatched_same_class
|
19
|
+
il = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000AE4QEC',
|
20
|
+
'MerchantId' => 'Amazon' } )
|
21
|
+
il2 = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000051WBE',
|
22
|
+
'MerchantId' => 'Amazon' } )
|
23
|
+
il3 = ItemLookup.new( 'ASIN', { 'ItemId' => 'B00061F8LO',
|
24
|
+
'MerchantId' => 'Amazon' } )
|
25
|
+
il4 = ItemLookup.new( 'ASIN', { 'ItemId' => 'B002DESIE6',
|
26
|
+
'MerchantId' => 'Amazon' } )
|
27
|
+
|
28
|
+
il.response_group = ResponseGroup.new( :Large )
|
29
|
+
il2.response_group = ResponseGroup.new( :Small )
|
30
|
+
|
31
|
+
# Create a multiple operation of the two ItemLookup operations.
|
32
|
+
#
|
33
|
+
mo = MultipleOperation.new( il, il2 )
|
34
|
+
response = @req.search( mo )
|
35
|
+
mor = response.item_lookup_response[0]
|
36
|
+
|
37
|
+
# Ensure our separate response groups were used.
|
38
|
+
#
|
39
|
+
arguments = mor.operation_request.arguments.argument
|
40
|
+
|
41
|
+
il_rg = arguments.select do |arg|
|
42
|
+
arg.attrib['name'] == 'ItemLookup.1.ResponseGroup'
|
43
|
+
end[0]
|
44
|
+
|
45
|
+
il2_rg = arguments.select do |arg|
|
46
|
+
arg.attrib['name'] == 'ItemLookup.2.ResponseGroup'
|
47
|
+
end[0]
|
48
|
+
|
49
|
+
assert_equal( 'Large', il_rg.attrib['value'] )
|
50
|
+
assert_equal( 'Small', il2_rg.attrib['value'] )
|
51
|
+
|
52
|
+
# Ensure we received a MultiOperationResponse.
|
53
|
+
#
|
54
|
+
assert_instance_of( Amazon::AWS::AWSObject::ItemLookupResponse, mor )
|
55
|
+
|
56
|
+
il_set = mor.items
|
57
|
+
il_arr1 = il_set[0].item
|
58
|
+
il_arr2 = il_set[1].item
|
59
|
+
|
60
|
+
# Ensure that there are two <ItemSet>s for the ItemLookup, because it was
|
61
|
+
# a batched operation.
|
62
|
+
#
|
63
|
+
assert_equal( 2, il_set.size )
|
64
|
+
|
65
|
+
# Assure that all item sets have some results.
|
66
|
+
#
|
67
|
+
assert( il_arr1.size > 0 )
|
68
|
+
assert( il_arr2.size > 0 )
|
69
|
+
|
70
|
+
mo = MultipleOperation.new( il, il2, il3 )
|
71
|
+
|
72
|
+
# Attempt to perform the search.
|
73
|
+
#
|
74
|
+
assert_raise( Amazon::AWS::Error::ExceededMaxBatchRequestsPerOperation ) do
|
75
|
+
@req.search( mo )
|
76
|
+
end
|
77
|
+
|
78
|
+
mo = MultipleOperation.new( il, il2, il3, il4 )
|
79
|
+
assert_raise( Amazon::AWS::Error::ExceededMaxBatchRequestsPerOperation ) do
|
80
|
+
@req.search( mo )
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def test_batched_same_class
|
86
|
+
il = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000AE4QEC',
|
87
|
+
'MerchantId' => 'Amazon' } )
|
88
|
+
il2 = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000051WBE',
|
89
|
+
'MerchantId' => 'Amazon' } )
|
90
|
+
il3 = ItemLookup.new( 'ASIN', { 'ItemId' => 'B00061F8LO',
|
91
|
+
'MerchantId' => 'Amazon' } )
|
92
|
+
il4 = ItemLookup.new( 'ASIN', { 'ItemId' => 'B002DESIE6',
|
93
|
+
'MerchantId' => 'Amazon' } )
|
94
|
+
|
95
|
+
il.response_group = ResponseGroup.new( :Large )
|
96
|
+
il2.response_group = ResponseGroup.new( :Small )
|
97
|
+
|
98
|
+
il.batch( il2 )
|
99
|
+
il3.batch( il4 )
|
100
|
+
|
101
|
+
# Create a multiple operation of the two batched operations.
|
102
|
+
#
|
103
|
+
mo = MultipleOperation.new( il, il3 )
|
104
|
+
|
105
|
+
# Attempt to perform the search.
|
106
|
+
#
|
107
|
+
assert_raise( Amazon::AWS::Error::ExceededMaxBatchRequestsPerOperation ) do
|
108
|
+
@req.search( mo )
|
109
|
+
end
|
110
|
+
|
111
|
+
# Create a multiple operation of a single operation, plus a batched.
|
112
|
+
#
|
113
|
+
mo = MultipleOperation.new( il2, il3 )
|
114
|
+
|
115
|
+
# Attempt to perform the search.
|
116
|
+
#
|
117
|
+
assert_raise( Amazon::AWS::Error::ExceededMaxBatchRequestsPerOperation ) do
|
118
|
+
@req.search( mo )
|
119
|
+
end
|
120
|
+
|
121
|
+
# Create a multiple operation of a batched operation, plus a single.
|
122
|
+
#
|
123
|
+
mo = MultipleOperation.new( il, il4 )
|
124
|
+
|
125
|
+
# Attempt to perform the search.
|
126
|
+
#
|
127
|
+
assert_raise( Amazon::AWS::Error::ExceededMaxBatchRequestsPerOperation ) do
|
128
|
+
@req.search( mo )
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
def test_unbatched_different_class
|
135
|
+
il = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000AE4QEC',
|
136
|
+
'MerchantId' => 'Amazon' } )
|
137
|
+
is = ItemSearch.new( 'Books', { 'Title' => 'Ruby' } )
|
138
|
+
bnl = BrowseNodeLookup.new( 694212 )
|
139
|
+
|
140
|
+
il.response_group = ResponseGroup.new( :Medium )
|
141
|
+
is.response_group = ResponseGroup.new( :Medium, :Tags )
|
142
|
+
bnl.response_group = ResponseGroup.new( :BrowseNodeInfo )
|
143
|
+
|
144
|
+
# Create a multiple operation of the ItemSearch operation and the
|
145
|
+
# ItemLookup operation.
|
146
|
+
#
|
147
|
+
mo = MultipleOperation.new( is, il )
|
148
|
+
response = @req.search( mo )
|
149
|
+
mor = response.multi_operation_response[0]
|
150
|
+
|
151
|
+
# Ensure our separate response groups were used.
|
152
|
+
#
|
153
|
+
arguments = mor.operation_request.arguments.argument
|
154
|
+
|
155
|
+
il_rg = arguments.select do |arg|
|
156
|
+
arg.attrib['name'] == 'ItemLookup.1.ResponseGroup'
|
157
|
+
end[0]
|
158
|
+
|
159
|
+
is_rg = arguments.select do |arg|
|
160
|
+
arg.attrib['name'] == 'ItemSearch.1.ResponseGroup'
|
161
|
+
end[0]
|
162
|
+
|
163
|
+
assert_equal( 'Medium', il_rg.attrib['value'] )
|
164
|
+
assert_equal( 'Medium,Tags', is_rg.attrib['value'] )
|
165
|
+
|
166
|
+
# Ensure we received a MultiOperationResponse.
|
167
|
+
#
|
168
|
+
assert_instance_of( Amazon::AWS::AWSObject::MultiOperationResponse, mor )
|
169
|
+
|
170
|
+
# Ensure response contains an ItemSearchResponse.
|
171
|
+
#
|
172
|
+
assert_instance_of( Amazon::AWS::AWSObject::ItemSearchResponse,
|
173
|
+
mor.item_search_response[0] )
|
174
|
+
|
175
|
+
# Ensure response also contains an ItemLookupResponse.
|
176
|
+
#
|
177
|
+
assert_instance_of( Amazon::AWS::AWSObject::ItemLookupResponse,
|
178
|
+
mor.item_lookup_response[0] )
|
179
|
+
|
180
|
+
is_set = mor.item_search_response[0].items
|
181
|
+
il_set = mor.item_lookup_response[0].items
|
182
|
+
is_arr = is_set.item
|
183
|
+
il_arr = il_set.item
|
184
|
+
|
185
|
+
# Ensure that there's one <ItemSet> for the ItemSearch.
|
186
|
+
#
|
187
|
+
assert_equal( 1, is_set.size )
|
188
|
+
|
189
|
+
# Ensure that there's one <ItemSet> for the ItemLookup.
|
190
|
+
#
|
191
|
+
assert_equal( 1, il_set.size )
|
192
|
+
|
193
|
+
# Assure that all item sets have some results.
|
194
|
+
#
|
195
|
+
assert( is_arr.size > 0 )
|
196
|
+
assert( il_arr.size > 0 )
|
197
|
+
|
198
|
+
mo = MultipleOperation.new( is, il, bnl )
|
199
|
+
assert_raise( Amazon::AWS::Error::ExceededMaxMultiOpOperations ) do
|
200
|
+
@req.search( mo )
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
|
205
|
+
def test_batched_different_class
|
206
|
+
il = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000AE4QEC',
|
207
|
+
'MerchantId' => 'Amazon' } )
|
208
|
+
il2 = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000051WBE',
|
209
|
+
'MerchantId' => 'Amazon' } )
|
210
|
+
il3 = ItemLookup.new( 'ASIN', { 'ItemId' => 'B00061F8LO',
|
211
|
+
'MerchantId' => 'Amazon' } )
|
212
|
+
is = ItemSearch.new( 'Books', { 'Title' => 'Ruby' } )
|
213
|
+
is2 = ItemSearch.new( 'Music', { 'Artist' => 'Dead Can Dance' } )
|
214
|
+
bnl = BrowseNodeLookup.new( 694212 )
|
215
|
+
|
216
|
+
il.response_group = ResponseGroup.new( :Medium )
|
217
|
+
il2.response_group = ResponseGroup.new( :Large )
|
218
|
+
is.response_group = ResponseGroup.new( :Medium, :Tags )
|
219
|
+
is2.response_group = ResponseGroup.new( :Small, :Reviews )
|
220
|
+
bnl.response_group = ResponseGroup.new( :BrowseNodeInfo )
|
221
|
+
|
222
|
+
# Create a multiple operation of two batched ItemSearch operations and two
|
223
|
+
# batched ItemLookup operations.
|
224
|
+
#
|
225
|
+
il.batch( il2 )
|
226
|
+
is.batch( is2 )
|
227
|
+
|
228
|
+
mo = MultipleOperation.new( [ is, il ] )
|
229
|
+
response = @req.search( mo )
|
230
|
+
mor = response.multi_operation_response[0]
|
231
|
+
|
232
|
+
# Ensure our separate response groups were used.
|
233
|
+
#
|
234
|
+
arguments = mor.operation_request.arguments.argument
|
235
|
+
|
236
|
+
il_rg = arguments.select do |arg|
|
237
|
+
arg.attrib['name'] == 'ItemLookup.1.ResponseGroup'
|
238
|
+
end[0]
|
239
|
+
|
240
|
+
il2_rg = arguments.select do |arg|
|
241
|
+
arg.attrib['name'] == 'ItemLookup.2.ResponseGroup'
|
242
|
+
end[0]
|
243
|
+
|
244
|
+
is_rg = arguments.select do |arg|
|
245
|
+
arg.attrib['name'] == 'ItemSearch.1.ResponseGroup'
|
246
|
+
end[0]
|
247
|
+
|
248
|
+
is2_rg = arguments.select do |arg|
|
249
|
+
arg.attrib['name'] == 'ItemSearch.2.ResponseGroup'
|
250
|
+
end[0]
|
251
|
+
|
252
|
+
assert_equal( 'Medium', il_rg.attrib['value'] )
|
253
|
+
assert_equal( 'Large', il2_rg.attrib['value'] )
|
254
|
+
assert_equal( 'Medium,Tags', is_rg.attrib['value'] )
|
255
|
+
assert_equal( 'Small,Reviews', is2_rg.attrib['value'] )
|
256
|
+
|
257
|
+
# Check to see whether we can set the response group for all encapsulated
|
258
|
+
# operations with a single assignment.
|
259
|
+
#
|
260
|
+
mo.response_group = ResponseGroup.new( :Small )
|
261
|
+
response = @req.search( mo )
|
262
|
+
mor = response.multi_operation_response[0]
|
263
|
+
|
264
|
+
arguments = mor.operation_request.arguments.argument
|
265
|
+
|
266
|
+
il_rg = arguments.select do |arg|
|
267
|
+
arg.attrib['name'] == 'ItemLookup.1.ResponseGroup'
|
268
|
+
end[0]
|
269
|
+
|
270
|
+
il2_rg = arguments.select do |arg|
|
271
|
+
arg.attrib['name'] == 'ItemLookup.2.ResponseGroup'
|
272
|
+
end[0]
|
273
|
+
|
274
|
+
is_rg = arguments.select do |arg|
|
275
|
+
arg.attrib['name'] == 'ItemSearch.1.ResponseGroup'
|
276
|
+
end[0]
|
277
|
+
|
278
|
+
is2_rg = arguments.select do |arg|
|
279
|
+
arg.attrib['name'] == 'ItemSearch.2.ResponseGroup'
|
280
|
+
end[0]
|
281
|
+
|
282
|
+
assert_equal( 'Small', il_rg.attrib['value'] )
|
283
|
+
assert_equal( 'Small', il2_rg.attrib['value'] )
|
284
|
+
assert_equal( 'Small', is_rg.attrib['value'] )
|
285
|
+
assert_equal( 'Small', is2_rg.attrib['value'] )
|
286
|
+
|
287
|
+
# Ensure we received a MultiOperationResponse.
|
288
|
+
#
|
289
|
+
assert_instance_of( Amazon::AWS::AWSObject::MultiOperationResponse, mor )
|
290
|
+
|
291
|
+
# Ensure response contains an ItemSearchResponse.
|
292
|
+
#
|
293
|
+
assert_instance_of( Amazon::AWS::AWSObject::ItemSearchResponse,
|
294
|
+
mor.item_search_response[0] )
|
295
|
+
|
296
|
+
# Ensure response also contains an ItemLookupResponse.
|
297
|
+
#
|
298
|
+
assert_instance_of( Amazon::AWS::AWSObject::ItemLookupResponse,
|
299
|
+
mor.item_lookup_response[0] )
|
300
|
+
|
301
|
+
is_set = mor.item_search_response[0].items
|
302
|
+
il_set = mor.item_lookup_response[0].items
|
303
|
+
|
304
|
+
# Ensure that there are two <ItemSet>s for the ItemSearch.
|
305
|
+
#
|
306
|
+
assert_equal( 2, is_set.size )
|
307
|
+
|
308
|
+
# Ensure that there are two <ItemSet>s for the ItemLookup.
|
309
|
+
#
|
310
|
+
assert_equal( 2, il_set.size )
|
311
|
+
|
312
|
+
is_arr = is_set[0].item
|
313
|
+
is2_arr = is_set[1].item
|
314
|
+
il_arr = il_set[0].item
|
315
|
+
il2_arr = il_set[1].item
|
316
|
+
|
317
|
+
# Assure that all item sets have some results.
|
318
|
+
#
|
319
|
+
assert( is_arr.size > 0 )
|
320
|
+
assert( is2_arr.size > 0 )
|
321
|
+
assert( il_arr.size > 0 )
|
322
|
+
assert( il2_arr.size > 0 )
|
323
|
+
|
324
|
+
mo = MultipleOperation.new( [ is, il, bnl ] )
|
325
|
+
assert_raise( Amazon::AWS::Error::ExceededMaxMultiOpOperations ) do
|
326
|
+
@req.search( mo )
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
|
331
|
+
def test_multiple_class_method
|
332
|
+
il = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000AE4QEC',
|
333
|
+
'MerchantId' => 'Amazon' } )
|
334
|
+
il.response_group = ResponseGroup.new( :Large )
|
335
|
+
|
336
|
+
is = ItemSearch.new( 'Books', { 'Title' => 'Ruby' } )
|
337
|
+
is.response_group = ResponseGroup.new( :Medium, :Tags )
|
338
|
+
|
339
|
+
response = Amazon::AWS.multiple_operation( is, il )
|
340
|
+
mor = response.multi_operation_response[0]
|
341
|
+
|
342
|
+
# Ensure we received a MultiOperationResponse.
|
343
|
+
#
|
344
|
+
assert_instance_of( Amazon::AWS::AWSObject::MultiOperationResponse, mor )
|
345
|
+
|
346
|
+
# Ensure response contains an ItemSearchResponse.
|
347
|
+
#
|
348
|
+
assert_instance_of( Amazon::AWS::AWSObject::ItemSearchResponse,
|
349
|
+
mor.item_search_response[0] )
|
350
|
+
|
351
|
+
# Ensure response also contains an ItemLookupResponse.
|
352
|
+
#
|
353
|
+
assert_instance_of( Amazon::AWS::AWSObject::ItemLookupResponse,
|
354
|
+
mor.item_lookup_response[0] )
|
355
|
+
|
356
|
+
is_set = response.multi_operation_response.item_search_response[0].items
|
357
|
+
il_set = response.multi_operation_response.item_lookup_response[0].items
|
358
|
+
is_arr = is_set.item
|
359
|
+
il_arr = il_set[0].item
|
360
|
+
|
361
|
+
# Ensure that there's one <ItemSet> for the ItemSearch.
|
362
|
+
#
|
363
|
+
assert_equal( 1, is_set.size )
|
364
|
+
|
365
|
+
# Ensure that there's one <ItemSet> for the ItemLookup.
|
366
|
+
#
|
367
|
+
assert_equal( 1, il_set.size )
|
368
|
+
|
369
|
+
# Assure that all item sets have some results.
|
370
|
+
#
|
371
|
+
assert( is_arr.size > 0 )
|
372
|
+
assert( il_arr.size > 0 )
|
373
|
+
end
|
374
|
+
|
375
|
+
end
|