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
@@ -0,0 +1,265 @@
1
+ # $Id: tc_multiple_operation.rb,v 1.3 2009/06/15 21:21:02 ianmacd Exp $
2
+ #
3
+
4
+ require 'test/unit'
5
+ require './setup'
6
+
7
+ class TestMultipleOperation < AWSTest
8
+
9
+ def test_unbatched_multiple_same_class_with_separate_response_groups
10
+ il = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000AE4QEC',
11
+ 'MerchantId' => 'Amazon' } )
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',
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' } )
169
+
170
+ # Create a batch request of the two ItemLookup operations.
171
+ #
172
+ il.batch( il2 )
173
+
174
+ is = ItemSearch.new( 'Books', { 'Title' => 'Ruby' } )
175
+
176
+ # Create a multiple operation of the ItemSearch operation and the two
177
+ # batched ItemLookup operations.
178
+ #
179
+ mo = MultipleOperation.new( is, il )
180
+
181
+ response = @req.search( mo, @rg )
182
+
183
+ mor = response.multi_operation_response[0]
184
+
185
+ # Ensure we received a MultiOperationResponse.
186
+ #
187
+ assert_instance_of( Amazon::AWS::AWSObject::MultiOperationResponse, mor )
188
+
189
+ # Ensure response contains an ItemSearchResponse.
190
+ #
191
+ assert_instance_of( Amazon::AWS::AWSObject::ItemSearchResponse,
192
+ mor.item_search_response[0] )
193
+
194
+ # Ensure response also contains an ItemLookupResponse.
195
+ #
196
+ assert_instance_of( Amazon::AWS::AWSObject::ItemLookupResponse,
197
+ mor.item_lookup_response[0] )
198
+
199
+ is_set = response.multi_operation_response.item_search_response[0].items
200
+ il_set = response.multi_operation_response.item_lookup_response[0].items
201
+ is_arr = is_set.item
202
+ il_arr1 = il_set[0].item
203
+ il_arr2 = il_set[1].item
204
+
205
+ # Ensure that there's one <ItemSet> for the ItemSearch.
206
+ #
207
+ assert_equal( 1, is_set.size )
208
+
209
+ # Ensure that there are two <ItemSet>s for the ItemLookup, because it was
210
+ # a batched operation.
211
+ #
212
+ assert_equal( 2, il_set.size )
213
+
214
+ # Assure that all item sets have some results.
215
+ #
216
+ assert( is_arr.size > 0 )
217
+ assert( il_arr1.size > 0 )
218
+ assert( il_arr2.size > 0 )
219
+ end
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
+
265
+ end
@@ -0,0 +1,58 @@
1
+ # $Id: tc_operation_request.rb,v 1.1 2008/05/19 10:17:26 ianmacd Exp $
2
+ #
3
+
4
+ require 'test/unit'
5
+ require './setup'
6
+
7
+ class TestOperationRequest < AWSTest
8
+
9
+ def test_operation_request
10
+ is = ItemSearch.new( 'Books', { 'Title' => 'Ruby' } )
11
+ response = @req.search( is, ResponseGroup.new( 'Request' ) )
12
+
13
+ # Same again with Symbols.
14
+ #
15
+ is = ItemSearch.new( :Books, { :Title => 'Ruby' } )
16
+ response = @req.search( is, ResponseGroup.new( :Request ) )
17
+
18
+ # Make sure undocumented AWSObject#results provides an accurate shortcut
19
+ # to the most interesting part of the data returned by AWS.
20
+ #
21
+ assert_equal( response.item_search_response[0].items[0].item,
22
+ response.kernel )
23
+
24
+ # Ensure response is an Amazon::AWS::AWSObject.
25
+ #
26
+ assert_instance_of( Amazon::AWS::AWSObject, response )
27
+
28
+ # Ensure non-existent instance variables return nil.
29
+ #
30
+ assert_nil( response.foo_bar_baz )
31
+
32
+ # Ensure top level of response is an Amazon::AWS::AWSArray.
33
+ #
34
+ assert_instance_of( Amazon::AWS::AWSArray, response.item_search_response )
35
+
36
+ # Ensure delegation of method from AWSArray to single element.
37
+ #
38
+ assert_equal( response.item_search_response[0].operation_request,
39
+ response.item_search_response.operation_request )
40
+
41
+ # Test for correct user-agent in response.
42
+ #
43
+ assert_equal( Amazon::AWS::USER_AGENT,
44
+ response.item_search_response[0].operation_request[0].
45
+ http_headers[0].header[0].attrib['value'] )
46
+
47
+ # Ensure that the correct version of the AWS API was requested.
48
+ #
49
+ response.item_search_response[0].operation_request[0].arguments[0].
50
+ argument.each do |arg|
51
+ next unless arg.attrib['name'] == 'Version'
52
+ assert_equal( Amazon::AWS::SERVICE['Version'], arg.attrib['value'] )
53
+ break
54
+ end
55
+
56
+ end
57
+
58
+ 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
@@ -0,0 +1,54 @@
1
+ # $Id: tc_seller_lookup.rb,v 1.1 2009/06/03 09:53:02 ianmacd Exp $
2
+ #
3
+
4
+ require 'test/unit'
5
+ require './setup'
6
+
7
+ class TestSellerLookup < AWSTest
8
+
9
+ def test_seller_lookup
10
+
11
+ sl = SellerLookup.new( 'A3QFR0K2KCB7EG' )
12
+ rg = ResponseGroup.new( 'Seller' )
13
+ response = @req.search( sl, rg )
14
+
15
+ seller = response.kernel
16
+
17
+ assert_equal( 'wherehouse', seller.nickname )
18
+
19
+ end
20
+
21
+ def test_seller_lookup_no_response_group
22
+
23
+ sl = SellerLookup.new( 'A3QFR0K2KCB7EG' )
24
+ sl.response_group = ResponseGroup.new( :Seller )
25
+ response = @req.search( sl )
26
+
27
+ seller = response.kernel
28
+
29
+ assert_equal( 'wherehouse', seller.nickname )
30
+
31
+ end
32
+
33
+ def test_seller_lookup_class_method
34
+
35
+ response = Amazon::AWS.seller_lookup( 'A3QFR0K2KCB7EG' )
36
+
37
+ seller = response.kernel
38
+
39
+ assert_equal( 'wherehouse', seller.nickname )
40
+
41
+ end
42
+
43
+ def test_seller_lookup_class_method_block
44
+
45
+ Amazon::AWS.seller_lookup( 'A3QFR0K2KCB7EG' ) do |r|
46
+
47
+ seller = r.kernel
48
+
49
+ assert_equal( 'wherehouse', seller.nickname )
50
+
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,103 @@
1
+ # $Id: tc_serialisation.rb,v 1.2 2008/06/22 21:18:50 ianmacd Exp $
2
+ #
3
+
4
+ require 'test/unit'
5
+ require './setup'
6
+ require 'yaml'
7
+ require 'tempfile'
8
+
9
+ class AWSSerialisationTest < AWSTest
10
+
11
+ def test_yaml_load
12
+
13
+ results_file = Tempfile.new( 'ruby_aws' )
14
+
15
+ # Serialise some results.
16
+ #
17
+ is = ItemSearch.new( 'Music', { 'Artist' => 'Voice Of The Beehive' } )
18
+ response = @req.search( is, @rg )
19
+ results = response.kernel
20
+
21
+ YAML.dump( results, results_file )
22
+ results = nil
23
+
24
+ # Remove knowledge of Amazon::AWS::AWSObject, so that YAML.load knows
25
+ # nothing of its subclasses.
26
+ #
27
+ Amazon::AWS.module_eval( %Q( remove_const :AWSObject ) )
28
+
29
+ # Silence warnings about redefined constants.
30
+ #
31
+ v = $VERBOSE
32
+ $VERBOSE = nil
33
+
34
+ # Reload Amazon::AWS and friends.
35
+ #
36
+ load 'amazon/aws.rb'
37
+
38
+ # Reset warning status.
39
+ #
40
+ $VERBOSE = v
41
+
42
+ # Demonstrate that normal YAML.load can't cope with instantiating objects
43
+ # from classes it knows nothing about.
44
+ #
45
+ results_file.open
46
+ results = YAML.load( results_file )
47
+ assert_instance_of( YAML::Object, results[0] )
48
+
49
+ # Ensure that AWSObject.yaml_load does the right thing.
50
+ #
51
+ results_file.open
52
+ results = Amazon::AWS::AWSObject.yaml_load( results_file )
53
+ assert_instance_of( Amazon::AWS::AWSObject::Item, results[0] )
54
+ end
55
+
56
+
57
+ def test_marshal_load
58
+
59
+ results_file = Tempfile.new( 'ruby_aws' )
60
+
61
+ # Serialise some results.
62
+ #
63
+ is = ItemSearch.new( 'Music', { 'Artist' => 'Voice Of The Beehive' } )
64
+ response = @req.search( is, @rg )
65
+ results = response.kernel
66
+
67
+ results_file.puts Marshal.dump( results )
68
+ results = nil
69
+
70
+ # Remove knowledge of Amazon::AWS::AWSObject, so that Marshal.load knows
71
+ # nothing of its subclasses.
72
+ #
73
+ Amazon::AWS.module_eval( %Q( remove_const :AWSObject ) )
74
+
75
+ # Silence warnings about redefined constants.
76
+ #
77
+ v = $VERBOSE
78
+ $VERBOSE = nil
79
+
80
+ # Reload Amazon::AWS and friends.
81
+ #
82
+ load 'amazon/aws.rb'
83
+
84
+ # Reset warning status.
85
+ #
86
+ $VERBOSE = v
87
+
88
+ # Demonstrate that normal Marshal.load can't cope with instantiating
89
+ # objects from classes it knows nothing about.
90
+ #
91
+ results_file.open
92
+
93
+ assert_raise ArgumentError do
94
+ Marshal.load( results_file )
95
+ end
96
+
97
+ # Ensure that Amazon::AWS::AWSObject.load does the right thing.
98
+ #
99
+ results_file.open
100
+ results = Amazon::AWS::AWSObject.load( results_file )
101
+ assert_instance_of( Amazon::AWS::AWSObject::Item, results[0] )
102
+ end
103
+ end