s3 0.3.14 → 0.3.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/s3/bucket.rb +2 -2
- data/lib/s3/connection.rb +15 -13
- data/lib/s3/object.rb +5 -4
- data/lib/s3/service.rb +2 -2
- data/lib/s3/version.rb +1 -1
- data/test/connection_test.rb +5 -5
- data/test/object_test.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5596d9154862c1102046dd3cac33020070a91e83
|
4
|
+
data.tar.gz: d1ded4e96c6c6801c03669b36bc9af3537117f9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd6edda1a3439dedc17f90a37efbe5bbcef3ba0bce78f95b2b8723d7995657907d7d81915ffa818be7bc712fefe9c64ca236a90d21e6fa0b7cca3194acc726d1
|
7
|
+
data.tar.gz: e5a767302fde08420437e3f39ea8bde7c1853b2d06715cc487617e19f2985a4002b8a1a4ebeca4352d2c2baae810ebaaad1a3bd607f3bc09ee8b02f4670c773b
|
data/Gemfile.lock
CHANGED
data/lib/s3/bucket.rb
CHANGED
@@ -200,9 +200,9 @@ module S3
|
|
200
200
|
@name = name
|
201
201
|
end
|
202
202
|
|
203
|
-
def bucket_request(method, options = {})
|
203
|
+
def bucket_request(method, options = {}, &block)
|
204
204
|
path = "#{path_prefix}#{options[:path]}"
|
205
|
-
service_request(method, options.merge(:host => host, :path => path))
|
205
|
+
service_request(method, options.merge(:host => host, :path => path), &block)
|
206
206
|
end
|
207
207
|
|
208
208
|
def name_valid?(name)
|
data/lib/s3/connection.rb
CHANGED
@@ -53,7 +53,7 @@ module S3
|
|
53
53
|
#
|
54
54
|
# ==== Returns
|
55
55
|
# Net::HTTPResponse object -- response from the server
|
56
|
-
def request(method, options)
|
56
|
+
def request(method, options, &block)
|
57
57
|
host = options.fetch(:host, HOST)
|
58
58
|
path = options.fetch(:path)
|
59
59
|
body = options.fetch(:body, nil)
|
@@ -85,7 +85,7 @@ module S3
|
|
85
85
|
request.content_length = body.respond_to?(:lstat) ? body.stat.size : body.size
|
86
86
|
end
|
87
87
|
|
88
|
-
send_request(host, request)
|
88
|
+
send_request(host, request, &block)
|
89
89
|
end
|
90
90
|
|
91
91
|
# Helper function to parser parameters and create single string of
|
@@ -173,8 +173,8 @@ module S3
|
|
173
173
|
http
|
174
174
|
end
|
175
175
|
|
176
|
-
def send_request(host, request, skip_authorization = false)
|
177
|
-
|
176
|
+
def send_request(host, request, skip_authorization = false, &block)
|
177
|
+
http(host).start do |http|
|
178
178
|
host = http.address
|
179
179
|
|
180
180
|
request["Date"] ||= Time.now.httpdate
|
@@ -191,16 +191,18 @@ module S3
|
|
191
191
|
:secret_access_key => secret_access_key)
|
192
192
|
end
|
193
193
|
|
194
|
-
http.request(request)
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
194
|
+
http.request(request) do |response|
|
195
|
+
if response.code.to_i == 307
|
196
|
+
if response.body
|
197
|
+
doc = Document.new response.body
|
198
|
+
return send_request(doc.elements["Error"].elements["Endpoint"].text, request, true, &block)
|
199
|
+
end
|
200
|
+
else
|
201
|
+
result = handle_response(response)
|
202
|
+
yield result unless block.nil?
|
203
|
+
return result
|
204
|
+
end
|
201
205
|
end
|
202
|
-
else
|
203
|
-
handle_response(response)
|
204
206
|
end
|
205
207
|
end
|
206
208
|
|
data/lib/s3/object.rb
CHANGED
@@ -187,8 +187,9 @@ module S3
|
|
187
187
|
end
|
188
188
|
|
189
189
|
def get_object(options = {}, &block)
|
190
|
-
|
191
|
-
|
190
|
+
object_request(:get, options) do |response|
|
191
|
+
parse_headers(response, &block)
|
192
|
+
end
|
192
193
|
end
|
193
194
|
|
194
195
|
def object_headers(options = {})
|
@@ -220,8 +221,8 @@ module S3
|
|
220
221
|
self.cache_control = options[:cache_control]
|
221
222
|
end
|
222
223
|
|
223
|
-
def object_request(method, options = {})
|
224
|
-
bucket_request(method, options.merge(:path => key))
|
224
|
+
def object_request(method, options = {}, &block)
|
225
|
+
bucket_request(method, options.merge(:path => key), &block)
|
225
226
|
end
|
226
227
|
|
227
228
|
def last_modified=(last_modified)
|
data/lib/s3/service.rb
CHANGED
@@ -70,8 +70,8 @@ module S3
|
|
70
70
|
names.map { |name| Bucket.send(:new, self, name) }
|
71
71
|
end
|
72
72
|
|
73
|
-
def service_request(method, options = {})
|
74
|
-
connection.request(method, options.merge(:path => "/#{options[:path]}"))
|
73
|
+
def service_request(method, options = {}, &block)
|
74
|
+
connection.request(method, options.merge(:path => "/#{options[:path]}"), &block)
|
75
75
|
end
|
76
76
|
|
77
77
|
def connection
|
data/lib/s3/version.rb
CHANGED
data/test/connection_test.rb
CHANGED
@@ -12,8 +12,8 @@ class ConnectionTest < Test::Unit::TestCase
|
|
12
12
|
@response_error = Net::HTTPInternalServerError.new("1.1", "500", "Internal Server Error")
|
13
13
|
@response_temporary_redirect = Net::HTTPInternalServerError.new("1.1", "307", "Temporary Redirect")
|
14
14
|
@connection.stubs(:http).returns(@http_request)
|
15
|
-
|
16
|
-
@http_request.stubs(:
|
15
|
+
@http_request.stubs(:start).yields(@http_request)
|
16
|
+
@http_request.stubs(:request).yields(@response_ok)
|
17
17
|
end
|
18
18
|
|
19
19
|
test "handle response not modify response when ok" do
|
@@ -36,7 +36,7 @@ class ConnectionTest < Test::Unit::TestCase
|
|
36
36
|
</Error>
|
37
37
|
EOFakeBody
|
38
38
|
|
39
|
-
@http_request.stubs(:
|
39
|
+
@http_request.stubs(:request).yields(@response_not_found)
|
40
40
|
@response_not_found.stubs(:body).returns(response_body)
|
41
41
|
|
42
42
|
assert_raise S3::Error::NoSuchBucket do
|
@@ -49,7 +49,7 @@ class ConnectionTest < Test::Unit::TestCase
|
|
49
49
|
end
|
50
50
|
|
51
51
|
test "handle response throws standard exception when error" do
|
52
|
-
@http_request.stubs(:
|
52
|
+
@http_request.stubs(:request).yields(@response_error)
|
53
53
|
@response_error.stubs(:body)
|
54
54
|
assert_raise S3::Error::ResponseError do
|
55
55
|
response = @connection.request(
|
@@ -174,7 +174,7 @@ class ConnectionTest < Test::Unit::TestCase
|
|
174
174
|
end
|
175
175
|
|
176
176
|
test "response.body is nil on TemporaryRedirect" do
|
177
|
-
@http_request.stubs(:
|
177
|
+
@http_request.stubs(:request).yields(@response_temporary_redirect)
|
178
178
|
@response_temporary_redirect.stubs(:body).returns(nil)
|
179
179
|
|
180
180
|
assert_nothing_raised do
|
data/test/object_test.rb
CHANGED
@@ -121,7 +121,7 @@ class ObjectTest < Test::Unit::TestCase
|
|
121
121
|
end
|
122
122
|
|
123
123
|
test "content and parse headers" do
|
124
|
-
@object_lena.expects(:object_request).with(:get, {}).
|
124
|
+
@object_lena.expects(:object_request).with(:get, {}).yields(@response_binary)
|
125
125
|
|
126
126
|
expected = /test/n
|
127
127
|
actual = @object_lena.content(true)
|
@@ -135,7 +135,7 @@ class ObjectTest < Test::Unit::TestCase
|
|
135
135
|
end
|
136
136
|
|
137
137
|
test "streaming" do
|
138
|
-
@object_lena.expects(:object_request).with(:get, {}).
|
138
|
+
@object_lena.expects(:object_request).with(:get, {}).yields(@response_binary)
|
139
139
|
|
140
140
|
expected = /test/n
|
141
141
|
io = StringIO.new
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kuba Kuźma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: proxies
|