swift_client 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/lib/swift_client.rb CHANGED
@@ -4,6 +4,7 @@ require "swift_client/version"
4
4
  require "httparty"
5
5
  require "mime-types"
6
6
  require "openssl"
7
+ require "stringio"
7
8
 
8
9
  class SwiftClient
9
10
  class AuthenticationError < StandardError; end
@@ -91,10 +92,11 @@ class SwiftClient
91
92
 
92
93
  mime_type = MIME::Types.of(object_name).first
93
94
 
94
- extended_headers = headers.dup
95
+ extended_headers = (headers || {}).dup
95
96
  extended_headers["Content-Type"] ||= mime_type.content_type if mime_type
97
+ extended_headers["Transfer-Encoding"] = "chunked"
96
98
 
97
- request :put, "/#{container_name}/#{object_name}", :body => data_or_io.respond_to?(:read) ? data_or_io.read : data_or_io, :headers => extended_headers
99
+ request :put, "/#{container_name}/#{object_name}", :body_stream => data_or_io.respond_to?(:read) ? data_or_io : StringIO.new(data_or_io), :headers => extended_headers
98
100
  end
99
101
 
100
102
  def post_object(object_name, container_name, headers = {})
@@ -152,11 +154,11 @@ class SwiftClient
152
154
  private
153
155
 
154
156
  def request(method, path, opts = {})
155
- opts[:headers] ||= {}
156
- opts[:headers]["X-Auth-Token"] = auth_token
157
- opts[:headers]["Accept"] = "application/json"
157
+ headers = (opts[:headers] || {}).dup
158
+ headers["X-Auth-Token"] = auth_token
159
+ headers["Accept"] = "application/json"
158
160
 
159
- response = HTTParty.send(method, "#{storage_url}#{path}", opts)
161
+ response = HTTParty.send(method, "#{storage_url}#{path}", opts.merge(:headers => headers))
160
162
 
161
163
  if response.code == 401
162
164
  authenticate
@@ -1,5 +1,5 @@
1
1
 
2
2
  class SwiftClient
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
 
@@ -131,13 +131,13 @@ class SwiftClientTest < MiniTest::Test
131
131
  end
132
132
 
133
133
  def test_put_object
134
- stub_request(:put, "https://example.com/v1/AUTH_account/container/object").with(:body => "data", :headers => { "Accept" => "application/json", "X-Auth-Token" => "Token", "X-Object-Meta-Test" => "Test" }).to_return(:status => 201, :body => "", :headers => {})
134
+ stub_request(:put, "https://example.com/v1/AUTH_account/container/object").with(:body => "data", :headers => { "Transfer-Encoding" => "chunked", "Accept" => "application/json", "X-Auth-Token" => "Token", "X-Object-Meta-Test" => "Test" }).to_return(:status => 201, :body => "", :headers => {})
135
135
 
136
136
  assert_equal 201, @swift_client.put_object("object", "data", "container", "X-Object-Meta-Test" => "Test").code
137
137
  end
138
138
 
139
139
  def test_put_object_with_io
140
- stub_request(:put, "https://example.com/v1/AUTH_account/container/object").with(:body => "data", :headers => { "Accept" => "application/json", "X-Auth-Token" => "Token", "X-Object-Meta-Test" => "Test" }).to_return(:status => 201, :body => "", :headers => {})
140
+ stub_request(:put, "https://example.com/v1/AUTH_account/container/object").with(:body => "data", :headers => { "Transfer-Encoding" => "chunked", "Accept" => "application/json", "X-Auth-Token" => "Token", "X-Object-Meta-Test" => "Test" }).to_return(:status => 201, :body => "", :headers => {})
141
141
 
142
142
  assert_equal 201, @swift_client.put_object("object", StringIO.new("data"), "container", "X-Object-Meta-Test" => "Test").code
143
143
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swift_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-09 00:00:00.000000000 Z
12
+ date: 2015-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty