ruby-aaws 0.4.1 → 0.4.2

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/NEWS CHANGED
@@ -1,4 +1,41 @@
1
- $Id: NEWS,v 1.9 2008/08/18 08:37:54 ianmacd Exp $
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
  -----
@@ -1,5 +1,5 @@
1
1
  #--
2
- # $Id: README.rdoc,v 1.14 2008/07/05 16:10:04 ianmacd Exp $
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, that name is already claimed by an {earlier
84
- # project}[http://rubyforge.org/projects/ruby-aws/]. For that reason, it's
85
- # necessary to download the gem to a local file before installing, because
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://www.amazon.com/E-Commerce-Service-AWS-home-page/b/ref=sc_fe_c_0_15763381_1?node=12738641]
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.1
126
- # === {gzip'ed tar archive}[http://www.caliban.org/files/ruby/ruby-aws-0.4.1.tar.gz]
127
- # === {Ruby Gem}[http://www.caliban.org/files/ruby/ruby-aaws-0.4.1.gem]
128
- # === {Fedora 7 RPM}[http://www.caliban.org/files/redhat/RPMS/noarch/ruby-aaws-0.4.1-1.fc7.noarch.rpm]
129
- # === {Fedora 7 doc RPM}[http://www.caliban.org/files/redhat/RPMS/noarch/ruby-aws-doc-0.4.1-1.fc7.noarch.rpm]
130
- # === {Fedora 7 source RPM}[http://www.caliban.org/files/redhat/SRPMS/ruby-aws-0.4.1-1.fc7.src.rpm]
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.1
133
+ # Version:: 0.4.2
136
134
  # Licence:: GPL[http://www.gnu.org/copyleft/gpl.html]
@@ -1,4 +1,4 @@
1
- # $Id: amazon.rb,v 1.18 2008/08/17 12:00:39 ianmacd Exp $
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
- def initialize
51
+ require 'stringio'
52
52
 
53
- config_files = [ File.join( '', 'etc', 'amazonrc' ) ]
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
- # Figure out where home is. The subsequent locations are for Windows.
56
- # [ruby-core:12347]
57
- #
58
- home = ENV['HOME'] || ENV['HOMEDRIVE'] + ENV['HOMEPATH'] ||
59
- ENV['USERPROFILE']
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
- if home
62
- config_files << File.expand_path( File.join( '~', '.amazonrc' ) )
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
- Amazon.dprintf( 'Opening %s ...', cf )
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
- File.open( cf ) { |f| lines = f.readlines }.each do |line|
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
- match = line.match( /^(\S+)\s*=\s*(['"]?)([^'"]+)(['"]?)/ )
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
@@ -1,4 +1,4 @@
1
- # $Id: aws.rb,v 1.65 2008/08/18 08:38:36 ianmacd Exp $
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.1'
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-06-26'
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
- MAX_PAGES = 400
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
@@ -1,4 +1,4 @@
1
- # $Id: search.rb,v 1.21 2008/05/31 19:42:04 ianmacd Exp $
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 catalogue. _operation_ is one of the
178
- # objects subclased from _Operation_, such as _ItemSearch_,
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 < MAX_PAGES ? nr_pages : MAX_PAGES ) do |page_nr|
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( { 'ItemPage' => page_nr } ) )
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
 
@@ -1,4 +1,4 @@
1
- # $Id: tc_aws.rb,v 1.8 2008/08/12 09:50:48 ianmacd Exp $
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.1
7
- date: 2008-08-18 00:00:00 +02:00
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