amazon_sdb 0.5.5 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ == 0.6.0 / 2007-12-28
2
+ * 2 major enhancements
3
+ * Correct error handling for API's HTTP responses (with tests)
4
+ * I now have Amazon::SimpleDB, so I can see if it works or not
5
+
1
6
  == 0.5.5 / 2007-12-15
2
7
 
3
8
  * 2 major enhancements
@@ -33,7 +33,7 @@ require 'amazon_sdb/exceptions'
33
33
 
34
34
  module Amazon
35
35
  module SDB
36
- VERSION = '0.5.5'
36
+ VERSION = '0.6.0'
37
37
  end
38
38
  end
39
39
 
@@ -76,12 +76,27 @@ module Amazon
76
76
  errnode = hpricot.at('//Errors/Error')
77
77
  return unless errnode
78
78
 
79
- msg = errnode.at('Message').innerText
80
- case errnode.at('Code').innerText
81
- when 'InvalidParameterValue'
82
- raise InvalidParameterError, msg
83
- when 'NumberDomainsExceeded'
84
- raise DomainLimitError, msg
79
+ code = errnode.at('Code').innerText
80
+ msg = "#{code}: #{errnode.at('Message').innerText}"
81
+
82
+ if AUTH_ERROR_CODES.include? code
83
+ raise AuthError, msg
84
+ elsif ACCESS_ERROR_CODES.include? code
85
+ raise AccessError, msg
86
+ elsif PARAMETER_ERROR_CODES.include? code
87
+ raise ParameterError, msg
88
+ elsif QUERY_ERROR_CODES.include? code
89
+ raise QuerySyntaxError, msg
90
+ elsif LIMIT_ERROR_CODES.include? code
91
+ raise LimitError, msg
92
+ elsif REQUEST_ERROR_CODES.include? code
93
+ raise RequestError, msg
94
+ elsif SERVER_ERROR_CODES.include? code
95
+ raise ServerError, msg
96
+ elsif TIMEOUT_ERROR_CODES.include? code
97
+ raise TimeoutError, msg
98
+ elsif VERSION_ERROR_CODES.include? code
99
+ raise VersionError, msg
85
100
  else
86
101
  raise UnknownError, msg
87
102
  end
@@ -129,11 +144,16 @@ module Amazon
129
144
  url = BASE_PATH + '?' + cgi_encode(options)
130
145
 
131
146
  # puts "Requesting #{url}" #if $DEBUG
132
- open(url) do |f|
133
- h = Hpricot.XML(f)
147
+ begin
148
+ open(url) do |f|
149
+ h = Hpricot.XML(f)
134
150
 
151
+ raise_errors h
152
+ yield h if block_given?
153
+ end
154
+ rescue OpenURI::HTTPError => e
155
+ h = Hpricot.XML(e.io.read)
135
156
  raise_errors h
136
- yield h if block_given?
137
157
  end
138
158
  end
139
159
 
@@ -1,18 +1,50 @@
1
1
  module Amazon
2
2
  module SDB
3
- class InvalidParameterError < ArgumentError
3
+ class Error < ::StandardError
4
4
  end
5
5
 
6
- class LimitError < Exception
6
+ ACCESS_ERROR_CODES = %w{AccessFailure}
7
+ class AccessError < Error
7
8
  end
8
9
 
9
- class DomainLimitError < LimitError
10
+ AUTH_ERROR_CODES = %w{AuthFailure AuthMissingFailure InvalidHTTPAuthHeader OptInRequired}
11
+ class AuthError < Error
10
12
  end
11
13
 
12
- class UnknownError < Exception
14
+ PARAMETER_ERROR_CODES = %w(InvalidAction InvalidNextToken InvalidParameterError
15
+ InvalidParameterCombination InvalidParameterValue MissingAction MissingParameter NoSuchDomain
16
+ )
17
+ class ParameterError < Error
13
18
  end
14
19
 
