ruby-aaws 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/NEWS CHANGED
@@ -1,6 +1,32 @@
1
- $Id: NEWS,v 1.12 2008/09/10 22:15:41 ianmacd Exp $
1
+ $Id: NEWS,v 1.13 2008/09/21 22:25:55 ianmacd Exp $
2
2
 
3
3
 
4
+ 0.4.3
5
+ -----
6
+
7
+ $AMAZONRCDIR is now searched for .amazonrc before $HOME and the other
8
+ directories. This allows a user-defined location to be used for the user
9
+ configuration file.
10
+
11
+ There is a new top-level class of exception for Ruby/AWS, Amazon::AmazonError.
12
+
13
+ Most non-operational exceptions, such as Amazon::AWS::HTTPError,
14
+ Amazon::Config::ConfigError, Amazon::AWS::Search::Request::AccessKeyIdError,
15
+ Amazon::AWS::Search::Request::LocaleError and
16
+ Amazon::AWS::ShoppingCart::CartError are now immediate subclasses of
17
+ AmazonError. Previously, they were subclasses of StandardError.
18
+
19
+ Amazon::AWS::Error::AWSError was previously a class that generated exceptions,
20
+ but it's now simply a container class derived from AmazonError. All
21
+ operational exceptions -- the ones whose class is dynamically created when AWS
22
+ returns an error -- are now subclasses of AWSError. Previously, they were
23
+ immediate subclasses of StandardError.
24
+
25
+ This has the advantage of allowing all of the exceptions resulting from
26
+ operational errors to be caught by rescuing just the container class,
27
+ AWSError.
28
+
29
+
4
30
  0.4.2
5
31
  -----
6
32
 
data/README CHANGED
@@ -1,4 +1,4 @@
1
- $Id: README,v 1.14 2008/08/17 11:59:27 ianmacd Exp $
1
+ $Id: README,v 1.16 2008/09/21 13:26:51 ianmacd Exp $
2
2
 
3
3
 
4
4
  Introduction
@@ -163,30 +163,32 @@ Usage
163
163
  First of all, create either /etc/amazonrc or ~/.amazonrc. Its contents should
164
164
  look something like this:
165
165
 
166
- dev_token = 'D11XZ51ZUKJY66'
166
+ key_id = '0Y44V8G41KCQPGF6PTR2'
167
167
  associate = 'fuzbarorg-21'
168
168
  locale = 'uk'
169
- email = 'foo@caliban.org'
170
- password = 'xxxxxx'
171
169
  cache = false
172
- key_id = '0Y44V8G41KCQPGF6PTR2'
173
170
 
174
- Because you're embedding a password and your key ID in the file, you should
175
- protect it (on UNIX and similar systems) by making it mode 0600:
171
+ Because you're embedding your key ID in the file, you should protect it (on
172
+ UNIX and similar systems) by making it mode 0600:
176
173
 
177
174
  $ chmod 600 ~/.amazonrc
178
175
 
179
- If you define cache to be true, you may also define cache_dir to point
180
- somewhere other /tmp/amazon, which is the default.
176
+ If you define 'cache' to be 'true', you may also define 'cache_dir' to point
177
+ to somewhere other the default, /tmp/amazon.
178
+
179
+ If $HOME is undefined, as is usually the case on Windows, alternative
180
+ locations are searched for the user configuration file. In fact, one location
181
+ is even searched prior to looking in $HOME.
181
182
 
182
- If you're using Windows, the following locations are searched for the user
183
- configuration file:
183
+ The exact search order is as follows:
184
184
 
185
- %HOME%
186
- %HOMEDRIVE% + %HOMEPATH%
187
- %USERPROFILE%
185
+ $AMAZONRCDIR
186
+ $HOME
187
+ $HOMEDRIVE + $HOMEPATH
188
+ $USERPROFILE
188
189
 
189
- Choose one of these at your convenience.
190
+ So, you can put the user configuration file in any of these locations, but it
191
+ must always be called .amazonrc.
190
192
 
191
193
  Once you have your configuration file, you can get started on your code.
192
194
 
@@ -1,5 +1,5 @@
1
1
  #--
2
- # $Id: README.rdoc,v 1.17 2008/09/10 21:56:13 ianmacd Exp $
2
+ # $Id: README.rdoc,v 1.18 2008/09/21 22:25:55 ianmacd Exp $
3
3
  #++
4
4
  #
5
5
  #
