swift_client 0.1.4 → 0.1.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb7d0291c3fcc0d03fd4aa4711c8c7c4a06b46bf
4
- data.tar.gz: 8caa6d7f8e4e21ce1567f7d968e6197fd83760f4
3
+ metadata.gz: f508dc3170899b3d306bf359c0d2df09edf0a694
4
+ data.tar.gz: a2ec9c73c26ca3ba8d7eb4b374d3d6c92acfb7d2
5
5
  SHA512:
6
- metadata.gz: 88d70e38c7d901e1625c03d12e7a9e016f7d26a3687c1ad3282cc7c29847a3cdfc168ce275453cfd69aff8e27a7ece108c25d2438c3e989beae693d8c17688dd
7
- data.tar.gz: eada405a14079e11075ba3a378461c2975da0ef2107609dcf706dca2373da5fde6eea263376873bab01455e38d84d2dd512feacc9a15b84c9395ef55ae0b2bbc
6
+ metadata.gz: 79cdf304996ef393d92c032d0da81ed9cb57c0cb8c17b3262f6854b722140293075202a3b7b6bc1b8d4049d137ab52d1a6dc9ac51504447b1ed44bca7d47d81f
7
+ data.tar.gz: ad166b66f8aa123e6a8ceda6d5acab0125a50034f20347af008cded08b00e4f0b5e35bf660110ae694bb46364f51bdeddc357b481494f21cad76b548d6307b1d
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ .ruby-version
data/README.md CHANGED
@@ -140,6 +140,7 @@ SwiftClient offers the following requests:
140
140
  * put_object(object_name, data_or_io, container_name, headers = {}) -> HTTParty::Response
141
141
  * post_object(object_name, container_name, headers = {}) -> HTTParty::Response
142
142
  * get_object(object_name, container_name) -> HTTParty::Response
143
+ * get_object(object_name, container_name){|chunk| save chunk } -> HTTParty::Response
143
144
  * head_object(object_name, container_name) -> HTTParty::Response
144
145
  * delete_object(object_name, container_name) -> HTTParty::Response
145
146
  * get_objects(container_name, query = {}) -> HTTParty::Response
@@ -148,6 +149,42 @@ SwiftClient offers the following requests:
148
149
  * temp_url(object_name, container_name, options = {}) -> HTTParty::Response
149
150
  * bulk_delete(entries) -> entries
150
151
 
152
+ ### Getting large objects
153
+ The `get_object` method with out a block is suitable for small objects that easily fit in memory. For larger objects, specify a block to process chunked data as it comes in.
154
+
155
+ ```ruby
156
+ File.open("/tmp/output", "wb") do |file_io|
157
+ swift_client.get_object("/large/object", "container") do |chunk|
158
+ file_io.write(chunk)
159
+ end
160
+ end
161
+ ```
162
+
163
+ ## Re-Using/Sharing/Caching Auth Tokens
164
+
165
+ Certain OpenStack/Swift providers have limits in place regarding token
166
+ generation. To re-use auth tokens by caching them via memcached, install dalli
167
+
168
+ `gem install dalli`
169
+
170
+ and provide an instance of Dalli::Client to SwiftClient:
171
+
172
+ ```ruby
173
+ swift_client = SwiftClient.new(
174
+ :auth_url => "https://example.com/auth/v1.0",
175
+ ...
176
+ :cache_store => Dalli::Client.new
177
+ )
178
+ ```
179
+
180
+ The cache key used to store the auth token will include all neccessary details
181
+ to ensure the auth token won't be used for a different swift account erroneously.
182
+
183
+ The cache implementation of SwiftClient is not restricted to memcached. To use
184
+ a different one, simply implement a driver for your favorite cache store. See
185
+ [null_cache.rb](https://github.com/mrkamel/swift_client/blob/master/lib/swift_client/null_cache.rb)
186
+ for more info.
187
+
151
188
  ## bulk_delete
152
189
 
153
190
  Takes an array containing container_name/object_name entries.
data/lib/swift_client.rb CHANGED
@@ -114,10 +114,10 @@ class SwiftClient
114
114
  request :post, "/#{container_name}/#{object_name}", :headers => headers
115
115
  end
116
116
 
117
- def get_object(object_name, container_name)
117
+ def get_object(object_name, container_name, &block)
118
118
  raise(EmptyNameError) if object_name.empty? || container_name.empty?
119
119
 
120
- request :get, "/#{container_name}/#{object_name}"
120
+ request(:get, "/#{container_name}/#{object_name}", block ? { :stream_body => true } : {}, &block)
121
121
  end
122
122
 
123
123
  def head_object(object_name, container_name)
@@ -183,21 +183,21 @@ class SwiftClient
183
183
  headers.keys.detect { |k| k.downcase == key.downcase }
184
184
  end
185
185
 
186
- def request(method, path, opts = {})
186
+ def request(method, path, opts = {}, &block)
187
187
  headers = (opts[:headers] || {}).dup
188
188
  headers["X-Auth-Token"] = auth_token
189
189
  headers["Accept"] = "application/json"
190
190
 
191
191
  stream_pos = opts[:body_stream].pos if opts[:body_stream]
192
192
 
193
- response = HTTParty.send(method, "#{storage_url}#{path}", opts.merge(:headers => headers))
193
+ response = HTTParty.send(method, "#{storage_url}#{path}", opts.merge(:headers => headers), &block)
194
194
 
195
195
  if response.code == 401
196
196
  authenticate
197
197
 
198
198
  opts[:body_stream].pos = stream_pos if opts[:body_stream]
199
199
 
200
- return request(method, path, opts)
200
+ return request(method, path, opts, &block)
201
201
  end
202
202
 
203
203
  raise(ResponseError.new(response.code, response.message)) unless response.success?
@@ -357,4 +357,3 @@ class SwiftClient
357
357
  end
358
358
  end
359
359
  end
360
-
@@ -1,5 +1,4 @@
1
1
 
2
2
  class SwiftClient
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.5"
4
4
  end
5
-
@@ -277,8 +277,18 @@ class SwiftClientTest < MiniTest::Test
277
277
 
278
278
  def test_get_object
279
279
  stub_request(:get, "https://example.com/v1/AUTH_account/container/object").with(:headers => { "Accept" => "application/json", "X-Auth-Token" => "Token" }).to_return(:status => 200, :body => "Body", :headers => {})
280
+ block_res = 0
281
+
282
+ large_body = "Body" * 16384
283
+ stub_request(:get, "https://example.com/v1/AUTH_account/container/large_object").with(:headers => { "Accept" => "application/json", "X-Auth-Token" => "Token" }).to_return(:status => 200, :body => large_body, :headers => {})
280
284
 
281
285
  assert_equal "Body", @swift_client.get_object("object", "container").body
286
+
287
+ @swift_client.get_object("large_object", "container") do |chunk|
288
+ block_res += chunk.length
289
+ end
290
+
291
+ assert_equal block_res, large_body.length
282
292
  end
283
293
 
284
294
  def test_head_object
@@ -340,4 +350,3 @@ class SwiftClientTest < MiniTest::Test
340
350
  assert @swift_client.temp_url("object", "container", :expires_in => 86400) =~ %r{https://example.com/v1/AUTH_account/container/object\?temp_url_sig=[a-f0-9]{40}&temp_url_expires=1086400}
341
351
  end
342
352
  end
343
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swift_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Vetter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-05 00:00:00.000000000 Z
11
+ date: 2016-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty