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.
- data/COPYING +340 -0
- data/INSTALL +260 -0
- data/NEWS +710 -0
- data/README +653 -0
- data/README.rdoc +145 -0
- data/Rakefile +35 -0
- data/VERSION +1 -0
- data/example/batch_operation +27 -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 +87 -0
- data/example/help1 +25 -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 +68 -0
- data/example/seller_listing_lookup1 +30 -0
- data/example/seller_listing_search1 +28 -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 +26 -0
- data/example/vehicle_search +22 -0
- data/lib/amazon/aws/cache.rb +141 -0
- data/lib/amazon/aws/search.rb +342 -0
- data/lib/amazon/aws/shoppingcart.rb +504 -0
- data/lib/amazon/aws.rb +1217 -0
- data/lib/amazon/locale.rb +102 -0
- data/lib/amazon.rb +145 -0
- data/ruby-aaws.gemspec +117 -0
- data/setup.rb +1306 -0
- data/test/setup.rb +34 -0
- data/test/tc_amazon.rb +20 -0
- data/test/tc_aws.rb +151 -0
- 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 +106 -0
- data/test/tc_list_lookup.rb +55 -0
- data/test/tc_list_search.rb +55 -0
- data/test/tc_multiple_operation.rb +265 -0
- data/test/tc_operation_request.rb +58 -0
- 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_serialisation.rb +103 -0
- data/test/tc_shopping_cart.rb +214 -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/tc_vehicle_operations.rb +106 -0
- data/test/ts_aws.rb +24 -0
- metadata +135 -0
data/test/setup.rb
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# $Id: setup.rb,v 1.5 2009/06/14 00:28:48 ianmacd Exp $
|
|
2
|
+
#
|
|
3
|
+
|
|
4
|
+
# Attempt to load Ruby/AWS using RubyGems.
|
|
5
|
+
#
|
|
6
|
+
begin
|
|
7
|
+
require 'rubygems'
|
|
8
|
+
gem 'ruby-aws'
|
|
9
|
+
rescue LoadError
|
|
10
|
+
# Either we don't have RubyGems or we don't have a gem of Ruby/AWS.
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Require the essential library, be it via RubyGems or the default way.
|
|
14
|
+
#
|
|
15
|
+
require 'amazon/aws/search'
|
|
16
|
+
|
|
17
|
+
include Amazon::AWS
|
|
18
|
+
include Amazon::AWS::Search
|
|
19
|
+
|
|
20
|
+
class AWSTest < Test::Unit::TestCase
|
|
21
|
+
|
|
22
|
+
def setup
|
|
23
|
+
@rg = ResponseGroup.new( :Small )
|
|
24
|
+
@req = Request.new
|
|
25
|
+
@req.locale = 'uk'
|
|
26
|
+
@req.cache = false
|
|
27
|
+
@req.encoding = 'utf-8'
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# The default_test method needs to be removed before Ruby 1.9.0.
|
|
31
|
+
#
|
|
32
|
+
undef_method :default_test if method_defined? :default_test
|
|
33
|
+
|
|
34
|
+
end
|
data/test/tc_amazon.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# $Id: tc_amazon.rb,v 1.1 2008/05/19 10:17:26 ianmacd Exp $
|
|
2
|
+
#
|
|
3
|
+
|
|
4
|
+
require 'test/unit'
|
|
5
|
+
require './setup'
|
|
6
|
+
|
|
7
|
+
class TestAmazonBasics < AWSTest
|
|
8
|
+
|
|
9
|
+
def test_uncamelise
|
|
10
|
+
str = 'ALongStringWithACRONYM'
|
|
11
|
+
uncamel_str = 'a_long_string_with_acronym'
|
|
12
|
+
|
|
13
|
+
# Ensure uncamelisation of strings occurs properly.
|
|
14
|
+
#
|
|
15
|
+
assert_equal( uncamel_str, Amazon::uncamelise( str ) )
|
|
16
|
+
assert_equal( 'asin', Amazon::uncamelise( 'ASIN' ) )
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
data/test/tc_aws.rb
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# $Id: tc_aws.rb,v 1.12 2009/06/14 00:29:28 ianmacd Exp $
|
|
2
|
+
#
|
|
3
|
+
|
|
4
|
+
require 'test/unit'
|
|
5
|
+
require './setup'
|
|
6
|
+
require 'fileutils'
|
|
7
|
+
require 'tmpdir'
|
|
8
|
+
require 'amazon/locale'
|
|
9
|
+
|
|
10
|
+
class TestAWSBasics < AWSTest
|
|
11
|
+
|
|
12
|
+
CACHE_DIR = Amazon::AWS::Cache::DEFAULT_CACHE_DIR
|
|
13
|
+
CACHE_PATH = File.join( Dir.tmpdir, 'aws_cache' )
|
|
14
|
+
|
|
15
|
+
def test_version
|
|
16
|
+
v = '1.8.7'
|
|
17
|
+
assert( RUBY_VERSION >= v, "Ruby version is lower than #{v}." )
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_cache
|
|
21
|
+
|
|
22
|
+
# Assure we can create a cache with a non-default path.
|
|
23
|
+
#
|
|
24
|
+
c = Cache.new( CACHE_PATH )
|
|
25
|
+
assert( CACHE_PATH, c.path )
|
|
26
|
+
assert( File.directory?( c.path ) )
|
|
27
|
+
FileUtils.rmdir( c.path )
|
|
28
|
+
|
|
29
|
+
c = Cache.new
|
|
30
|
+
|
|
31
|
+
# Ensure that default cache path has been chosen.
|
|
32
|
+
#
|
|
33
|
+
assert( CACHE_DIR, c.path )
|
|
34
|
+
|
|
35
|
+
# Ensure that cache directory has been created.
|
|
36
|
+
#
|
|
37
|
+
assert( File.directory?( c.path ) )
|
|
38
|
+
|
|
39
|
+
f = File.join( c.path, 'foobar' )
|
|
40
|
+
|
|
41
|
+
# Just over a day ago.
|
|
42
|
+
#
|
|
43
|
+
t = Time.now - 86460
|
|
44
|
+
|
|
45
|
+
FileUtils.touch f, { :mtime => t }
|
|
46
|
+
assert( File.exist?( f ) )
|
|
47
|
+
|
|
48
|
+
# Ensure expired file is properly flushed.
|
|
49
|
+
#
|
|
50
|
+
c.flush_expired
|
|
51
|
+
assert( ! File.exist?( f ) )
|
|
52
|
+
|
|
53
|
+
FileUtils.touch f
|
|
54
|
+
assert( File.exist?( f ) )
|
|
55
|
+
|
|
56
|
+
# Ensure unexpired file is properly retained.
|
|
57
|
+
#
|
|
58
|
+
c.flush_expired
|
|
59
|
+
assert( File.exist?( f ) )
|
|
60
|
+
|
|
61
|
+
# Ensure file is properly flushed.
|
|
62
|
+
#
|
|
63
|
+
c.flush_all
|
|
64
|
+
assert( ! File.exist?( f ) )
|
|
65
|
+
|
|
66
|
+
h = Help.new( :ResponseGroup, :Large )
|
|
67
|
+
h_rg = ResponseGroup.new( :Help )
|
|
68
|
+
|
|
69
|
+
# Ensure that file is not cached when no cache is desired.
|
|
70
|
+
#
|
|
71
|
+
@req.cache = false
|
|
72
|
+
resp = @req.search( h, h_rg )
|
|
73
|
+
assert_equal( 0, Dir.glob( File.join( c.path, '*' ) ).size )
|
|
74
|
+
|
|
75
|
+
# Ensure that file is cached when cache is desired.
|
|
76
|
+
#
|
|
77
|
+
@req.cache = c
|
|
78
|
+
resp = @req.search( h, h_rg )
|
|
79
|
+
assert_equal( 1, Dir.glob( File.join( c.path, '*' ) ).size )
|
|
80
|
+
|
|
81
|
+
# Flush it away.
|
|
82
|
+
#
|
|
83
|
+
c.flush_all
|
|
84
|
+
assert_equal( 0, Dir.glob( File.join( c.path, '*' ) ).size )
|
|
85
|
+
|
|
86
|
+
FileUtils.rmdir( c.path )
|
|
87
|
+
|
|
88
|
+
# Turn off caching for future tests. This happens in the setup method,
|
|
89
|
+
# anyway, but it can't hurt to tidy up after ourselves.
|
|
90
|
+
#
|
|
91
|
+
@req.cache = false
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def test_config
|
|
96
|
+
# Test bad quoting.
|
|
97
|
+
#
|
|
98
|
+
assert_raise( Amazon::Config::ConfigError ) do
|
|
99
|
+
cf = Amazon::Config.new( <<' EOF' )
|
|
100
|
+
bad_syntax = 'bad quotes"
|
|
101
|
+
EOF
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Test good quoting.
|
|
105
|
+
#
|
|
106
|
+
assert_nothing_raised do
|
|
107
|
+
cf = Amazon::Config.new( <<' EOF' )
|
|
108
|
+
good_syntax = 'good quotes'
|
|
109
|
+
EOF
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Test that config files are properly read from $AMAZONRC.
|
|
113
|
+
#
|
|
114
|
+
Dir.mktmpdir do |td|
|
|
115
|
+
ENV['AMAZONRCDIR'] = td
|
|
116
|
+
ENV['AMAZONRCFILE'] = '.user_defined_name'
|
|
117
|
+
File.open( File.join( td, '.user_defined_name' ), 'w' ) do |tf|
|
|
118
|
+
tf.puts( 'foo = bar' )
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
cf = Amazon::Config.new
|
|
122
|
+
assert_equal( 'bar', cf['foo'] )
|
|
123
|
+
ENV['AMAZONRCDIR'] = nil
|
|
124
|
+
ENV['AMAZONRCFILE'] = nil
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def test_exceptions
|
|
129
|
+
assert_raise( Amazon::AWS::HTTPError ) { raise Amazon::AWS::HTTPError }
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
include Amazon
|
|
133
|
+
|
|
134
|
+
def test_geo
|
|
135
|
+
|
|
136
|
+
require 'net/geoip'
|
|
137
|
+
|
|
138
|
+
assert_equal( 'de', Locale.get_locale_by_name( 'www.marxer.org' ) )
|
|
139
|
+
assert_equal( 'jp', Locale.get_locale_by_name( 'ruby-lang.org' ) )
|
|
140
|
+
assert_equal( 'uk', Locale.get_locale_by_name( 'xs1.xs4all.nl' ) )
|
|
141
|
+
assert_equal( 'uk', Locale.get_locale_by_name( 'caliban.org' ) )
|
|
142
|
+
assert_equal( 'us', Locale.get_locale_by_name( 'google.com' ) )
|
|
143
|
+
|
|
144
|
+
# Ensure non-existent hostname causes an Amazon::Locale::GeoError.
|
|
145
|
+
#
|
|
146
|
+
assert_raise( Amazon::Locale::GeoError ) do
|
|
147
|
+
Locale.get_locale_by_name( 'marxer.org' )
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# $Id: tc_browse_node_lookup.rb,v 1.2 2009/06/02 00:39:43 ianmacd Exp $
|
|
2
|
+
#
|
|
3
|
+
|
|
4
|
+
require 'test/unit'
|
|
5
|
+
require './setup'
|
|
6
|
+
|
|
7
|
+
class TestBrowseNodeLookup < AWSTest
|
|
8
|
+
|
|
9
|
+
def test_browse_node_lookup
|
|
10
|
+
|
|
11
|
+
bnl = BrowseNodeLookup.new( 694212 )
|
|
12
|
+
rg = ResponseGroup.new( :BrowseNodeInfo )
|
|
13
|
+
|
|
14
|
+
response = @req.search( bnl, rg )
|
|
15
|
+
|
|
16
|
+
results = response.kernel
|
|
17
|
+
|
|
18
|
+
# Ensure we got some actual results back.
|
|
19
|
+
#
|
|
20
|
+
assert( results.size > 0 )
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_browse_node_lookup_no_response_group
|
|
25
|
+
|
|
26
|
+
bnl = BrowseNodeLookup.new( 694212 )
|
|
27
|
+
bnl.response_group = ResponseGroup.new( :BrowseNodeInfo )
|
|
28
|
+
response = @req.search( bnl, nil )
|
|
29
|
+
|
|
30
|
+
results = response.kernel
|
|
31
|
+
|
|
32
|
+
# Ensure we got more than 10 results back.
|
|
33
|
+
#
|
|
34
|
+
assert( results.size > 0 )
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_browse_node_lookup_class_method
|
|
39
|
+
|
|
40
|
+
response = Amazon::AWS.browse_node_lookup( 694212 )
|
|
41
|
+
|
|
42
|
+
results = response.kernel
|
|
43
|
+
|
|
44
|
+
# Ensure we got some actual results back.
|
|
45
|
+
#
|
|
46
|
+
assert( results.size > 0 )
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_browse_node_lookup_class_method_block
|
|
51
|
+
|
|
52
|
+
Amazon::AWS.browse_node_lookup( '694212' ) do |r|
|
|
53
|
+
|
|
54
|
+
results = r.kernel
|
|
55
|
+
|
|
56
|
+
# Ensure we got some actual results back.
|
|
57
|
+
#
|
|
58
|
+
assert( results.size > 0 )
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# $Id: tc_customer_content_lookup.rb,v 1.1 2009/06/02 00:29:18 ianmacd Exp $
|
|
2
|
+
#
|
|
3
|
+
|
|
4
|
+
require 'test/unit'
|
|
5
|
+
require './setup'
|
|
6
|
+
|
|
7
|
+
class TestCustomerContentLookup < AWSTest
|
|
8
|
+
|
|
9
|
+
def test_customer_content_lookup
|
|
10
|
+
|
|
11
|
+
@req.locale = 'us'
|
|
12
|
+
ccl = CustomerContentLookup.new( 'AJDWXANG1SYZP' )
|
|
13
|
+
rg = ResponseGroup.new( :CustomerReviews )
|
|
14
|
+
|
|
15
|
+
response = @req.search( ccl, rg )
|
|
16
|
+
|
|
17
|
+
review = response.customer_content_lookup_response.customers.customer.
|
|
18
|
+
customer_reviews.review[0]
|
|
19
|
+
|
|
20
|
+
# Ensure we got the right review.
|
|
21
|
+
#
|
|
22
|
+
assert_equal( 3746, review.content[0].size )
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_customer_content_lookup_no_response_group
|
|
27
|
+
|
|
28
|
+
@req.locale = 'us'
|
|
29
|
+
ccl = CustomerContentLookup.new( 'AJDWXANG1SYZP' )
|
|
30
|
+
ccl.response_group = ResponseGroup.new( :CustomerReviews )
|
|
31
|
+
response = @req.search( ccl, nil )
|
|
32
|
+
|
|
33
|
+
review = response.customer_content_lookup_response.customers.customer.
|
|
34
|
+
customer_reviews.review[0]
|
|
35
|
+
|
|
36
|
+
# Ensure we got the right review.
|
|
37
|
+
#
|
|
38
|
+
assert_equal( 3746, review.content[0].size )
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_customer_content_lookup_class_method
|
|
43
|
+
|
|
44
|
+
response = Amazon::AWS.customer_content_lookup( 'AA5QZU6TJQXEN' )
|
|
45
|
+
|
|
46
|
+
nickname = response.customer_content_lookup_response.customers.customer.
|
|
47
|
+
nickname
|
|
48
|
+
|
|
49
|
+
assert_equal( 'jimwood43', nickname )
|
|
50
|
+
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_item_search_class_method_block
|
|
54
|
+
|
|
55
|
+
Amazon::AWS.customer_content_lookup( 'AA5QZU6TJQXEN' ) do |r|
|
|
56
|
+
|
|
57
|
+
nickname = r.customer_content_lookup_response.customers.customer.nickname
|
|
58
|
+
|
|
59
|
+
assert_equal( 'jimwood43', nickname )
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
data/test/tc_help.rb
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# $Id: tc_help.rb,v 1.2 2009/06/02 00:39:23 ianmacd Exp $
|
|
2
|
+
#
|
|
3
|
+
|
|
4
|
+
require 'test/unit'
|
|
5
|
+
require './setup'
|
|
6
|
+
|
|
7
|
+
class TestHelp < AWSTest
|
|
8
|
+
|
|
9
|
+
def test_help
|
|
10
|
+
|
|
11
|
+
h = Help.new( 'ResponseGroup', 'Large' )
|
|
12
|
+
rg = ResponseGroup.new( 'Help' )
|
|
13
|
+
response = @req.search( h, rg )
|
|
14
|
+
|
|
15
|
+
# Get a list of valid operations for the Large response group.
|
|
16
|
+
#
|
|
17
|
+
results = response.help_response[0].information.response_group_information.
|
|
18
|
+
valid_operations.operation
|
|
19
|
+
|
|
20
|
+
# Ensure we got some actual results back.
|
|
21
|
+
#
|
|
22
|
+
assert( results.size > 0 )
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_help_no_response_group
|
|
27
|
+
|
|
28
|
+
h = Help.new( 'ResponseGroup', 'Large' )
|
|
29
|
+
h.response_group = ResponseGroup.new( 'Help' )
|
|
30
|
+
response = @req.search( h, nil )
|
|
31
|
+
|
|
32
|
+
# Get a list of valid operations for the Large response group.
|
|
33
|
+
#
|
|
34
|
+
results = response.help_response[0].information.response_group_information.
|
|
35
|
+
valid_operations.operation
|
|
36
|
+
|
|
37
|
+
# Ensure we got some actual results back.
|
|
38
|
+
#
|
|
39
|
+
assert( results.size > 0 )
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_help_class_method
|
|
44
|
+
|
|
45
|
+
response = Amazon::AWS.help( 'ResponseGroup', 'Large' )
|
|
46
|
+
|
|
47
|
+
# With no response group, Large will be tried. The resulting exception
|
|
48
|
+
# will be rescued and the text of the message returned by AWS will be used
|
|
49
|
+
# to determine a response group that will work.
|
|
50
|
+
#
|
|
51
|
+
results = response.help_response[0].information.response_group_information.
|
|
52
|
+
valid_operations.operation
|
|
53
|
+
|
|
54
|
+
# Ensure we got some actual results back.
|
|
55
|
+
#
|
|
56
|
+
assert( results.size > 0 )
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# $Id: tc_item_lookup.rb,v 1.2 2009/05/30 11:11:27 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
|
+
response = @req.search( is, @rg )
|
|
13
|
+
|
|
14
|
+
results = response.kernel
|
|
15
|
+
|
|
16
|
+
# Ensure we got some actual results back.
|
|
17
|
+
#
|
|
18
|
+
assert( results.size > 0 )
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_item_lookup_no_response_group
|
|
23
|
+
|
|
24
|
+
is = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000AE4QEC' } )
|
|
25
|
+
is.response_group = ResponseGroup.new( :Small )
|
|
26
|
+
response = @req.search( is, nil )
|
|
27
|
+
|
|
28
|
+
results = response.kernel
|
|
29
|
+
|
|
30
|
+
# Ensure we got more than 10 results back.
|
|
31
|
+
#
|
|
32
|
+
assert( results.size > 0 )
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_item_lookup_class_method
|
|
37
|
+
|
|
38
|
+
response = Amazon::AWS.item_lookup( 'ASIN', { 'ItemId' => 'B000AE4QEC' } )
|
|
39
|
+
|
|
40
|
+
results = response.kernel
|
|
41
|
+
|
|
42
|
+
# Ensure we got some actual results back.
|
|
43
|
+
#
|
|
44
|
+
assert( results.size > 0 )
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_item_search_class_method_block
|
|
49
|
+
|
|
50
|
+
Amazon::AWS.item_lookup( 'ASIN', { 'ItemId' => 'B000AE4QEC' } ) do |r|
|
|
51
|
+
|
|
52
|
+
results = r.kernel
|
|
53
|
+
|
|
54
|
+
# Ensure we got some actual results back.
|
|
55
|
+
#
|
|
56
|
+
assert( results.size > 0 )
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# encoding: ASCII-8BIT
|
|
2
|
+
#
|
|
3
|
+
# $Id: tc_item_search.rb,v 1.6 2009/06/15 10:18:07 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, @rg )
|
|
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, @rg )
|
|
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_multiple_pages
|
|
52
|
+
|
|
53
|
+
@req.encoding = 'utf-8'
|
|
54
|
+
is = ItemSearch.new( 'Books', { 'Title' => 'programming' } )
|
|
55
|
+
responses = @req.search( is, @rg, 5 )
|
|
56
|
+
|
|
57
|
+
results = []
|
|
58
|
+
responses.each { |response| results += response.kernel }
|
|
59
|
+
|
|
60
|
+
# Ensure we got more than 10 results back.
|
|
61
|
+
#
|
|
62
|
+
assert( results.size > 10 )
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def test_item_search_no_response_group
|
|
67
|
+
|
|
68
|
+
@req.encoding = 'utf-8'
|
|
69
|
+
is = ItemSearch.new( 'Books', { 'Title' => 'programming' } )
|
|
70
|
+
is.response_group = ResponseGroup.new( :Small )
|
|
71
|
+
responses = @req.search( is, nil, 5 )
|
|
72
|
+
|
|
73
|
+
results = []
|
|
74
|
+
responses.each { |response| results += response.kernel }
|
|
75
|
+
|
|
76
|
+
# Ensure we got more than 10 results back.
|
|
77
|
+
#
|
|
78
|
+
assert( results.size > 10 )
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_item_search_class_method
|
|
83
|
+
|
|
84
|
+
response = Amazon::AWS.item_search( 'Books', { 'Title' => 'programming' } )
|
|
85
|
+
|
|
86
|
+
results = response.kernel
|
|
87
|
+
|
|
88
|
+
# Ensure we got some actual results back.
|
|
89
|
+
#
|
|
90
|
+
assert( results.size > 0 )
|
|
91
|
+
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def test_item_search_class_method_block
|
|
95
|
+
|
|
96
|
+
Amazon::AWS.item_search( 'Books', { 'Title' => 'programming' } ) do |r|
|
|
97
|
+
|
|
98
|
+
results = r.kernel
|
|
99
|
+
|
|
100
|
+
# Ensure we got some actual results back.
|
|
101
|
+
#
|
|
102
|
+
assert( results.size > 0 )
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
end
|
|
@@ -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
|