s3 0.3.5 → 0.3.6

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.
@@ -1,12 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- s3 (0.3.5)
4
+ s3 (0.3.6)
5
+ http_connection
5
6
  proxies
6
7
 
7
8
  GEM
8
9
  remote: http://rubygems.org/
9
10
  specs:
11
+ http_connection (1.3.1)
10
12
  mocha (0.9.8)
11
13
  rake
12
14
  proxies (0.2.1)
@@ -18,6 +20,7 @@ PLATFORMS
18
20
 
19
21
  DEPENDENCIES
20
22
  bundler (>= 1.0.0)
23
+ http_connection
21
24
  mocha
22
25
  proxies
23
26
  s3!
@@ -111,6 +111,7 @@ module Paperclip
111
111
  begin
112
112
  log("saving #{path(style)}")
113
113
  object = bucket.objects.build(path(style))
114
+ file.rewind
114
115
  object.content = file.read
115
116
  object.acl = @s3_permissions
116
117
  object.storage_class = @s3_storage_class
data/lib/s3.rb CHANGED
@@ -15,7 +15,6 @@ require "s3/parser"
15
15
  require "s3/bucket"
16
16
  require "s3/connection"
17
17
  require "s3/exceptions"
18
- require "s3/request"
19
18
  require "s3/object"
20
19
  require "s3/service"
21
20
  require "s3/signature"
@@ -57,10 +57,16 @@ module S3
57
57
  end
58
58
  end
59
59
 
60
- # Saves the newly built bucket. Optionally you can pass location
61
- # of the bucket (<tt>:eu</tt> or <tt>:us</tt>)
62
- def save(location = nil)
63
- create_bucket_configuration(location)
60
+ # Saves the newly built bucket.
61
+ #
62
+ # ==== Options
63
+ # * <tt>:location</tt> - location of the bucket
64
+ # (<tt>:eu</tt> or <tt>us</tt>)
65
+ # * Any other options are passed through to
66
+ # Connection#request
67
+ def save(options = {})
68
+ options = {:location => options} unless options.is_a?(Hash)
69
+ create_bucket_configuration(options)
64
70
  true
65
71
  end
66
72
 
@@ -97,13 +103,22 @@ module S3
97
103
  attr_writer :service
98
104
 
99
105
  def location_constraint
100
- response = bucket_request(:get, :params => { :location => nil })
106
+ response = bucket_request(:get, :params => {:location => nil})
101
107
  parse_location_constraint(response.body)
102
108
  end
103
109
 
104
110
  def list_bucket(options = {})
105
111
  response = bucket_request(:get, :params => options)
106
112
  objects_attributes = parse_list_bucket_result(response.body)
113
+
114
+ # If there are more than 1000 objects S3 truncates listing
115
+ # and we need to request another listing for the remaining objects.
116
+ while parse_is_truncated(response.body)
117
+ marker = objects_attributes.last[:key]
118
+ response = bucket_request(:get, :params => options.merge(:marker => marker))
119
+ objects_attributes += parse_list_bucket_result(response.body)
120
+ end
121
+
107
122
  objects_attributes.map { |object_attributes| Object.send(:new, self, object_attributes) }
108
123
  end
109
124
 
@@ -117,9 +132,9 @@ module S3
117
132
  end
118
133
  end
119
134
 
120
- def create_bucket_configuration(location = nil)
121
- location = location.to_s.upcase if location
122
- options = { :headers => {} }
135
+ def create_bucket_configuration(options = {})
136
+ location = options[:location].to_s.upcase if options[:location]
137
+ options[:headers] ||= {}
123
138
  if location and location != "US"
124
139
  options[:body] = "<CreateBucketConfiguration><LocationConstraint>#{location}</LocationConstraint></CreateBucketConfiguration>"
125
140
  options[:headers][:content_type] = "application/xml"
@@ -21,8 +21,6 @@ module S3
21
21
  # * <tt>:proxy</tt> - Hash for Net::HTTP Proxy settings
22
22
  # { :host => "proxy.mydomain.com", :port => "80, :user => "user_a", :password => "secret" }
23
23
  # * <tt>:proxy</tt> - Hash for Net::HTTP Proxy settings
24
- # * <tt>:chunk_size</tt> - Size of a chunk when streaming
25
- # (1048576 (1 MiB) by default)
26
24
  def initialize(options = {})
27
25
  @access_key_id = options.fetch(:access_key_id)
28
26
  @secret_access_key = options.fetch(:secret_access_key)
@@ -30,7 +28,6 @@ module S3
30
28
  @debug = options.fetch(:debug, false)
31
29
  @timeout = options.fetch(:timeout, 60)
32
30
  @proxy = options.fetch(:proxy, nil)
33
- @chunk_size = options.fetch(:chunk_size, 1048576)
34
31
  end
35
32
 
36
33
  # Makes request with given HTTP method, sets missing parameters,
@@ -67,7 +64,7 @@ module S3
67
64
  end
68
65
 
69
66
  path = URI.escape(path)
70
- request = Request.new(@chunk_size, method.to_s.upcase, !!body, true, path)
67
+ request = Net::HTTPGenericRequest.new(method.to_s.upcase, !!body, true, path)
71
68
 
72
69
  headers = self.class.parse_headers(headers)
73
70
  headers.each do |key, value|
@@ -44,5 +44,9 @@ module S3
44
44
  message = document.elements["Error/Message"].text
45
45
  [code, message]
46
46
  end
47
+
48
+ def parse_is_truncated xml
49
+ rexml_document(xml).elements["ListBucketResult/IsTruncated"].text =='true'
50
+ end
47
51
  end
48
52
  end
@@ -22,15 +22,12 @@ module S3
22
22
  # (false by default)
23
23
  # * <tt>:timeout</tt> - Timeout to use by the Net::HTTP object
24
24
  # (60 by default)
25
- # * <tt>:chunk_size</tt> - Size of a chunk when streaming
26
- # (1048576 (1 MiB) by default)
27
25
  def initialize(options)
28
26
  @access_key_id = options.fetch(:access_key_id)
29
27
  @secret_access_key = options.fetch(:secret_access_key)
30
28
  @use_ssl = options.fetch(:use_ssl, false)
31
29
  @timeout = options.fetch(:timeout, 60)
32
30
  @debug = options.fetch(:debug, false)
33
- @chunk_size = options.fetch(:chunk_size, 1048576)
34
31
 
35
32
  raise ArgumentError, "Missing proxy settings. Must specify at least :host." if options[:proxy] && !options[:proxy][:host]
36
33
  @proxy = options.fetch(:proxy, nil)
@@ -39,7 +36,7 @@ module S3
39
36
  # Returns all buckets in the service and caches the result (see
40
37
  # +reload+)
41
38
  def buckets
42
- Proxy.new(lambda { list_all_my_buckets}, :owner => self, :extend => BucketsExtension)
39
+ Proxy.new(lambda { list_all_my_buckets }, :owner => self, :extend => BucketsExtension)
43
40
  end
44
41
 
45
42
  # Returns "http://" or "https://", depends on <tt>:use_ssl</tt>
@@ -77,8 +74,7 @@ module S3
77
74
  :use_ssl => @use_ssl,
78
75
  :timeout => @timeout,
79
76
  :debug => @debug,
80
- :proxy => @proxy,
81
- :chunk_size => @chunk_size)
77
+ :proxy => @proxy)
82
78
  end
83
79
  @connection
84
80
  end
@@ -25,9 +25,7 @@ module S3
25
25
  request = options[:request]
26
26
  access_key_id = options[:access_key_id]
27
27
 
28
- options.merge!(:headers => request,
29
- :method => request.method,
30
- :resource => request.path)
28
+ options.merge!(:headers => request, :method => request.method, :resource => request.path)
31
29
 
32
30
  signature = canonicalized_signature(options)
33
31
 
@@ -1,3 +1,3 @@
1
1
  module S3
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
data/s3.gemspec CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.rubyforge_project = "s3"
17
17
 
18
18
  s.add_dependency "proxies"
19
+ s.add_dependency "http_connection"
19
20
  s.add_development_dependency "test-unit", ">= 2.0"
20
21
  s.add_development_dependency "mocha"
21
22
  s.add_development_dependency "bundler", ">= 1.0.0"
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 3
9
- - 5
10
- version: 0.3.5
8
+ - 6
9
+ version: 0.3.6
11
10
  platform: ruby
12
11
  authors:
13
12
  - "Jakub Ku\xC5\xBAma"