@@ -120,15 +120,15 @@
120
120
  #
121
121
  # == Download
122
122
  #
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]
123
+ # Version 0.4.3
124
+ # === {gzip'ed tar archive}[http://www.caliban.org/files/ruby/ruby-aws-0.4.3.tar.gz]
125
+ # === {Ruby Gem}[http://www.caliban.org/files/ruby/ruby-aaws-0.4.3.gem]
126
+ # === {Fedora 9 RPM}[http://www.caliban.org/files/redhat/RPMS/noarch/ruby-aws-0.4.3-1.fc9.noarch.rpm]
127
+ # === {Fedora 9 doc RPM}[http://www.caliban.org/files/redhat/RPMS/noarch/ruby-aws-doc-0.4.3-1.fc9.noarch.rpm]
128
+ # === {Fedora 9 source RPM}[http://www.caliban.org/files/redhat/SRPMS/ruby-aws-0.4.3-1.fc9.src.rpm]
129
129
  #
130
130
  #
131
131
  # ---
132
132
  # Author:: Ian Macdonald <mailto:ian@caliban.org>
133
- # Version:: 0.4.2
133
+ # Version:: 0.4.3
134
134
  # Licence:: GPL[http://www.gnu.org/copyleft/gpl.html]
@@ -1,8 +1,12 @@
1
- # $Id: amazon.rb,v 1.20 2008/09/08 22:42:30 ianmacd Exp $
1
+ # $Id: amazon.rb,v 1.23 2008/09/21 22:24:35 ianmacd Exp $
2
2
  #
3
3
 
4
4
  module Amazon
5
5
 
6
+ # A top-level exception container class.
7
+ #
8
+ class AmazonError < StandardError; end
9
+
6
10
  NAME = 'Ruby/Amazon'
7
11
  @@config = {}
8
12
 
@@ -52,7 +56,7 @@ module Amazon
52
56
 
53
57
  # Exception class for configuration file errors.
54
58
  #
55
- class ConfigError < StandardError; end
59
+ class ConfigError < AmazonError; end
56
60
 
57
61
  # A configuration may be passed in as a string. Otherwise, the files
58
62
  # <tt>/etc/amazonrc</tt> and <tt>~/.amazonrc</tt> are read if they exist
@@ -73,10 +77,11 @@ module Amazon
73
77
  #
74
78
  config_files = [ File.join( '', 'etc', 'amazonrc' ) ]
75
79
 
76
- # Figure out where home is. The subsequent locations are for Windows.
80
+ # Figure out where home is. The locations after HOME are for Windows.
77
81
  # [ruby-core:12347]
78
82
  #
79
- home = ENV['HOME'] || ENV['HOMEDRIVE'] + ENV['HOMEPATH'] ||
83
+ home = ENV['AMAZONRCDIR'] ||
84
+ ENV['HOME'] || ENV['HOMEDRIVE'] + ENV['HOMEPATH'] ||
80
85
  ENV['USERPROFILE']
81
86
 
82
87
  if home
@@ -1,4 +1,4 @@
1
- # $Id: aws.rb,v 1.68 2008/09/10 21:56:14 ianmacd Exp $
1
+ # $Id: aws.rb,v 1.71 2008/09/21 22:28:17 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.2'
15
+ VERSION = '0.4.3'
16
16
  USER_AGENT = '%s %s' % [ NAME, VERSION ]
17
17
 
18
18
  # Default Associate tags to use per locale.
@@ -41,19 +41,20 @@ module Amazon
41
41
  # search operation, using whichever pagination parameter is relevant to
42
42
  # that type of operation.
43
43
  #
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
- }
44
+ PAGINATION = {
45
+ 'ItemSearch' => { 'parameter' => 'ItemPage',
46
+ 'max_page' => 400 },
47
+ 'ItemLookup' => { 'paraneter' => 'OfferPage',
48
+ 'max_page' => 100 },
49
+ 'ListLookup' => { 'parameter' => 'ProductPage',
50
+ 'max_page' => 30 },
51
+ 'ListSearch' => { 'parameter' => 'ListPage',
52
+ 'max_page' => 20 },
53
+ 'CustomerContentLookup' => { 'parameter' => 'ReviewPage',
54
+ 'max_page' => 10 },
55
+ 'CustomerContentSearch' => { 'parameter' => 'CustomerPage',
56
+ 'max_page' => 20 }
57
+ }
57
58
  # N.B. ItemLookup can also use the following two pagination parameters
