ruby-aaws 0.4.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS +372 -283
- data/README +101 -60
- data/README.rdoc +13 -9
- data/example/batch_operation +27 -0
- data/example/item_lookup1 +5 -4
- data/example/item_lookup2 +5 -4
- data/example/multiple_operation1 +4 -3
- data/example/vehicle_search +22 -0
- data/lib/amazon.rb +22 -8
- data/lib/amazon/aws.rb +270 -107
- data/lib/amazon/aws/search.rb +26 -3
- data/test/tc_multiple_operation.rb +12 -4
- data/test/tc_vehicle_operations.rb +106 -0
- data/test/ts_aws.rb +2 -1
- metadata +6 -2
data/lib/amazon/aws/search.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: search.rb,v 1.
|
1
|
+
# $Id: search.rb,v 1.30 2009/02/19 16:19:47 ianmacd Exp $
|
2
2
|
#
|
3
3
|
|
4
4
|
module Amazon
|
@@ -35,7 +35,7 @@ module Amazon
|
|
35
35
|
# _key_id_ is your AWS {access key
|
36
36
|
# ID}[https://aws-portal.amazon.com/gp/aws/developer/registration/index.html],
|
37
37
|
# _associate_ is your
|
38
|
-
# Associates[http://docs.amazonwebservices.com/AWSECommerceService/
|
38
|
+
# Associates[http://docs.amazonwebservices.com/AWSECommerceService/2009-01-06/GSG/BecominganAssociate.html]
|
39
39
|
# tag (if any), _locale_ is the locale in which you which to work
|
40
40
|
# (*us* for amazon.com[http://www.amazon.com/], *uk* for
|
41
41
|
# amazon.co.uk[http://www.amazon.co.uk], etc.), _cache_ is whether or
|
@@ -82,6 +82,7 @@ module Amazon
|
|
82
82
|
else
|
83
83
|
nil
|
84
84
|
end
|
85
|
+
@api = @config['api'] || nil
|
85
86
|
self.locale = locale
|
86
87
|
end
|
87
88
|
|
@@ -101,6 +102,10 @@ module Amazon
|
|
101
102
|
@tag = Amazon::AWS::DEF_ASSOC[@locale]
|
102
103
|
end
|
103
104
|
|
105
|
+
if @config.key?( @locale ) && @config[@locale].key?( 'associate' )
|
106
|
+
@tag = @config[@locale]['associate']
|
107
|
+
end
|
108
|
+
|
104
109
|
# We must now set up a new HTTP connection to the correct server for
|
105
110
|
# this locale, unless the same server is used for both.
|
106
111
|
#
|
@@ -188,7 +193,7 @@ module Amazon
|
|
188
193
|
# The maximum page number that can be returned for each type of
|
189
194
|
# operation is documented in the AWS Developer's Guide:
|
190
195
|
#
|
191
|
-
# http://docs.amazonwebservices.com/AWSECommerceService/
|
196
|
+
# http://docs.amazonwebservices.com/AWSECommerceService/2009-01-06/DG/index.html?MaximumNumberofPages.html
|
192
197
|
#
|
193
198
|
# Note that _ItemLookup_ operations can use three separate pagination
|
194
199
|
# parameters. Ruby/AWS, however, uses _OfferPage_ for the purposes of
|
@@ -205,6 +210,11 @@ module Amazon
|
|
205
210
|
merge( operation.params ).
|
206
211
|
merge( response_group.params )
|
207
212
|
|
213
|
+
# Check to see whether a particular version of the API has been
|
214
|
+
# requested. If so, overwrite Version with the new value.
|
215
|
+
#
|
216
|
+
q_params.merge!( { 'Version' => @api } ) if @api
|
217
|
+
|
208
218
|
query = Amazon::AWS.assemble_query( q_params )
|
209
219
|
page = Amazon::AWS.get_page( self, query )
|
210
220
|
doc = Document.new( page )
|
@@ -215,6 +225,19 @@ module Amazon
|
|
215
225
|
#
|
216
226
|
error_check( doc )
|
217
227
|
|
228
|
+
# Another possible error results in a document containing nothing
|
229
|
+
# but <Result>Internal Error</Result>. This occurs when a specific
|
230
|
+
# version of the AWS API is requested, in combination with an
|
231
|
+
# operation that did not yet exist in that version of the API.
|
232
|
+
#
|
233
|
+
# For example:
|
234
|
+
#
|
235
|
+
# http://ecs.amazonaws.com/onca/xml?AWSAccessKeyId=foo&Operation=VehicleSearch&Year=2008&ResponseGroup=VehicleMakes&Service=AWSECommerceService&Version=2008-03-03
|
236
|
+
#
|
237
|
+
if xml = doc.elements['Result']
|
238
|
+
raise Amazon::AWS::Error::AWSError, xml.text
|
239
|
+
end
|
240
|
+
|
218
241
|
# Fundamental errors happen at the OperationRequest level. For
|
219
242
|
# example, if an invalid AWSAccessKeyId is used.
|
220
243
|
#
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: tc_multiple_operation.rb,v 1.
|
1
|
+
# $Id: tc_multiple_operation.rb,v 1.2 2009/02/19 16:50:00 ianmacd Exp $
|
2
2
|
#
|
3
3
|
|
4
4
|
require 'test/unit'
|
@@ -8,11 +8,19 @@ class TestMultipleOperation < AWSTest
|
|
8
8
|
|
9
9
|
def test_item_search
|
10
10
|
il = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000AE4QEC',
|
11
|
-
'MerchantId' => 'Amazon' },
|
12
|
-
{ 'ItemId' => 'B000051WBE',
|
13
11
|
'MerchantId' => 'Amazon' } )
|
12
|
+
il2 = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000051WBE',
|
13
|
+
'MerchantId' => 'Amazon' } )
|
14
|
+
|
15
|
+
# Create a batch request of the two ItemLookup operations.
|
16
|
+
#
|
17
|
+
il.batch( il2 )
|
18
|
+
|
14
19
|
is = ItemSearch.new( 'Books', { 'Title' => 'Ruby' } )
|
15
|
-
|
20
|
+
|
21
|
+
# Create a multiple operation of the ItemSearch operation and the two
|
22
|
+
# batched ItemLookup operations.
|
23
|
+
#
|
16
24
|
mo = MultipleOperation.new( is, il )
|
17
25
|
|
18
26
|
response = @req.search( mo, @rg )
|
@@ -0,0 +1,106 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
#
|
3
|
+
# $Id: tc_vehicle_operations.rb,v 1.1 2009/02/19 15:50:03 ianmacd Exp $
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require './setup'
|
7
|
+
|
8
|
+
class TestVehicles < AWSTest
|
9
|
+
|
10
|
+
def test_vehicle_search
|
11
|
+
@req.locale = 'us'
|
12
|
+
|
13
|
+
# Get all cars for year 2008.
|
14
|
+
#
|
15
|
+
vs = VehicleSearch.new( { 'Year' => 2008 } )
|
16
|
+
rg = ResponseGroup.new( 'VehicleMakes' )
|
17
|
+
response = @req.search( vs, rg )
|
18
|
+
|
19
|
+
makes = response.vehicle_search_response[0].vehicle_years[0].
|
20
|
+
vehicle_year[0].vehicle_makes[0].vehicle_make
|
21
|
+
assert( makes.size > 0 )
|
22
|
+
|
23
|
+
make_id = makes.find { |make| make.make_name == 'Audi' }.make_id.to_i
|
24
|
+
|
25
|
+
|
26
|
+
# Get all Audi models from 2008.
|
27
|
+
#
|
28
|
+
vs = VehicleSearch.new( { 'Year' => 2008,
|
29
|
+
'MakeId' => make_id } )
|
30
|
+
rg = ResponseGroup.new( 'VehicleModels' )
|
31
|
+
response = @req.search( vs, rg )
|
32
|
+
|
33
|
+
models = response.vehicle_search_response[0].vehicle_years[0].
|
34
|
+
vehicle_year[0].vehicle_makes[0].vehicle_make[0].
|
35
|
+
vehicle_models[0].vehicle_model
|
36
|
+
assert( models.size > 0 )
|
37
|
+
|
38
|
+
model_id = models.find { |model| model.model_name == 'R8' }.model_id.to_i
|
39
|
+
|
40
|
+
# Get all Audi R8 trim packages from 2008.
|
41
|
+
#
|
42
|
+
vs = VehicleSearch.new( { 'Year' => 2008,
|
43
|
+
'MakeId' => make_id,
|
44
|
+
'ModelId' => model_id } )
|
45
|
+
rg = ResponseGroup.new( 'VehicleTrims' )
|
46
|
+
response = @req.search( vs, rg )
|
47
|
+
|
48
|
+
trims = response.vehicle_search_response[0].vehicle_years[0].
|
49
|
+
vehicle_year[0].vehicle_makes[0].vehicle_make[0].
|
50
|
+
vehicle_models[0].vehicle_model[0].vehicle_trims[0].vehicle_trim
|
51
|
+
assert( trims.size > 0 )
|
52
|
+
|
53
|
+
trim_id = trims.find { |trim| trim.trim_name == 'Base' }.trim_id.to_i
|
54
|
+
|
55
|
+
vs = VehicleSearch.new( { 'Year' => 2008,
|
56
|
+
'MakeId' => make_id,
|
57
|
+
'ModelId' => model_id,
|
58
|
+
'TrimId' => trim_id } )
|
59
|
+
rg = ResponseGroup.new( 'VehicleOptions' )
|
60
|
+
response = @req.search( vs, rg )
|
61
|
+
|
62
|
+
options = response.vehicle_search_response[0].vehicle_years[0].
|
63
|
+
vehicle_year[0].vehicle_makes[0].vehicle_make[0].
|
64
|
+
vehicle_models[0].vehicle_model[0].vehicle_trims[0].
|
65
|
+
vehicle_trim[0].vehicle_options[0]
|
66
|
+
engine = options.vehicle_engine_options.vehicle_engine
|
67
|
+
engine_name = engine.engine_name
|
68
|
+
engine_id = engine.engine_id
|
69
|
+
assert_not_nil( engine_name )
|
70
|
+
|
71
|
+
# Find parts for our 2008 Audi R8 with Base trim and whatever engine that
|
72
|
+
# trim package has.
|
73
|
+
#
|
74
|
+
vps = VehiclePartSearch.new( 2008, make_id, model_id,
|
75
|
+
{ 'TrimId' => trim_id,
|
76
|
+
'EngineId' => engine_id } )
|
77
|
+
rg = ResponseGroup.new( 'VehicleParts' )
|
78
|
+
response = @req.search( vps, rg )
|
79
|
+
|
80
|
+
parts = response.vehicle_part_search_response[0].vehicle_parts[0].part
|
81
|
+
assert( parts.size > 0 )
|
82
|
+
|
83
|
+
# Now, we do a reverse look-up.
|
84
|
+
#
|
85
|
+
# Go through all parts and test to see if they fit in our 2008 Audi R8
|
86
|
+
# Base trim. The answer should always be yes.
|
87
|
+
#
|
88
|
+
# part = parts[rand( parts.size - 1 )].item.asin
|
89
|
+
|
90
|
+
parts.each do |part|
|
91
|
+
vpl = VehiclePartLookup.new( part.item.asin,
|
92
|
+
{ 'Year' => 2008,
|
93
|
+
'MakeId' => make_id,
|
94
|
+
'ModelId' => model_id,
|
95
|
+
'TrimId' => trim_id } )
|
96
|
+
|
97
|
+
rg = ResponseGroup.new( 'VehiclePartFit' )
|
98
|
+
response = @req.search( vpl, rg )
|
99
|
+
|
100
|
+
fit = response.vehicle_part_lookup_response[0].vehicle_parts[0].part.
|
101
|
+
vehicle_part_fit.is_fit
|
102
|
+
assert_equal( 'YES', fit )
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
data/test/ts_aws.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: ts_aws.rb,v 1.
|
1
|
+
# $Id: ts_aws.rb,v 1.5 2009/02/19 15:50:03 ianmacd Exp $
|
2
2
|
#
|
3
3
|
|
4
4
|
require 'test/unit'
|
@@ -8,5 +8,6 @@ require 'tc_serialisation'
|
|
8
8
|
require 'tc_operation_request'
|
9
9
|
require 'tc_item_search'
|
10
10
|
require 'tc_multiple_operation'
|
11
|
+
require 'tc_vehicle_operations'
|
11
12
|
|
12
13
|
require 'tc_shopping_cart'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-aaws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian Macdonald
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-02-20 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- example/item_search3
|
39
39
|
- example/list_lookup1
|
40
40
|
- example/list_search1
|
41
|
+
- example/vehicle_search
|
41
42
|
- example/seller_listing_lookup1
|
42
43
|
- example/seller_listing_search1
|
43
44
|
- example/seller_lookup1
|
@@ -45,6 +46,7 @@ files:
|
|
45
46
|
- example/similarity_lookup1
|
46
47
|
- example/tag_lookup1
|
47
48
|
- example/transaction_lookup1
|
49
|
+
- example/batch_operation
|
48
50
|
- lib/amazon.rb
|
49
51
|
- lib/amazon/aws/search.rb
|
50
52
|
- lib/amazon/aws/cache.rb
|
@@ -60,6 +62,7 @@ files:
|
|
60
62
|
- test/tc_shopping_cart.rb
|
61
63
|
- test/ts_aws.rb
|
62
64
|
- test/tc_serialisation.rb
|
65
|
+
- test/tc_vehicle_operations.rb
|
63
66
|
- COPYING
|
64
67
|
- NEWS
|
65
68
|
- README
|
@@ -100,3 +103,4 @@ test_files:
|
|
100
103
|
- test/tc_shopping_cart.rb
|
101
104
|
- test/ts_aws.rb
|
102
105
|
- test/tc_serialisation.rb
|
106
|
+
- test/tc_vehicle_operations.rb
|