@@ -15,68 +14,77 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-10-05 00:00:00 +02:00
17
+ date: 2010-10-09 00:00:00 +02:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
21
+ name: proxies
22
22
  requirement: &id001 !ruby/object:Gem::Requirement
23
23
  none: false
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- hash: 3
28
27
  segments:
29
28
  - 0
30
29
  version: "0"
31
30
  type: :runtime
32
- name: proxies
33
31
  prerelease: false
34
32
  version_requirements: *id001
35
33
  - !ruby/object:Gem::Dependency
34
+ name: http_connection
36
35
  requirement: &id002 !ruby/object:Gem::Requirement
37
36
  none: false
38
37
  requirements:
39
38
  - - ">="
40
39
  - !ruby/object:Gem::Version
41
- hash: 3
42
40
  segments:
43
- - 2
44
41
  - 0
45
- version: "2.0"
46
- type: :development
47
- name: test-unit
42
+ version: "0"
43
+ type: :runtime
48
44
  prerelease: false
49
45
  version_requirements: *id002
50
46
  - !ruby/object:Gem::Dependency
47
+ name: test-unit
51
48
  requirement: &id003 !ruby/object:Gem::Requirement
52
49
  none: false
53
50
  requirements:
54
51
  - - ">="
55
52
  - !ruby/object:Gem::Version
56
- hash: 3
57
53
  segments:
54
+ - 2
58
55
  - 0
59
- version: "0"
56
+ version: "2.0"
60
57
  type: :development
61
- name: mocha
62
58
  prerelease: false
63
59
  version_requirements: *id003
64
60
  - !ruby/object:Gem::Dependency
61
+ name: mocha
65
62
  requirement: &id004 !ruby/object:Gem::Requirement
66
63
  none: false
67
64
  requirements:
68
65
  - - ">="
69
66
  - !ruby/object:Gem::Version
70
- hash: 23
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: *id004
73
+ - !ruby/object:Gem::Dependency
74
+ name: bundler
75
+ requirement: &id005 !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
71
80
  segments:
72
81
  - 1
73
82
  - 0
74
83
  - 0
75
84
  version: 1.0.0
76
85
  type: :development
77
- name: bundler
78
86
  prerelease: false
79
- version_requirements: *id004
87
+ version_requirements: *id005
80
88
  description: "S3 library provides access to Amazon's Simple Storage Service. It supports both: European and US buckets through REST API."
81
89
  email:
82
90
  - qoobaa@gmail.com
@@ -103,7 +111,6 @@ files:
103
111
  - lib/s3/object.rb
104
112
  - lib/s3/objects_extension.rb
105
113
  - lib/s3/parser.rb
106
- - lib/s3/request.rb
107
114
  - lib/s3/service.rb
108
115
  - lib/s3/signature.rb
109
116
  - lib/s3/version.rb
@@ -128,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
135
  requirements:
129
136
  - - ">="
130
137
  - !ruby/object:Gem::Version
131
- hash: 3
138
+ hash: 4530267442220315944
132
139
  segments:
133
140
  - 0
134
141
  version: "0"
@@ -137,7 +144,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
144
  requirements:
138
145
  - - ">="
139
146
  - !ruby/object:Gem::Version
140
- hash: 23
141
147
  segments:
142
148
  - 1
143
149
  - 3
@@ -1,31 +0,0 @@
1
- module S3
2
- # Class responsible for sending chunked requests
3
- # properly. Net::HTTPGenericRequest has hardcoded chunk_size, so we
4
- # inherit the class and override chunk_size.
5
- class Request < Net::HTTPGenericRequest
6
- def initialize(chunk_size, m, reqbody, resbody, path, initheader = nil)
7
- @chunk_size = chunk_size
8
- super(m, reqbody, resbody, path, initheader)
9
- end
10
-
11
- private
12
-
13
- def send_request_with_body_stream(sock, ver, path, f)
14
- unless content_length() or chunked?
15
- raise ArgumentError, "Content-Length not given and Transfer-Encoding is not `chunked'"
16
- end
17
- supply_default_content_type
18
- write_header sock, ver, path
19
- if chunked?
20
- while s = f.read(@chunk_size)
21
- sock.write(sprintf("%x\r\n", s.length) << s << "\r\n")
22
- end
23
- sock.write "0\r\n\r\n"
24
- else
25
- while s = f.read(@chunk_size)
26
- sock.write s
27
- end
28
- end
29
- end
30
- end
31
- end