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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 738f6e2f37dce25baa6d1248a067ffe24a662013
4
- data.tar.gz: d365944c476e8d06ac8adeddc07062f930a04399
3
+ metadata.gz: 5596d9154862c1102046dd3cac33020070a91e83
4
+ data.tar.gz: d1ded4e96c6c6801c03669b36bc9af3537117f9d
5
5
  SHA512:
6
- metadata.gz: e321145e101f53bcaa5b015b18b00a52c62314846975d1c58ab80c55509914de5daee41e67982c4b4562e347bb2c04bb6cc298e7858a21f3a71a380a63f47c57
7
- data.tar.gz: 3a6431995f5c25882de1efa5a7811c336a8061634555c9f6f3f06a349035206ef38a6554c106a51bda62d92c83a462fc2508c93a530bbcf12bda4f8ce5a305bd
6
+ metadata.gz: bd6edda1a3439dedc17f90a37efbe5bbcef3ba0bce78f95b2b8723d7995657907d7d81915ffa818be7bc712fefe9c64ca236a90d21e6fa0b7cca3194acc726d1
7
+ data.tar.gz: e5a767302fde08420437e3f39ea8bde7c1853b2d06715cc487617e19f2985a4002b8a1a4ebeca4352d2c2baae810ebaaad1a3bd607f3bc09ee8b02f4670c773b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- s3 (0.3.14)
4
+ s3 (0.3.15)
5
5
  proxies (~> 0.2.0)
6
6
 
7
7
  GEM
@@ -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)
@@ -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
- response = http(host).start do |http|
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
- end
196
-
197
- if response.code.to_i == 307
198
- if response.body
199
- doc = Document.new response.body
200
- send_request(doc.elements["Error"].elements["Endpoint"].text, request, true)
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
 
@@ -187,8 +187,9 @@ module S3
187
187
  end
188
188
 
189
189
  def get_object(options = {}, &block)
190
- response = object_request(:get, options)
191
- parse_headers(response, &block)
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)
@@ -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
@@ -1,3 +1,3 @@
1
1
  module S3
2
- VERSION = "0.3.14"
2
+ VERSION = "0.3.15"
3
3
  end
@@ -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(:start).returns(@response_ok)
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(:start).returns(@response_not_found)
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(:start).returns(@response_error)
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(:start).returns(@response_temporary_redirect)
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
@@ -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, {}).returns(@response_binary)
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, {}).returns(@response_binary)
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.14
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-29 00:00:00.000000000 Z
11
+ date: 2013-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: proxies