aws-sdk 1.0.2 → 1.0.3

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.
@@ -350,6 +350,7 @@ module AWS
350
350
  protected
351
351
  def xml_error_response? response
352
352
  response.http_response.status >= 300 and
353
+ response.http_response.body and
353
354
  xml_error_grammar.parse(response.http_response.body).respond_to?(:code)
354
355
 
355
356
  end
@@ -11,6 +11,7 @@
11
11
  # ANY KIND, either express or implied. See the License for the specific
12
12
  # language governing permissions and limitations under the License.
13
13
 
14
+ require 'aws/base_client'
14
15
  require 'aws/configured_xml_grammars'
15
16
 
16
17
  module AWS
@@ -11,7 +11,7 @@
11
11
  # ANY KIND, either express or implied. See the License for the specific
12
12
  # language governing permissions and limitations under the License.
13
13
 
14
- require 'cgi'
14
+ require 'aws/uri_escape'
15
15
 
16
16
  module AWS
17
17
  module Http
@@ -24,6 +24,8 @@ module AWS
24
24
  # @private
25
25
  class Param
26
26
 
27
+ include UriEscape
28
+
27
29
  attr_accessor :name, :value
28
30
 
29
31
  def initialize name, value = nil
@@ -56,14 +58,6 @@ module AWS
56
58
  end
57
59
  end
58
60
 
59
- # @private
60
- protected
61
- def escape value
62
- value = value.encode("UTF-8") if
63
- value.respond_to?(:encode)
64
- CGI::escape(value.to_s).gsub('+', '%20')
65
- end
66
-
67
61
  end
68
62
  end
69
63
  end
@@ -32,8 +32,8 @@ module AWS
32
32
  # A handful of useful Rails integration methods.
33
33
  #
34
34
  # If you require this gem inside a Rails application (via config.gem
35
- # for rails 2 and bundler for rails 3) then AWS::Rails.setup
36
- # is called automatically.
35
+ # for rails 2 and bundler for rails 3) then {setup} is called
36
+ # automatically.
37
37
  module Rails
38
38
 
39
39
  # Adds extra functionality to Rails.
@@ -43,33 +43,12 @@ module AWS
43
43
  #
44
44
  # Rails 3+ (RAILS_ROOT/Gemfile)
45
45
  #
46
- # gem 'aws-sdk-rails'
46
+ # gem 'aws-sdk'
47
47
  #
48
48
  # Rails 2.1 - 2.3 (RAILS_ROOT/config/environment.rb)
49
49
  #
50
- # config.gem 'aws-sdk-rails'
50
+ # config.gem 'aws-sdk'
51
51
  #
52
- # === Selective Rails Features
53
- #
54
- # If you would prefer to cherry pick a few of the features added by this
55
- # gem you can change your gem requirement to load 'aws/rails' instead:
56
- #
57
- # Rails 3+ (RAILS_ROOT/Gemfile)
58
- #
59
- # gem 'aws-sdk-rails', :require => 'aws/rails'
60
- #
61
- # Rails 2.1 - 2.3 (RAILS_ROOT/config/environment.rb)
62
- #
63
- # config.gem 'aws-sdk-rails', :lib => 'aws/rails'
64
- #
65
- # In both of the examples above you can now configure AWS and call the setup
66
- # methods of choice inside a config initializer (e.g.
67
- # RAILS_ROOT/config/initializers/aws.rb):
68
- #
69
- # AWS.config(...)
70
- # AWS.log_to_rails_logger
71
- # AWS.add_action_mailer_delivery_method
72
- #
73
52
  # @return [nil]
74
53
  def self.setup
75
54
  load_yaml_config
@@ -135,7 +114,8 @@ module AWS
135
114
 
136
115
  end
137
116
 
138
- # Adds a delivery method to ActionMailer that uses {AWS::SimplEmailService}.
117
+ # Adds a delivery method to ActionMailer that uses
118
+ # {AWS::SimpleEmailService}.
139
119
  #
140
120
  # Once you have an SES delivery method you can configure Rails to
141
121
  # use this for ActionMailer in your environment configuration
@@ -58,6 +58,7 @@ module AWS
58
58
  # by AWS.
59
59
  def throttled?
60
60
  !successful? and
61
+ http_response.body and
61
62
  parsed_body = XmlGrammar.parse(http_response.body) and
62
63
  parsed_body.respond_to?(:code) and
63
64
  parsed_body.code == "Throttling"
@@ -78,6 +78,11 @@ module AWS
78
78
 
79
79
  XMLNS = "http://s3.amazonaws.com/doc/#{API_VERSION}/"
80
80
 
81
+ EMPTY_BODY_ERRORS = {
82
+ 304 => Errors::NotModified,
83
+ 404 => Errors::NoSuchKey
84
+ }
85
+
81
86
  include DataOptions