15
- class RecordNotFoundError < Exception
20
+ QUERY_ERROR_CODES = %w{InvalidNumberPredicates InvalidNumberValueTests InvalidQueryExpression}
21
+ class QuerySyntaxError < Error
22
+ end
23
+
24
+ LIMIT_ERROR_CODES = %w{NumberDomainsExceeded NumberDomainAttributesExceeded NumberDomainBytesExceeded NumberDomainBytesExceeeded URITooLong}
25
+ class LimitError < Error
26
+ end
27
+
28
+ SERVER_ERROR_CODES = %w{InternalError ServiceOverload ServiceUnavailable}
29
+ class ServerError < Error
30
+ end
31
+
32
+ class UnknownError < Error
33
+ end
34
+
35
+ REQUEST_ERROR_CODES = %w{InvalidHttpRequest InvalidSOAPRequest InvalidURI InvalidService UnsupportedHttpVerb}
36
+ class RequestError < Error
37
+ end
38
+
39
+ TIMEOUT_ERROR_CODES = %w{RequestExpired RequestTimeout RequestThrottled}
40
+ class TimeoutError < Error
41
+ end
42
+
43
+ VERSION_ERROR_CODES = %w{FeatureDeprecated NoSuchVersion NotYetImplemented}
44
+ class VersionError < Error
45
+ end
46
+
47
+ class RecordNotFoundError < Error
16
48
  end
17
49
  end
18
50
  end
@@ -115,14 +115,14 @@ class TestAmazonBase < Test::Unit::TestCase
115
115
  def test_create_domain_invalid_param
116
116
  @sdb.responses << error_response('InvalidParameterValue', 'Value (X) for parameter DomainName is invalid.')
117
117
 
118
- assert_raise(Amazon::SDB::InvalidParameterError) { @sdb.create_domain('(X)') }
118
+ assert_raise(Amazon::SDB::ParameterError) { @sdb.create_domain('(X)') }
119
119
  assert_equal 1, @sdb.uris.length
120
120
  end
121
121
 
122
122
  def test_create_domain_limit_error
123
123
  @sdb.responses << error_response('NumberDomainsExceeded', 'Domain Limit reached')
124
124
 
125
- assert_raise(Amazon::SDB::DomainLimitError) { @sdb.create_domain('foo') }
125
+ assert_raise(Amazon::SDB::LimitError) { @sdb.create_domain('foo') }
126
126
  end
127
127
 
128
128
  def test_delete_domain
