ruby-aaws 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS +42 -1
- data/README.rdoc +12 -14
- data/lib/amazon.rb +48 -14
- data/lib/amazon/aws.rb +25 -6
- data/lib/amazon/aws/search.rb +22 -5
- data/test/tc_aws.rb +16 -2
- metadata +2 -2
data/NEWS
CHANGED
@@ -1,4 +1,41 @@
|
|
1
|
-
$Id: NEWS,v 1.
|
1
|
+
$Id: NEWS,v 1.12 2008/09/10 22:15:41 ianmacd Exp $
|
2
|
+
|
3
|
+
|
4
|
+
0.4.2
|
5
|
+
-----
|
6
|
+
|
7
|
+
The version of the Amazon AWS API requested when performing operations is now
|
8
|
+
2008-08-19. This is the latest at the time of writing.
|
9
|
+
|
10
|
+
The exception class Amazon::Config::ConfigError was mysteriously not defined.
|
11
|
+
|
12
|
+
Amazon::Config.new now accepts an optional argument, config_str, which may
|
13
|
+
contain the string equivalent of a config file's contents. When config_str is
|
14
|
+
not nil (nil is the default), this string is read instead of /etc/amazonrc and
|
15
|
+
~/.amazonrc. This addition is really just to aid unit-testing of the
|
16
|
+
Amazon::Config class, as Amazon::Config.new never needs to be called by user
|
17
|
+
code.
|
18
|
+
|
19
|
+
Config file lines may now contain leading whitespace.
|
20
|
+
|
21
|
+
The Amazon::AWS::MAX_PAGES constant has gone, replaced by the PAGINATION hash.
|
22
|
+
Only ItemSearch should use ItemPage to page through results up to MAX_PAGES
|
23
|
+
when ALL_PAGES has been requested, but the same approach was attempted for all
|
24
|
+
types of operation.
|
25
|
+
|
26
|
+
Each operation has its own pagination parameter and its own maximum number of
|
27
|
+
pages that can be fetched. This is now stored in the Amazon::AWS::PAGINATION
|
28
|
+
hash.
|
29
|
+
|
30
|
+
Note that ItemLookup has three possible pagination parameters: OfferPage,
|
31
|
+
VariationPage and ReviewPage. Ruby/AWS uses OfferPage for the purposes of
|
32
|
+
ALL_PAGES.
|
33
|
+
|
34
|
+
Operations that do not explicitly provide a pagination parameter (or, at
|
35
|
+
least, those for which there isn't one listed in the AWS Developer's Guide)
|
36
|
+
use ItemPage and pagination up to page 400. This is likely to throw an
|
37
|
+
exception, as such operations almost certainly don't support multiple results
|
38
|
+
pages.
|
2
39
|
|
3
40
|
|
4
41
|
0.4.1
|
@@ -17,6 +54,10 @@ file:
|
|
17
54
|
|
18
55
|
Choose one of these at your convenience.
|
19
56
|
|
57
|
+
The Ruby/AWS gem has been renamed ruby-aaws (from ruby-aws) to avoid a
|
58
|
+
namespace clash with another project. This clash prevented remote installation
|
59
|
+
of the gem.
|
60
|
+
|
20
61
|
|
21
62
|
0.4.0
|
22
63
|
-----
|
data/README.rdoc
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# $Id: README.rdoc,v 1.
|
2
|
+
# $Id: README.rdoc,v 1.17 2008/09/10 21:56:13 ianmacd Exp $
|
3
3
|
#++
|
4
4
|
#
|
5
5
|
#
|
@@ -80,11 +80,9 @@
|
|
80
80
|
# RubyGems[http://www.rubygems.org/] installation.
|
81
81
|
#
|
82
82
|
# Note, however, if choosing the gem installation, that whilst Ruby/AWS's
|
83
|
-
# RubyForge UNIX name is ruby-aws
|
84
|
-
# project}[http://rubyforge.org/projects/ruby-aws/]
|
85
|
-
#
|
86
|
-
# RubyForge's gem repository will always find the other ruby-aws project when
|
87
|
-
# queried for this name.
|
83
|
+
# RubyForge UNIX name is now ruby-aaws. The ruby-aws name was taken by
|
84
|
+
# {another project}[http://rubyforge.org/projects/ruby-aws/] and this clash
|
85
|
+
# prevented remote installation of the Ruby/AWS gem.
|
88
86
|
#
|
89
87
|
#
|
90
88
|
# == Prerequisites
|
@@ -115,22 +113,22 @@
|
|
115
113
|
# where you can discuss all Ruby/AWS-related subjects and issues.
|
116
114
|
#
|
117
115
|
# Please see the Amazon Web Services
|
118
|
-
# documentation[http://
|
116
|
+
# documentation[http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=5]
|
119
117
|
# for definitive information on the capabilities and inner workings of the AWS
|
120
118
|
# API.
|
121
119
|
#
|
122
120
|
#
|
123
121
|
# == Download
|
124
122
|
#
|
125
|
-
# Version 0.4.
|
126
|
-
# === {gzip'ed tar archive}[http://www.caliban.org/files/ruby/ruby-aws-0.4.
|
127
|
-
# === {Ruby Gem}[http://www.caliban.org/files/ruby/ruby-aaws-0.4.
|
128
|
-
# === {Fedora
|
129
|
-
# === {Fedora
|
130
|
-
# === {Fedora
|
123
|
+
# Version 0.4.2
|
124
|
+
# === {gzip'ed tar archive}[http://www.caliban.org/files/ruby/ruby-aws-0.4.2.tar.gz]
|
125
|
+
# === {Ruby Gem}[http://www.caliban.org/files/ruby/ruby-aaws-0.4.2.gem]
|
126
|
+
# === {Fedora 9 RPM}[http://www.caliban.org/files/redhat/RPMS/noarch/ruby-aws-0.4.2-1.fc9.noarch.rpm]
|
127
|
+
# === {Fedora 9 doc RPM}[http://www.caliban.org/files/redhat/RPMS/noarch/ruby-aws-doc-0.4.2-1.fc9.noarch.rpm]
|
128
|
+
# === {Fedora 9 source RPM}[http://www.caliban.org/files/redhat/SRPMS/ruby-aws-0.4.2-1.fc9.src.rpm]
|
131
129
|
#
|
132
130
|
#
|
133
131
|
# ---
|
134
132
|
# Author:: Ian Macdonald <mailto:ian@caliban.org>
|
135
|
-
# Version:: 0.4.
|
133
|
+
# Version:: 0.4.2
|
136
134
|
# Licence:: GPL[http://www.gnu.org/copyleft/gpl.html]
|
data/lib/amazon.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: amazon.rb,v 1.
|
1
|
+
# $Id: amazon.rb,v 1.20 2008/09/08 22:42:30 ianmacd Exp $
|
2
2
|
#
|
3
3
|
|
4
4
|
module Amazon
|
@@ -48,26 +48,59 @@ module Amazon
|
|
48
48
|
#
|
49
49
|
class Config < Hash
|
50
50
|
|
51
|
-
|
51
|
+
require 'stringio'
|
52
52
|
|
53
|
-
|
53
|
+
# Exception class for configuration file errors.
|
54
|
+
#
|
55
|
+
class ConfigError < StandardError; end
|
56
|
+
|
57
|
+
# A configuration may be passed in as a string. Otherwise, the files
|
58
|
+
# <tt>/etc/amazonrc</tt> and <tt>~/.amazonrc</tt> are read if they exist
|
59
|
+
# and are readable.
|
60
|
+
#
|
61
|
+
def initialize(config_str=nil)
|
62
|
+
|
63
|
+
if config_str
|
64
|
+
|
65
|
+
# We have been passed a config file as a string.
|
66
|
+
#
|
67
|
+
config_files = [ config_str ]
|
68
|
+
config_class = StringIO
|
69
|
+
|
70
|
+
else
|
71
|
+
|
72
|
+
# Perform the usual search for the system and user config files.
|
73
|
+
#
|
74
|
+
config_files = [ File.join( '', 'etc', 'amazonrc' ) ]
|
54
75
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
76
|
+
# Figure out where home is. The subsequent locations are for Windows.
|
77
|
+
# [ruby-core:12347]
|
78
|
+
#
|
79
|
+
home = ENV['HOME'] || ENV['HOMEDRIVE'] + ENV['HOMEPATH'] ||
|
80
|
+
ENV['USERPROFILE']
|
60
81
|
|
61
|
-
|
62
|
-
|
82
|
+
if home
|
83
|
+
config_files << File.expand_path( File.join( '~', '.amazonrc' ) )
|
84
|
+
end
|
85
|
+
|
86
|
+
config_class = File
|
63
87
|
end
|
64
88
|
|
65
89
|
config_files.each do |cf|
|
66
|
-
if File.exists?( cf ) && File.readable?( cf )
|
67
90
|
|
68
|
-
|
91
|
+
if config_class == StringIO
|
92
|
+
readable = true
|
93
|
+
else
|
94
|
+
# We must determine whether the file is readable.
|
95
|
+
#
|
96
|
+
readable = File.exists?( cf ) && File.readable?( cf )
|
97
|
+
end
|
98
|
+
|
99
|
+
if readable
|
100
|
+
|
101
|
+
Amazon.dprintf( 'Opening %s ...', cf ) if config_class == File
|
69
102
|
|
70
|
-
|
103
|
+
config_class.open( cf ) { |f| lines = f.readlines }.each do |line|
|
71
104
|
line.chomp!
|
72
105
|
|
73
106
|
# Skip comments and blank lines.
|
@@ -79,9 +112,10 @@ module Amazon
|
|
79
112
|
# Store these, because we'll probably find a use for these later.
|
80
113
|
#
|
81
114
|
begin
|
82
|
-
|
115
|
+
match = line.match( /^\s*(\S+)\s*=\s*(['"]?)([^'"]+)(['"]?)/ )
|
83
116
|
key, begin_quote, val, end_quote = match[1, 4]
|
84
117
|
raise ConfigError if begin_quote != end_quote
|
118
|
+
|
85
119
|
rescue NoMethodError, ConfigError
|
86
120
|
raise ConfigError, "bad config line: #{line}"
|
87
121
|
end
|
data/lib/amazon/aws.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: aws.rb,v 1.
|
1
|
+
# $Id: aws.rb,v 1.68 2008/09/10 21:56:14 ianmacd Exp $
|
2
2
|
#
|
3
3
|
#:include: ../../README.rdoc
|
4
4
|
|
@@ -12,7 +12,7 @@ module Amazon
|
|
12
12
|
require 'rexml/document'
|
13
13
|
|
14
14
|
NAME = '%s/%s' % [ Amazon::NAME, 'AWS' ]
|
15
|
-
VERSION = '0.4.
|
15
|
+
VERSION = '0.4.2'
|
16
16
|
USER_AGENT = '%s %s' % [ NAME, VERSION ]
|
17
17
|
|
18
18
|
# Default Associate tags to use per locale.
|
@@ -29,7 +29,7 @@ module Amazon
|
|
29
29
|
# Service name and version for AWS.
|
30
30
|
#
|
31
31
|
SERVICE = { 'Service' => 'AWSECommerceService',
|
32
|
-
'Version' => '2008-
|
32
|
+
'Version' => '2008-08-19'
|
33
33
|
}
|
34
34
|
|
35
35
|
# Maximum number of 301 and 302 HTTP responses to follow, should Amazon
|
@@ -38,10 +38,29 @@ module Amazon
|
|
38
38
|
MAX_REDIRECTS = 3
|
39
39
|
|
40
40
|
# Maximum number of results pages that can be retrieved for a given
|
41
|
-
# search
|
41
|
+
# search operation, using whichever pagination parameter is relevant to
|
42
|
+
# that type of operation.
|
42
43
|
#
|
43
|
-
|
44
|
-
|
44
|
+
PAGINATION = { 'ItemSearch' => { 'parameter' => 'ItemPage',
|
45
|
+
'max_page' => 400 },
|
46
|
+
'ItemLookup' => { 'paraneter' => 'OfferPage',
|
47
|
+
'max_page' => 100 },
|
48
|
+
'ListLookup' => { 'parameter' => 'ProductPage',
|
49
|
+
'max_page' => 30 },
|
50
|
+
'ListSearch' => { 'parameter' => 'ListPage',
|
51
|
+
'max_page' => 20 },
|
52
|
+
'CustomerContentLookup' => { 'parameter' => 'ReviewPage',
|
53
|
+
'max_page' => 10 },
|
54
|
+
'CustomerContentSearch' => { 'parameter' => 'CustomerPage',
|
55
|
+
'max_page' => 20 }
|
56
|
+
}
|
57
|
+
# N.B. ItemLookup can also use the following two pagination parameters
|
58
|
+
#
|
59
|
+
# max. page
|
60
|
+
# ---------
|
61
|
+
# VariationPage 150
|
62
|
+
# ReviewPage 20
|
63
|
+
|
45
64
|
# Exception class for HTTP errors.
|
46
65
|
#
|
47
66
|
class HTTPError < StandardError; end
|
data/lib/amazon/aws/search.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: search.rb,v 1.
|
1
|
+
# $Id: search.rb,v 1.23 2008/09/10 21:43:58 ianmacd Exp $
|
2
2
|
#
|
3
3
|
|
4
4
|
module Amazon
|
@@ -174,8 +174,8 @@ module Amazon
|
|
174
174
|
private :error_check
|
175
175
|
|
176
176
|
|
177
|
-
# Perform a search of the AWS
|
178
|
-
# objects
|
177
|
+
# Perform a search of the AWS database. _operation_ is one of the
|
178
|
+
# objects subclassed from _Operation_, such as _ItemSearch_,
|
179
179
|
# _ItemLookup_, etc. It may also be a _MultipleOperation_ object.
|
180
180
|
#
|
181
181
|
# _response_group_ will apply to all both operations contained in
|
@@ -186,6 +186,15 @@ module Amazon
|
|
186
186
|
# returned. If the special value <b>:ALL_PAGES</b> is given, all
|
187
187
|
# results pages will be returned.
|
188
188
|
#
|
189
|
+
# The maximum page number that can be returned for each type of
|
190
|
+
# operation is documented in the AWS Developer's Guide:
|
191
|
+
#
|
192
|
+
# http://docs.amazonwebservices.com/AWSECommerceService/2008-08-19/DG/index.html?CHAP_MakingRequestsandUnderstandingResponses.html#PagingThroughResults
|
193
|
+
#
|
194
|
+
# Note that _ItemLookup_ operations can use three separate pagination
|
195
|
+
# parameters. Ruby/AWS, however, uses _OfferPage_ for the purposes of
|
196
|
+
# returning multiple pages.
|
197
|
+
#
|
189
198
|
# If operation is of class _MultipleOperation_, the operations
|
190
199
|
# combined within will return only the first page, regardless of
|
191
200
|
# whether a higher number of pages is requested.
|
@@ -273,11 +282,19 @@ module Amazon
|
|
273
282
|
#
|
274
283
|
nr_pages = tp.to_i if nr_pages == :ALL_PAGES || nr_pages > tp.to_i
|
275
284
|
|
285
|
+
if PAGINATION.key? operation.kind
|
286
|
+
page_parameter = PAGINATION[operation.kind]['parameter']
|
287
|
+
max_pages = PAGINATION[operation.kind]['max_page']
|
288
|
+
else
|
289
|
+
page_parameter = 'ItemPage'
|
290
|
+
max_pages = 400
|
291
|
+
end
|
292
|
+
|
276
293
|
# Iterate over pages 2 and higher, but go no higher than MAX_PAGES.
|
277
294
|
#
|
278
|
-
2.upto( nr_pages <
|
295
|
+
2.upto( nr_pages < max_pages ? nr_pages : max_pages ) do |page_nr|
|
279
296
|
query = Amazon::AWS.assemble_query(
|
280
|
-
q_params.merge( {
|
297
|
+
q_params.merge( { page_parameter => page_nr } ) )
|
281
298
|
page = Amazon::AWS.get_page( self, query )
|
282
299
|
doc = Document.new( page )
|
283
300
|
|
data/test/tc_aws.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: tc_aws.rb,v 1.
|
1
|
+
# $Id: tc_aws.rb,v 1.9 2008/09/08 21:23:01 ianmacd Exp $
|
2
2
|
#
|
3
3
|
|
4
4
|
require 'test/unit'
|
@@ -92,8 +92,22 @@ class TestAWSBasics < AWSTest
|
|
92
92
|
|
93
93
|
end
|
94
94
|
|
95
|
+
def test_config
|
96
|
+
assert_raise( Amazon::Config::ConfigError ) do
|
97
|
+
cf = Amazon::Config.new( <<' EOF' )
|
98
|
+
bad_syntax = 'bad quotes"
|
99
|
+
EOF
|
100
|
+
end
|
101
|
+
|
102
|
+
assert_nothing_raised do
|
103
|
+
cf = Amazon::Config.new( <<' EOF' )
|
104
|
+
good_syntax = 'good quotes'
|
105
|
+
EOF
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
95
109
|
def test_exceptions
|
96
|
-
assert_raise( Amazon::AWS::HTTPError) { raise Amazon::AWS::HTTPError }
|
110
|
+
assert_raise( Amazon::AWS::HTTPError ) { raise Amazon::AWS::HTTPError }
|
97
111
|
end
|
98
112
|
|
99
113
|
include Amazon
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ruby-aaws
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.4.
|
7
|
-
date: 2008-
|
6
|
+
version: 0.4.2
|
7
|
+
date: 2008-09-11 00:00:00 +02:00
|
8
8
|
summary: Ruby interface to Amazon Associates Web Services
|
9
9
|
require_paths:
|
10
10
|
- lib
|