aws-sdk-core 2.0.0.rc3 → 2.0.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,9 +24,9 @@ module Aws
24
24
  private
25
25
 
26
26
  def error(context, code, message)
27
- svc_class_name = context.config.api.metadata['service_class_name']
28
- klass = Errors.error_class(svc_class_name, code)
29
- Errors.error_class(svc_class_name, code).new(context, message)
27
+ svc = context.client.class.name.split('::')[1]
28
+ errors_module = Aws.const_get(svc).const_get(:Errors)
29
+ errors_module.error_class(code).new(context, message)
30
30
  end
31
31
 
32
32
  def empty_body?(response)
@@ -57,24 +57,18 @@ module Aws
57
57
  const_set(constant, Class.new(ServiceError))
58
58
  end
59
59
 
60
- end
61
-
62
- class << self
63
-
64
60
  # Given the name of a service and an error code, this method
65
61
  # returns an error class (that extends {ServiceError}.
66
62
  #
67
- # Aws::Errors.error_class('S3', 'NoSuchBucket').new
63
+ # Aws::S3::Errors.error_class('NoSuchBucket').new
68
64
  # #=> #<Aws::S3::Errors::NoSuchBucket>
69
65
  #
70
66
  # @api private
71
- def error_class(svc_class_name, error_code)
72
- constant = error_code.to_s.gsub(/\W+/, '').to_sym
73
- errors = Aws.const_get(svc_class_name).const_get(:Errors)
74
- if errors.constants.include?(constant)
75
- errors.const_get(constant)
67
+ def error_class(contstant)
68
+ if constants.include?(contstant.to_sym)
69
+ const_get(contstant)
76
70
  else
77
- errors.const_set(constant, Class.new(ServiceError))
71
+ const_set(contstant, Class.new(ServiceError))
78
72
  end
79
73
  end
80
74
 
@@ -56,7 +56,7 @@ module Aws
56
56
  def compute_checksums(body, &block)
57
57
 
58
58
  tree_hash = TreeHash.new
59
- digest = OpenSSL::Digest::Digest.new('sha256')
59
+ digest = OpenSSL::Digest.new('sha256')
60
60
 
61
61
  # if the body is empty/EOF, then we should compute the
62
62
  # digests of the empty string
@@ -21,7 +21,7 @@ module Aws
21
21
  if xml['Error']
22
22
  error_code = xml['Error']['Code']
23
23
  error_message = xml['Error']['Message']
24
- Errors.error_class('S3', error_code).new(error_message)
24
+ S3::Errors.error_class(error_code).new(response.context, error_message)
25
25
  end
26
26
  end
27
27
 
@@ -11,7 +11,7 @@ module Aws
11
11
 
12
12
  def sha256_hmac(value)
13
13
  Base64.encode64(
14
- OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha256'),
14
+ OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'),
15
15
  @credentials.secret_access_key, value)
16
16
  ).strip
17
17
  end
@@ -69,7 +69,7 @@ module Aws
69
69
  end
70
70
 
71
71
  def hmac(key, value)
72
- OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), key, value)
72
+ OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), key, value)
73
73
  end
74
74
 
75
75
  # From the S3 developer guide:
@@ -119,11 +119,11 @@ module Aws
119
119
  end
120
120
 
121
121
  def hmac(key, value)
122
- OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha256'), key, value)
122
+ OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), key, value)
123
123
  end
124
124
 
125
125
  def hexhmac(key, value)
126
- OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha256'), key, value)
126
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), key, value)
127
127
  end
128
128
 
129
129
  private
@@ -31,7 +31,7 @@ module Aws
31
31
  class TreeHash
32
32
 
33
33
  def initialize(hashes = [])
34
- @digest = OpenSSL::Digest::Digest.new('sha256')
34
+ @digest = OpenSSL::Digest.new('sha256')
35
35
  @hashes = hashes
36
36
  end
37
37
 
@@ -49,7 +49,7 @@ module Aws
49
49
 
50
50
  def digest
51
51
  hashes = @hashes
52
- digest = OpenSSL::Digest::Digest.new('sha256')
52
+ digest = OpenSSL::Digest.new('sha256')
53
53
  until hashes.count == 1
54
54
  hashes = hashes.each_slice(2).map do |h1,h2|
55
55
  digest.reset
@@ -1,3 +1,3 @@
1
1
  module Aws
2
- VERSION = '2.0.0.rc3'
2
+ VERSION = '2.0.0.rc4'
3
3
  end
@@ -235,13 +235,27 @@ module Aws
235
235
  expect(err_class.new).to be_kind_of(Errors::ServiceError)
236
236
  end
237
237
 
238
+ end
239
+
240
+ describe 'DynamicErrors module' do
241
+
238
242
  it 'allows you to create error classes named like Ruby classes' do
239
- error_class = Aws::Errors.error_class('S3', 'Range')
243
+ mod = Module.new
244
+ mod.extend(Aws::Errors::DynamicErrors)
245
+ error_class = mod.error_class('Range')
240
246
  expect(error_class).not_to be(Range)
241
- expect(error_class).to be(Aws::S3::Errors::Range)
247
+ expect(error_class).to be(mod::Range)
242
248
  expect(error_class.ancestors).to include(Errors::ServiceError)
243
249
  end
244
250
 
251
+ it 'always returns the same error class given the same error code' do
252
+ mod = Module.new
253
+ mod.extend(Aws::Errors::DynamicErrors)
254
+ klass2 = mod.error_class(:Range)
255
+ klass1 = mod.error_class('Range')
256
+ expect(klass1).to be(klass2)
257
+ end
258
+
245
259
  end
246
260
  end
247
261
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-sdk-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.rc3
4
+ version: 2.0.0.rc4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amazon Web Services
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-18 00:00:00.000000000 Z
11
+ date: 2014-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json