hollownest-ruby-aws 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +138 -0
- data/lib/amazon.rb +153 -0
- data/lib/amazon/aws.rb +1339 -0
- data/lib/amazon/aws/cache.rb +141 -0
- data/lib/amazon/aws/search.rb +356 -0
- data/lib/amazon/aws/shoppingcart.rb +504 -0
- data/lib/amazon/locale.rb +102 -0
- data/test/local/cache_files/books.xml +802 -0
- data/test/local/cache_files/electronics.xml +842 -0
- data/test/local/cache_files/movies.xml +1056 -0
- data/test/local/cache_files/music.xml +744 -0
- data/test/local/tc_local_search.rb +31 -0
- data/test/network/tc_amazon.rb +17 -0
- data/test/network/tc_aws.rb +136 -0
- data/test/network/tc_item_search.rb +25 -0
- data/test/network/tc_multiple_operation.rb +70 -0
- data/test/network/tc_operation_request.rb +62 -0
- data/test/network/tc_serialisation.rb +107 -0
- data/test/network/tc_shopping_cart.rb +217 -0
- data/test/network/tc_vehicle_operations.rb +109 -0
- data/test/test_helper.rb +16 -0
- metadata +79 -0
@@ -0,0 +1,217 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
3
|
+
require 'amazon/aws/shoppingcart'
|
4
|
+
|
5
|
+
include Amazon::AWS::ShoppingCart
|
6
|
+
|
7
|
+
class TestShoppingCart < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
# B00151HZA6 B000WC4AH0 B0006L16N8
|
11
|
+
@asins = ['0805006001', '1599867419', '0689875886']
|
12
|
+
@add_asins = ['8850700148', '0816648999', '1604596813', '0785822577', '044023865X']
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_shopping_cart1
|
16
|
+
cart = Cart.new(@@key_id, @@associates_id)
|
17
|
+
cart.locale = 'us'
|
18
|
+
|
19
|
+
# Check that initial quantities are zero.
|
20
|
+
#
|
21
|
+
items = cart.items
|
22
|
+
sfl_items = cart.saved_for_later_items
|
23
|
+
assert_equal( 0, items.size )
|
24
|
+
assert_equal( 0, sfl_items.size )
|
25
|
+
|
26
|
+
# Create a cart with three items. The last two are given as multiple
|
27
|
+
# single-element hashes. MergeCart is false.
|
28
|
+
#
|
29
|
+
cart.cart_create( :ASIN, @asins[0], 3, false,
|
30
|
+
{ @asins[1] => 2 },
|
31
|
+
{ @asins[2] => 1 } )
|
32
|
+
items = cart.items
|
33
|
+
|
34
|
+
# Check that the quantities match what we expect.
|
35
|
+
#
|
36
|
+
assert_equal( 3, items.size )
|
37
|
+
item = items.find { |item| item.asin == @asins[0] }
|
38
|
+
assert_equal( '3', item.quantity[0] )
|
39
|
+
item = items.find { |item| item.asin == @asins[1] }
|
40
|
+
assert_equal( '2', item.quantity[0] )
|
41
|
+
item = items.find { |item| item.asin == @asins[2] }
|
42
|
+
assert_equal( '1', item.quantity[0] )
|
43
|
+
|
44
|
+
# Check purchase URL.
|
45
|
+
#
|
46
|
+
|
47
|
+
# Check for correct Cart Id.
|
48
|
+
#
|
49
|
+
assert_match( /cart-id=#{cart.cart_id}/,
|
50
|
+
cart.purchase_url,
|
51
|
+
'Cart Id incorrect' )
|
52
|
+
|
53
|
+
# Check for correct value of MergeCart.
|
54
|
+
#
|
55
|
+
assert_match( /MergeCart=False/,
|
56
|
+
cart.purchase_url,
|
57
|
+
'MergeCart is not False' )
|
58
|
+
|
59
|
+
# Clear cart.
|
60
|
+
#
|
61
|
+
cart.cart_clear
|
62
|
+
|
63
|
+
# Ensure that clearing the cart actually empties it.
|
64
|
+
#
|
65
|
+
assert_equal( 0, cart.cart_items.size )
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_shopping_cart2
|
69
|
+
cart = Cart.new(@@key_id, @@associates_id)
|
70
|
+
cart.locale = 'us'
|
71
|
+
|
72
|
+
# Create a cart with three items. The last two are given in a single
|
73
|
+
# hash. MergeCart is true. Cart#create is used as an alias of
|
74
|
+
# Cart#cart_create.
|
75
|
+
#
|
76
|
+
cart.create( :ASIN, @asins[0], 1, true,
|
77
|
+
{ @asins[1] => 2,
|
78
|
+
@asins[2] => 3 } )
|
79
|
+
items = cart.items
|
80
|
+
|
81
|
+
# Check that the quantities match what we expect.
|
82
|
+
#
|
83
|
+
assert_equal( 3, items.size )
|
84
|
+
item = items.find { |item| item.asin == @asins[0] }
|
85
|
+
assert_equal( '1', item.quantity[0] )
|
86
|
+
item = items.find { |item| item.asin == @asins[1] }
|
87
|
+
assert_equal( '2', item.quantity[0] )
|
88
|
+
item = items.find { |item| item.asin == @asins[2] }
|
89
|
+
assert_equal( '3', item.quantity[0] )
|
90
|
+
|
91
|
+
# Check purchase URL.
|
92
|
+
#
|
93
|
+
|
94
|
+
# Check for correct Cart Id.
|
95
|
+
#
|
96
|
+
assert_match( /cart-id=#{cart.cart_id}/,
|
97
|
+
cart.purchase_url,
|
98
|
+
'Cart Id incorrect' )
|
99
|
+
|
100
|
+
# Check for correct value of MergeCart.
|
101
|
+
#
|
102
|
+
assert_match( /MergeCart=True/,
|
103
|
+
cart.purchase_url,
|
104
|
+
'MergeCart is not True' )
|
105
|
+
|
106
|
+
# Add some items.
|
107
|
+
#
|
108
|
+
cart.cart_add( :ASIN, @add_asins[0], 1,
|
109
|
+
{ @add_asins[1] => 1,
|
110
|
+
@add_asins[2] => 4 },
|
111
|
+
{ @add_asins[3] => 3,
|
112
|
+
@add_asins[4] => 2 } )
|
113
|
+
|
114
|
+
# Check that the quantities match what we expect.
|
115
|
+
#
|
116
|
+
items = cart.items
|
117
|
+
assert_equal( 8, items.size )
|
118
|
+
item = items.find { |item| item.asin == @add_asins[0] }
|
119
|
+
assert_equal( '1', item.quantity[0] )
|
120
|
+
item = items.find { |item| item.asin == @add_asins[1] }
|
121
|
+
assert_equal( '1', item.quantity[0] )
|
122
|
+
item = items.find { |item| item.asin == @add_asins[2] }
|
123
|
+
assert_equal( '4', item.quantity[0] )
|
124
|
+
item = items.find { |item| item.asin == @add_asins[3] }
|
125
|
+
assert_equal( '3', item.quantity[0] )
|
126
|
+
item = items.find { |item| item.asin == @add_asins[4] }
|
127
|
+
assert_equal( '2', item.quantity[0] )
|
128
|
+
|
129
|
+
# Modify an item quantity.
|
130
|
+
#
|
131
|
+
cart.cart_modify( :ASIN, @asins[0], 2 )
|
132
|
+
items = cart.items
|
133
|
+
assert_equal( 8, items.size )
|
134
|
+
item = items.find { |item| item.asin == @asins[0] }
|
135
|
+
assert_equal( '2', item.quantity[0] )
|
136
|
+
|
137
|
+
# Move item to 'Save For Later' area.
|
138
|
+
#
|
139
|
+
cart.cart_modify( :ASIN, @add_asins[0], 1, true )
|
140
|
+
sfl_items = cart.saved_for_later_items
|
141
|
+
assert_equal( 1, sfl_items.size )
|
142
|
+
item = sfl_items.find { |item| item.asin == @add_asins[0] }
|
143
|
+
assert_equal( '1', item.quantity[0] )
|
144
|
+
items = cart.items
|
145
|
+
assert_equal( 7, items.size )
|
146
|
+
assert( ! cart.active?( :ASIN, @add_asins[0] ) )
|
147
|
+
|
148
|
+
# Move item back to 'Active' area.
|
149
|
+
#
|
150
|
+
cart.cart_modify( :ASIN, @add_asins[0], 1, false )
|
151
|
+
items = cart.items
|
152
|
+
assert_equal( 8, items.size )
|
153
|
+
item = items.find { |item| item.asin == @add_asins[0] }
|
154
|
+
assert_equal( '1', item.quantity[0] )
|
155
|
+
sfl_items = cart.saved_for_later_items
|
156
|
+
assert_equal( 0, sfl_items.size )
|
157
|
+
assert( ! cart.saved_for_later?( :ASIN, @add_asins[0] ) )
|
158
|
+
|
159
|
+
# Remove an item.
|
160
|
+
#
|
161
|
+
cart.cart_modify( :ASIN, @add_asins[0], 0 )
|
162
|
+
|
163
|
+
# Check that the number of items in the cart has been reduced by one.
|
164
|
+
#
|
165
|
+
items = cart.items
|
166
|
+
assert_equal( 7, items.size )
|
167
|
+
|
168
|
+
# Check that the item is no longer in the cart.
|
169
|
+
#
|
170
|
+
assert( ! cart.include?( :ASIN, @add_asins[0] ) )
|
171
|
+
|
172
|
+
# Check that modifying non-existent item raises exception.
|
173
|
+
#
|
174
|
+
assert_raise( Amazon::AWS::ShoppingCart::CartError ) do
|
175
|
+
cart.cart_modify( :ASIN, @add_asins[0], 1 )
|
176
|
+
end
|
177
|
+
|
178
|
+
# Move another item to the 'Save For Later' area.
|
179
|
+
#
|
180
|
+
cart.cart_modify( :ASIN, @asins[0], 2, true )
|
181
|
+
items = cart.items
|
182
|
+
assert_equal( 6, items.size )
|
183
|
+
sfl_items = cart.saved_for_later_items
|
184
|
+
assert_equal( 1, sfl_items.size )
|
185
|
+
|
186
|
+
# Now remove that item while it's still in the 'Save For Later' area.
|
187
|
+
#
|
188
|
+
cart.cart_modify( :ASIN, @asins[0], 0 )
|
189
|
+
items = cart.items
|
190
|
+
assert_equal( 6, items.size )
|
191
|
+
sfl_items = cart.saved_for_later_items
|
192
|
+
assert_equal( 0, sfl_items.size )
|
193
|
+
|
194
|
+
# Ensure that the item is no longer in either area of the cart.
|
195
|
+
#
|
196
|
+
assert( ! cart.include?( :ASIN, @add_asins[0] ) )
|
197
|
+
assert( ! cart.active?( :ASIN, @add_asins[0] ) )
|
198
|
+
assert( ! cart.saved_for_later?( :ASIN, @add_asins[0] ) )
|
199
|
+
|
200
|
+
# Check that modifying non-existent item raises exception.
|
201
|
+
#
|
202
|
+
assert_raise( Amazon::AWS::ShoppingCart::CartError ) do
|
203
|
+
cart.cart_modify( :ASIN, @asins[0], 1 )
|
204
|
+
end
|
205
|
+
|
206
|
+
# Check that retrieving the cart at a later time works properly.
|
207
|
+
#
|
208
|
+
old_cart = cart
|
209
|
+
cart = Cart.new(@@key_id, @@associates_id)
|
210
|
+
cart.locale = 'us'
|
211
|
+
cart.cart_get( old_cart.cart_id, old_cart.hmac )
|
212
|
+
assert_equal( old_cart.cart_id, cart.cart_id )
|
213
|
+
assert_equal( old_cart.hmac, cart.hmac )
|
214
|
+
assert_equal( old_cart.items, cart.items )
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
3
|
+
|
4
|
+
class TestVehicles < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@rg = ResponseGroup.new( :Small )
|
8
|
+
@req = Request.new(@@key_id, @@associates_id)
|
9
|
+
@req.locale = 'uk'
|
10
|
+
@req.cache = false
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_vehicle_search
|
14
|
+
@req.locale = 'us'
|
15
|
+
|
16
|
+
# Get all cars for year 2008.
|
17
|
+
#
|
18
|
+
vs = VehicleSearch.new( { 'Year' => 2008 } )
|
19
|
+
rg = ResponseGroup.new( 'VehicleMakes' )
|
20
|
+
response = @req.search( vs, rg )
|
21
|
+
|
22
|
+
makes = response.vehicle_search_response[0].vehicle_years[0].
|
23
|
+
vehicle_year[0].vehicle_makes[0].vehicle_make
|
24
|
+
assert( makes.size > 0 )
|
25
|
+
|
26
|
+
make_id = makes.find { |make| make.make_name == 'Audi' }.make_id.to_i
|
27
|
+
|
28
|
+
|
29
|
+
# Get all Audi models from 2008.
|
30
|
+
#
|
31
|
+
vs = VehicleSearch.new( { 'Year' => 2008,
|
32
|
+
'MakeId' => make_id } )
|
33
|
+
rg = ResponseGroup.new( 'VehicleModels' )
|
34
|
+
response = @req.search( vs, rg )
|
35
|
+
|
36
|
+
models = response.vehicle_search_response[0].vehicle_years[0].
|
37
|
+
vehicle_year[0].vehicle_makes[0].vehicle_make[0].
|
38
|
+
vehicle_models[0].vehicle_model
|
39
|
+
assert( models.size > 0 )
|
40
|
+
|
41
|
+
model_id = models.find { |model| model.model_name == 'R8' }.model_id.to_i
|
42
|
+
|
43
|
+
# Get all Audi R8 trim packages from 2008.
|
44
|
+
#
|
45
|
+
vs = VehicleSearch.new( { 'Year' => 2008,
|
46
|
+
'MakeId' => make_id,
|
47
|
+
'ModelId' => model_id } )
|
48
|
+
rg = ResponseGroup.new( 'VehicleTrims' )
|
49
|
+
response = @req.search( vs, rg )
|
50
|
+
|
51
|
+
trims = response.vehicle_search_response[0].vehicle_years[0].
|
52
|
+
vehicle_year[0].vehicle_makes[0].vehicle_make[0].
|
53
|
+
vehicle_models[0].vehicle_model[0].vehicle_trims[0].vehicle_trim
|
54
|
+
assert( trims.size > 0 )
|
55
|
+
|
56
|
+
trim_id = trims.find { |trim| trim.trim_name == 'Base' }.trim_id.to_i
|
57
|
+
|
58
|
+
vs = VehicleSearch.new( { 'Year' => 2008,
|
59
|
+
'MakeId' => make_id,
|
60
|
+
'ModelId' => model_id,
|
61
|
+
'TrimId' => trim_id } )
|
62
|
+
rg = ResponseGroup.new( 'VehicleOptions' )
|
63
|
+
response = @req.search( vs, rg )
|
64
|
+
|
65
|
+
options = response.vehicle_search_response[0].vehicle_years[0].
|
66
|
+
vehicle_year[0].vehicle_makes[0].vehicle_make[0].
|
67
|
+
vehicle_models[0].vehicle_model[0].vehicle_trims[0].
|
68
|
+
vehicle_trim[0].vehicle_options[0]
|
69
|
+
engine = options.vehicle_engine_options.vehicle_engine
|
70
|
+
engine_name = engine.engine_name
|
71
|
+
engine_id = engine.engine_id
|
72
|
+
assert_not_nil( engine_name )
|
73
|
+
|
74
|
+
# Find parts for our 2008 Audi R8 with Base trim and whatever engine that
|
75
|
+
# trim package has.
|
76
|
+
#
|
77
|
+
vps = VehiclePartSearch.new( 2008, make_id, model_id,
|
78
|
+
{ 'TrimId' => trim_id,
|
79
|
+
'EngineId' => engine_id } )
|
80
|
+
rg = ResponseGroup.new( 'VehicleParts' )
|
81
|
+
response = @req.search( vps, rg )
|
82
|
+
|
83
|
+
parts = response.vehicle_part_search_response[0].vehicle_parts[0].part
|
84
|
+
assert( parts.size > 0 )
|
85
|
+
|
86
|
+
# Now, we do a reverse look-up.
|
87
|
+
#
|
88
|
+
# Go through all parts and test to see if they fit in our 2008 Audi R8
|
89
|
+
# Base trim. The answer should always be yes.
|
90
|
+
#
|
91
|
+
# part = parts[rand( parts.size - 1 )].item.asin
|
92
|
+
|
93
|
+
parts.each do |part|
|
94
|
+
vpl = VehiclePartLookup.new( part.item.asin,
|
95
|
+
{ 'Year' => 2008,
|
96
|
+
'MakeId' => make_id,
|
97
|
+
'ModelId' => model_id,
|
98
|
+
'TrimId' => trim_id } )
|
99
|
+
|
100
|
+
rg = ResponseGroup.new( 'VehiclePartFit' )
|
101
|
+
response = @req.search( vpl, rg )
|
102
|
+
|
103
|
+
fit = response.vehicle_part_lookup_response[0].vehicle_parts[0].part.
|
104
|
+
vehicle_part_fit.is_fit
|
105
|
+
assert_equal( 'YES', fit )
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
lib_dir = File.dirname(__FILE__) + '/../lib'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'test/unit'
|
4
|
+
$:.unshift lib_dir unless $:.include?(lib_dir)
|
5
|
+
require 'amazon'
|
6
|
+
require 'amazon/aws'
|
7
|
+
require 'amazon/aws/search'
|
8
|
+
|
9
|
+
include Amazon::AWS
|
10
|
+
include Amazon::AWS::Search
|
11
|
+
|
12
|
+
|
13
|
+
class Test::Unit::TestCase
|
14
|
+
@@associates_id = "reagif-20"
|
15
|
+
@@key_id = "15QN36861J5Q5KH0KZR2"
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hollownest-ruby-aws
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hollownest
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-28 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: TODO
|
17
|
+
email: pac@hollownest.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README.rdoc
|
26
|
+
- lib/amazon
|
27
|
+
- lib/amazon/aws
|
28
|
+
- lib/amazon/aws/cache.rb
|
29
|
+
- lib/amazon/aws/search.rb
|
30
|
+
- lib/amazon/aws/shoppingcart.rb
|
31
|
+
- lib/amazon/aws.rb
|
32
|
+
- lib/amazon/locale.rb
|
33
|
+
- lib/amazon.rb
|
34
|
+
- test/local
|
35
|
+
- test/local/cache_files
|
36
|
+
- test/local/cache_files/books.xml
|
37
|
+
- test/local/cache_files/electronics.xml
|
38
|
+
- test/local/cache_files/movies.xml
|
39
|
+
- test/local/cache_files/music.xml
|
40
|
+
- test/local/tc_local_search.rb
|
41
|
+
- test/network
|
42
|
+
- test/network/tc_amazon.rb
|
43
|
+
- test/network/tc_aws.rb
|
44
|
+
- test/network/tc_item_search.rb
|
45
|
+
- test/network/tc_multiple_operation.rb
|
46
|
+
- test/network/tc_operation_request.rb
|
47
|
+
- test/network/tc_serialisation.rb
|
48
|
+
- test/network/tc_shopping_cart.rb
|
49
|
+
- test/network/tc_vehicle_operations.rb
|
50
|
+
- test/test_helper.rb
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: http://github.com/hollownest/ruby-aws
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options:
|
55
|
+
- --inline-source
|
56
|
+
- --charset=UTF-8
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.2.0
|
75
|
+
signing_key:
|
76
|
+
specification_version: 2
|
77
|
+
summary: TODO
|
78
|
+
test_files: []
|
79
|
+
|