@@ -0,0 +1,152 @@
1
+ require 'test_sdb_harness'
2
+
3
+ class TestException < Test::Unit::TestCase
4
+ def setup
5
+ @sdb = Amazon::SDB::Base.new 'API_KEY', 'SECRET_KEY'
6
+ end
7
+
8
+ def assert_err(code, exception_class)
9
+ @sdb.responses << error_response(code)
10
+ assert_raise(exception_class) { @sdb.domains }
11
+ end
12
+
13
+ def test_access_failure
14
+ assert_err('AccessFailure', Amazon::SDB::AccessError)
15
+ end
16
+
17
+ def test_auth_failure
18
+ assert_err('AuthFailure', Amazon::SDB::AuthError)
19
+ end
20
+
21
+ def test_auth_missing
22
+ assert_err('AuthMissingFailure', Amazon::SDB::AuthError)
23
+ end
24
+
25
+ def test_deprecated
26
+ assert_err('FeatureDeprecated', Amazon::SDB::VersionError)
27
+ end
28
+
29
+ def test_internal_error
30
+ assert_err('InternalError', Amazon::SDB::ServerError)
31
+ end
32
+
33
+ def test_invalid_action
34
+ assert_err('InvalidAction', Amazon::SDB::ParameterError)
35
+ end
36
+
37
+ def test_invalid_http_auth_header
38
+ assert_err('InvalidHTTPAuthHeader', Amazon::SDB::AuthError)
39
+ end
40
+
41
+ def test_invalid_http_request
42
+ assert_err('InvalidHttpRequest', Amazon::SDB::RequestError)
43
+ end
44
+
45
+ def test_invalid_param_value
46
+ assert_err('InvalidParameterValue', Amazon::SDB::ParameterError)
47
+ end
48
+
49
+ def test_invalid_next_token
50
+ assert_err('InvalidNextToken', Amazon::SDB::ParameterError)
51
+ end
52
+
53
+ def test_invalid_num_predicates
54
+ assert_err('InvalidNumberPredicates', Amazon::SDB::QuerySyntaxError)
55
+ end
56
+
57
+ def test_invalid_number_value_tests
58
+ assert_err('InvalidNumberValueTests', Amazon::SDB::QuerySyntaxError)
59
+ end
60
+
61
+ def test_invalid_parameter_combo
62
+ assert_err('InvalidParameterCombination', Amazon::SDB::ParameterError)
63
+ end
64
+
65
+ def test_invalid_parameter_value
66
+ assert_err('InvalidParameterValue', Amazon::SDB::ParameterError)
67
+ end
68
+
69
+ def test_invalid_query_expr
70
+ assert_err('InvalidQueryExpression', Amazon::SDB::QuerySyntaxError)
71
+ end
72
+
73
+ def test_invalid_response_groups
74
+ assert_err('InvalidResponseGroups', Amazon::SDB::UnknownError)
75
+ end
76
+
77
+ def test_invalid_service
78
+ assert_err('InvalidService', Amazon::SDB::RequestError)
79
+ end
80
+
81
+ def test_soap_request
82
+ assert_err('InvalidSOAPRequest', Amazon::SDB::RequestError)
83
+ end
84
+
85
+ def test_invalid_uri
86
+ assert_err('InvalidURI', Amazon::SDB::RequestError)
87
+ end
88
+
89
+ def test_missing_action
90
+ assert_err('MissingAction', Amazon::SDB::ParameterError)
91
+ end
92
+
93
+ def test_missing_parameter
94
+ assert_err('MissingParameter', Amazon::SDB::ParameterError)
95
+ end
96
+
97
+ def test_no_such_domain
98
+ assert_err('NoSuchDomain', Amazon::SDB::ParameterError)
99
+ end
100
+
101
+ def test_no_such_version
102
+ assert_err('NoSuchVersion', Amazon::SDB::VersionError)
103
+ end
104
+
105
+ def test_not_yet_implemented
106
+ assert_err('NotYetImplemented', Amazon::SDB::VersionError)
107
+ end
108
+
109
+ def test_num_domains_exceeded
110
+ assert_err('NumberDomainsExceeded', Amazon::SDB::LimitError)
111
+ end
112
+
113
+ def test_num_domain_attributes_exceed
114
+ assert_err('NumberDomainAttributesExceeded', Amazon::SDB::LimitError)
115
+ end
116
+
117
+ def test_num_domain_bytes_exceed
118
+ assert_err('NumberDomainBytesExceeded', Amazon::SDB::LimitError)
119
+ end
120
+
121
+ def test_num_item_attrs_exceed
122
+ assert_err('NumberDomainBytesExceeded', Amazon::SDB::LimitError)
123
+ end
124
+
125
+ def test_request_expired
126
+ assert_err('RequestExpired', Amazon::SDB::TimeoutError)
127
+ end
128
+
129
+ def test_request_timeout
130
+ assert_err('RequestTimeout', Amazon::SDB::TimeoutError)
131
+ end
132
+
133
+ def test_request_throttle
134
+ assert_err('RequestThrottled', Amazon::SDB::TimeoutError)
135
+ end
136
+
137
+ def test_service_overload
138
+ assert_err('ServiceOverload', Amazon::SDB::ServerError)
139
+ end
140
+
141
+ def test_service_unavailable
142
+ assert_err('ServiceUnavailable', Amazon::SDB::ServerError)
143
+ end
144
+
145
+ def test_unsupported_http_verb
146
+ assert_err('UnsupportedHttpVerb', Amazon::SDB::RequestError)
147
+ end
148
+
149
+ def test_uri_too_long
150
+ assert_err('URITooLong', Amazon::SDB::LimitError)
151
+ end
152
+ end
@@ -25,7 +25,9 @@ class Amazon::SDB::Base
25
25
  end
26
26
 
27
27
  class Test::Unit::TestCase
28
- def error_response(code, msg)
28
+ def error_response(code, msg=nil)
29
+ msg ||= "ERROR MESSAGE"
30
+
29
31
  "<Response>
30
32
  <Errors>
31
33
  <Error>
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amazon_sdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
5
- platform: ""
4
+ version: 0.6.0
5
+ platform: ruby
6
6
  authors:
7
7
  - Jacob Harris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2007-12-17 00:00:00 -05:00
12
+ date: 2007-12-28 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -28,7 +28,7 @@ dependencies:
28
28
  requirements:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- version: 1.3.0
31
+ version: 1.4.0
32
32
  version:
33
33
  description: A ruby wrapper to Amazon's sdb service
34
34
  email: harrisj@nytimes.com
@@ -79,12 +79,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  requirements: []
80
80
 
81
81
  rubyforge_project: nytimes
82
- rubygems_version: 0.9.5
82
+ rubygems_version: 1.0.0
83
83
  signing_key:
84
84
  specification_version: 2
85
85
  summary: A ruby wrapper to Amazon's sdb service
86
86
  test_files:
87
87
  - test/test_amazon_base.rb
88
88
  - test/test_amazon_domain.rb
89
+ - test/test_exceptions.rb
89
90
  - test/test_multimap.rb
90
91
  - test/test_sdb_harness.rb