82
87
 
83
88
  configure_client
@@ -471,6 +476,9 @@ module AWS
471
476
  MetaUtils.extend_method(response, :etag) do
472
477
  response.http_response.header('ETag')
473
478
  end
479
+ MetaUtils.extend_method(response, :last_modified) do
480
+ Time.parse(response.http_response.header('Last-Modified'))
481
+ end
474
482
  end
475
483
 
476
484
  simulate_response do |response|
@@ -610,6 +618,10 @@ module AWS
610
618
  end
611
619
  end
612
620
 
621
+ MetaUtils.extend_method(resp, :last_modified) do
622
+ Time.parse(resp.http_response.header('Last-Modified'))
623
+ end
624
+
613
625
  MetaUtils.extend_method(resp, :content_length) do
614
626
  http_response.header('content-length').to_i
615
627
  end
@@ -695,6 +707,9 @@ module AWS
695
707
  MetaUtils.extend_method(response, :etag) do
696
708
  response.http_response.header('ETag')
697
709
  end
710
+ MetaUtils.extend_method(response, :last_modified) do
711
+ Time.parse(response.http_response.header('Last-Modified'))
712
+ end
698
713
  end
699
714
 
700
715
  simulate_response do |response|
@@ -791,6 +806,9 @@ module AWS
791
806
  MetaUtils.extend_method(response, :etag) do
792
807
  response.http_response.header('ETag')
793
808
  end
809
+ MetaUtils.extend_method(response, :last_modified) do
810
+ Time.parse(response.http_response.header('Last-Modified'))
811
+ end
794
812
  end
795
813
 
796
814
  end
@@ -799,9 +817,23 @@ module AWS
799
817
  def xml_error_response? response
800
818
  (response.http_response.status >= 300 ||
801
819
  response.request_type == :complete_multipart_upload) and
820
+ response.http_response.body and
802
821
  XmlGrammar.parse(response.http_response.body).respond_to?(:code)
803
822
  end
804
823
 
824
+ protected
825
+ def populate_error response
826
+ code = response.http_response.status
827
+ if EMPTY_BODY_ERRORS.include?(code) and
828
+ response.http_response.body.nil?
829
+ response.error =
830
+ EMPTY_BODY_ERRORS[code].new(response.http_request,
831
+ response.http_response)
832
+ else
833
+ super
834
+ end
835
+ end
836
+
805
837
  protected
806
838
  def should_retry? response
807
839
  super or
@@ -38,6 +38,34 @@ module AWS
38
38
 
39
39
  include LazyErrorClasses
40
40
 
41
+ # This error is special, because S3 does not (and must not
42
+ # according to RFC 2616) return a body with the HTTP response.
43
+ # The interface is the same as for any other client error.
44
+ class NotModified < AWS::Errors::Base
45
+ include AWS::Errors::ClientError
46
+
47
+ def code; "NotModified"; end
48
+
49
+ def initialize(req, resp)
50
+ super(req, resp, "Not Modified")
51
+ end
52
+
53
+ end
54
+
55
+ # This error is special, because S3 does not return a body with
56
+ # the HTTP response. The interface is the same as for any other
57
+ # client error.
58
+ class NoSuchKey < AWS::Errors::Base
59
+ include AWS::Errors::ClientError
60
+
61
+ def code; "NoSuchKey"; end
62
+
63
+ def initialize(req, resp)
64
+ super(req, resp, "No Such Key")
65
+ end
66
+
67
+ end
68
+
41
69
  end
42
70
  end
43
71
  end
@@ -13,6 +13,7 @@
13
13
 
14
14
  require 'aws/http/request'
15
15
  require 'aws/base_client'
16
+ require 'aws/uri_escape'
16
17
  require 'uri'
17
18
  require 'time'
18
19
 
@@ -22,6 +23,8 @@ module AWS
22
23
  # @private
23
24
  class Request < AWS::Http::Request
24
25
 
26
+ include UriEscape
27
+
25
28
  # @param [bucket] S3 bucket name
26
29
  attr_accessor :bucket
27
30
 
@@ -59,7 +62,7 @@ module AWS
59
62
  def path
60
63
  parts = []
61
64
  parts << bucket if bucket and Client.path_style_bucket_name?(bucket)
62
- parts << key if key
65
+ parts << escape_path(key) if key
63
66
  "/#{parts.join('/')}"
64
67
  end
65
68
 
@@ -74,6 +74,14 @@ module AWS
74
74
 
75
75
  alias_method :eql?, :==
76
76
 
77
+ def exists?
78
+ head
79
+ rescue Errors::NoSuchKey => e
80
+ false
81
+ else
82
+ true
83
+ end
84
+
77
85
  # Performs a HEAD request against this object and returns an object