58
59
  #
59
60
  # max. page
@@ -63,7 +64,7 @@ module Amazon
63
64
 
64
65
  # Exception class for HTTP errors.
65
66
  #
66
- class HTTPError < StandardError; end
67
+ class HTTPError < AmazonError; end
67
68
 
68
69
  class Endpoint
69
70
 
@@ -1147,25 +1148,25 @@ module Amazon
1147
1148
  #
1148
1149
  module Error
1149
1150
 
1150
- # An exception generator class.
1151
+ # The base exception class for errors that result from AWS operations.
1152
+ # Classes for these are dynamically generated as subclasses of this one.
1151
1153
  #
1152
- class AWSError
1153
-
1154
- attr_reader :exception
1155
-
1156
- def initialize(xml)
1157
- err_class = xml.elements['Code'].text.sub( /^AWS.*\./, '' )
1158
- err_msg = xml.elements['Message'].text
1154
+ class AWSError < AmazonError; end
1159
1155
 
1160
- unless Amazon::AWS::Error.const_defined?( err_class )
1161
- Amazon::AWS::Error.const_set( err_class,
1162
- Class.new( StandardError ) )
1163
- end
1156
+ def Error.exception(xml)
1157
+ err_class = xml.elements['Code'].text.sub( /^AWS.*\./, '' )
1158
+ err_msg = xml.elements['Message'].text
1164
1159
 
1165
- ex_class = Amazon::AWS::Error.const_get( err_class )
1166
- @exception = ex_class.new( err_msg )
1160
+ # Dynamically define a new exception class for this class of error,
1161
+ # unless it already exists.
1162
+ #
1163
+ unless Amazon::AWS::Error.const_defined?( err_class )
1164
+ Amazon::AWS::Error.const_set( err_class, Class.new( AWSError ) )
1167
1165
  end
1168
1166
 
1167
+ # Generate and return a new exception from the relevant class.
1168
+ #
1169
+ Amazon::AWS::Error.const_get( err_class ).new( err_msg )
1169
1170
  end
1170
1171
 
1171
1172
  end
@@ -1,4 +1,4 @@
1
- # $Id: search.rb,v 1.23 2008/09/10 21:43:58 ianmacd Exp $
1
+ # $Id: search.rb,v 1.26 2008/09/21 22:17:32 ianmacd Exp $
2
2
  #
3
3
 
4
4
  module Amazon
@@ -21,11 +21,11 @@ module Amazon
21
21
 
22
22
  # Exception class for bad access key ID.
23
23
  #
24
- class AccessKeyIdError < StandardError; end
24
+ class AccessKeyIdError < Amazon::AWS::Error::AWSError; end
25
25
 
26
26
  # Exception class for bad locales.
27
27
  #
28
- class LocaleError < StandardError; end
28
+ class LocaleError < Amazon::AWS::Error::AWSError; end
29
29
 
30
30
  attr_reader :conn, :locale, :user_agent
31
31
  attr_writer :cache
@@ -167,8 +167,7 @@ module Amazon
167
167
  #
168
168
  def error_check(xml)
169
169
  if xml = xml.elements['Errors/Error']
170
- error = Amazon::AWS::Error::AWSError.new( xml )
171
- raise error.exception
170
+ raise Amazon::AWS::Error.exception( xml )
172
171
  end
173
172
  end
174
173
  private :error_check
@@ -1,4 +1,4 @@
1
- # $Id: shoppingcart.rb,v 1.17 2008/07/13 01:56:43 ianmacd Exp $
1
+ # $Id: shoppingcart.rb,v 1.19 2008/09/21 22:17:32 ianmacd Exp $
2
2
  #
3
3
 
4
4
  require 'amazon/aws/search'
@@ -16,7 +16,7 @@ module Amazon
16
16
  # Attempts to remove non-existent items from a shopping-cart will raise
17
17
  # this exception.
18
18
  #
19
- class CartError < StandardError; end
19
+ class CartError < Amazon::AWS::Error::AWSError; end
20
20
 
21
21
  class Cart < Amazon::AWS::Search::Request
22
22
 
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.2
7
- date: 2008-09-11 00:00:00 +02:00
6
+ version: 0.4.3
7
+ date: 2008-09-22 00:00:00 +02:00
8
8
  summary: Ruby interface to Amazon Associates Web Services
9
9
  require_paths:
10
10
  - lib