78
86
  # with useful information about the object, including:
79
87
  #
@@ -103,6 +111,13 @@ module AWS
103
111
  head.etag
104
112
  end
105
113
 
114
+ # Returns the object's last modified time.
115
+ #
116
+ # @return [Time] Returns the object's last modified time.
117
+ def last_modified
118
+ head.last_modified
119
+ end
120
+
106
121
  # @return [Integer] Size of the object in bytes.
107
122
  def content_length
108
123
  head.content_length
@@ -488,14 +503,24 @@ module AWS
488
503
  # @param [Hash] options
489
504
  # @option options [String] :version_id Reads data from a
490
505
  # specific version of this object.
491
- # @option options [Time] :if_unmodified_since Causes #read
492
- # to return nil if the object was modified since the
493
- # given time.
494
- # @option options [Time] :if_modified_since Causes #read
495
- # to return nil unless the object was modified since the
496
- # given time.
497
- # @option options [String] :if_match If specified, the method
498
- # will return nil (and not fetch any data) unless the object ETag
506
+ #
507
+ # @option options [Time] :if_unmodified_since If specified, the
508
+ # method will raise
509
+ # <tt>AWS::S3::Errors::PreconditionFailed</tt> unless the
510
+ # object has not been modified since the given time.
511
+ #
512
+ # @option options [Time] :if_modified_since If specified, the
513
+ # method will raise <tt>AWS::S3::Errors::NotModified</tt> if
514
+ # the object has not been modified since the given time.
515
+ #
516
+ # @option options [String] :if_match If specified, the method
517
+ # will raise <tt>AWS::S3::Errors::PreconditionFailed</tt>
518
+ # unless the object ETag matches the provided value.
519
+ #
520
+ # @option options [String] :if_none_match If specified, the
521
+ # method will raise <tt>AWS::S3::Errors::NotModified</tt> if
522
+ # the object ETag matches the provided value.
523
+ #
499
524
  # @option options [Range] :range A byte range to read data from
500
525
  def read(options = {}, &blk)
501
526
  options[:bucket_name] = bucket.name
@@ -0,0 +1,40 @@
1
+ # Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is
10
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific
12
+ # language governing permissions and limitations under the License.
13
+
14
+ require 'cgi'
15
+
16
+ module AWS
17
+
18
+ # @private
19
+ module UriEscape
20
+
21
+ # Does URI escaping the way AWS expects it to be done.
22
+ #
23
+ # @private
24
+ protected
25
+ def escape value
26
+ value = value.encode("UTF-8") if
27
+ value.respond_to?(:encode)
28
+ CGI::escape(value.to_s).gsub('+', '%20')
29
+ end
30
+
31
+ # URI-escapes a path without escaping the separators
32
+ #
33
+ # @private
34
+ protected
35
+ def escape_path value
36
+ value.split("/").map { |part| escape(part) }.join("/")
37
+ end
38
+
39
+ end
40
+ end
@@ -66,14 +66,16 @@ module AWS
66
66
  class CustomizationContext < Hash
67
67
 
68
68
  def initialize(element_name = nil)
69
- self[:children] = {}
69
+ original_store(:children, {})
70
70
 
71
71
  if element_name
72
- self[:name] = element_name
72
+ original_store(:name, element_name)
73
73
  recompute_accessors
74
74
  end
75
75
  end
76
76
 
77
+ alias_method :original_store, :[]=
78
+
77
79
  def []=(name, value)
78
80
  super
79
81
  if respond_to?("changed_#{name}")
@@ -90,16 +92,16 @@ module AWS
90
92
  end
91
93
 
92
94
  def deep_copy(hash = self)
93
- hash.inject(hash.class.new) do |copy,(key,value)|
95
+ fields = hash.inject({}) do |copy,(key,value)|
94
96
  if value.is_a?(CustomizationContext)
95
- copy[key] = value.deep_copy
97
+ value = value.deep_copy
96
98
  elsif value.is_a?(Hash)
97
- copy[key] = deep_copy(value)
98
- else
99
- copy[key] = value
99
+ value = deep_copy(value)
100
100
  end
101
+ copy[key] = value
101
102
  copy
102
103
  end
104
+ hash.merge(fields)
103
105
  end
104
106
 
105
107
  private
metadata CHANGED
@@ -1,67 +1,93 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: aws-sdk
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 17
5
5
  prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 3
10
+ version: 1.0.3
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Amazon Web Services
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2011-07-21 00:00:00.000000000 -07:00
17
+
18
+ date: 2011-07-29 00:00:00 -07:00
13
19
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: uuidtools
17
- requirement: &2155405840 !ruby/object:Gem::Requirement
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
18
24
  none: false
19
- requirements:
25
+ requirements:
20
26
  - - ~>
21
- - !ruby/object:Gem::Version
22
- version: '2.1'
27
+ - !ruby/object:Gem::Version
28
+ hash: 1
29
+ segments:
30
+ - 2
31
+ - 1
32
+ version: "2.1"
23
33
  type: :runtime
34
+ name: uuidtools
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
24
37
  prerelease: false
25
- version_requirements: *2155405840
26
- - !ruby/object:Gem::Dependency
27
- name: httparty
28
- requirement: &2155405080 !ruby/object:Gem::Requirement
38
+ requirement: &id002 !ruby/object:Gem::Requirement
29
39
  none: false
30
- requirements:
40
+ requirements:
31
41
  - - ~>
32
- - !ruby/object:Gem::Version
33
- version: '0.7'
42
+ - !ruby/object:Gem::Version
43
+ hash: 5
44
+ segments:
45
+ - 0
46
+ - 7
47
+ version: "0.7"
34
48
  type: :runtime
49
+ name: httparty
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
35
52
  prerelease: false
36
- version_requirements: *2155405080
37
- - !ruby/object:Gem::Dependency
38
- name: nokogiri
39
- requirement: &2155394520 !ruby/object:Gem::Requirement
53
+ requirement: &id003 !ruby/object:Gem::Requirement
40
54
  none: false
41
- requirements:
42
- - - ~>
43
- - !ruby/object:Gem::Version
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 15
59
+ segments:
60
+ - 1
61
+ - 4
62
+ - 4
44
63
  version: 1.4.4
45
64
  type: :runtime
65
+ name: nokogiri
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
46
68
  prerelease: false
47
- version_requirements: *2155394520
48
- - !ruby/object:Gem::Dependency
49
- name: json
50
- requirement: &2155393900 !ruby/object:Gem::Requirement
69
+ requirement: &id004 !ruby/object:Gem::Requirement
51
70
  none: false
52
- requirements:
71
+ requirements:
53
72
  - - ~>
54
- - !ruby/object:Gem::Version
55
- version: '1.4'
73
+ - !ruby/object:Gem::Version
74
+ hash: 7
75
+ segments:
76
+ - 1
77
+ - 4
78
+ version: "1.4"
56
79
  type: :runtime
57
- prerelease: false
58
- version_requirements: *2155393900
80
+ name: json
81
+ version_requirements: *id004
59
82
  description: AWS SDK for Ruby
60
83
  email:
61
84
  executables: []
85
+
62
86
  extensions: []
87
+
63
88
  extra_rdoc_files: []
64
- files:
89
+
90
+ files:
65
91
  - ca-bundle.crt
66
92
  - rails/init.rb
67
93
  - lib/aws/api_config.rb
@@ -255,6 +281,7 @@ files:
255
281
  - lib/aws/sqs/received_sns_message.rb
256
282
  - lib/aws/sqs/request.rb
257
283
  - lib/aws/sqs.rb
284
+ - lib/aws/uri_escape.rb
258
285
  - lib/aws/xml_grammar.rb
259
286
  - lib/aws-sdk.rb
260
287
  - lib/aws.rb
@@ -270,31 +297,37 @@ files:
270
297
  - LICENSE.txt
271
298
  has_rdoc: true
272
299
  homepage: http://aws.amazon.com/sdkforruby
273
- licenses:
300
+ licenses:
274
301
  - Apache 2.0
275
302
  post_install_message:
276
303
  rdoc_options: []
277
- require_paths:
304
+
305
+ require_paths:
278
306
  - lib
279
- required_ruby_version: !ruby/object:Gem::Requirement
307
+ required_ruby_version: !ruby/object:Gem::Requirement
280
308
  none: false
281
- requirements:
282
- - - ! '>='
283
- - !ruby/object:Gem::Version
284
- version: '0'
285
- segments:
309
+ requirements:
310
+ - - ">="
311
+ - !ruby/object:Gem::Version
312
+ hash: 3
313
+ segments:
286
314
  - 0
287
- hash: 437793363847079671
288
- required_rubygems_version: !ruby/object:Gem::Requirement
315
+ version: "0"
316
+ required_rubygems_version: !ruby/object:Gem::Requirement
289
317
  none: false
290
- requirements:
291
- - - ! '>='
292
- - !ruby/object:Gem::Version
293
- version: '0'
318
+ requirements:
319
+ - - ">="
320
+ - !ruby/object:Gem::Version
321
+ hash: 3
322
+ segments:
323
+ - 0
324
+ version: "0"
294
325
  requirements: []
326
+
295
327
  rubyforge_project:
296
- rubygems_version: 1.6.1
328
+ rubygems_version: 1.6.2
297
329
  signing_key:
298
330
  specification_version: 3
299
331
  summary: AWS SDK for Ruby
300
332
  test_files: []
333
+