From c49ea097b891926546d80163da2e7ab05df33e4a Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Mon, 24 Mar 2014 16:04:38 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E4=BB=A4http=5Frequest()=E8=BE=93?= =?UTF-8?q?=E5=87=BAHTTP=20Response=20Headers=EF=BC=8C=E5=B9=B6=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E6=89=80=E6=9C=89=E7=9A=84=E4=B8=8A=E4=BC=A0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/qiniu/auth.rb | 14 +++---- lib/qiniu/utils.rb | 8 ++-- spec/qiniu/upload_spec.rb | 78 +++++++++++++++++++++++++++++++++------ 3 files changed, 79 insertions(+), 21 deletions(-) diff --git a/lib/qiniu/auth.rb b/lib/qiniu/auth.rb index 867e4a3..1d3075c 100755 --- a/lib/qiniu/auth.rb +++ b/lib/qiniu/auth.rb @@ -10,16 +10,16 @@ module Qiniu include Utils def call_with_signature(url, data, retry_times = 0, options = {}) - code, data = http_request url, data, options.merge({:qbox_signature_token => generate_qbox_signature(url, data, options[:mime])}) - [code, data] - end + code, data, raw_headers = http_request url, data, options.merge({:qbox_signature_token => generate_qbox_signature(url, data, options[:mime])}) + [code, data, raw_headers] + end # call_with_signature def request(url, data = nil, options = {}) - code, data = Auth.call_with_signature(url, data, 0, options) - [code, data] - end + code, data, raw_headers = Auth.call_with_signature(url, data, 0, options) + [code, data, raw_headers] + end # request - end + end # class << self end # module Auth end # module Qiniu diff --git a/lib/qiniu/utils.rb b/lib/qiniu/utils.rb index ba7a4d8..8e1d252 100755 --- a/lib/qiniu/utils.rb +++ b/lib/qiniu/utils.rb @@ -75,9 +75,10 @@ module Qiniu data = {} body = response.respond_to?(:body) ? response.body : {} data = safe_json_parse(body) unless body.empty? + raw_headers = response.raw_headers end - [code, data] - end + [code, data, raw_headers] + end # send_request_with def http_request url, data = nil, options = {} retry_times = 0 @@ -100,8 +101,9 @@ module Qiniu code = res.code.to_i if res.respond_to? :code body = res.respond_to?(:body) ? res.body : "" data = safe_json_parse(body) unless body.empty? + raw_headers = response.raw_headers end - [code, data] + [code, data, raw_headers] end end diff --git a/spec/qiniu/upload_spec.rb b/spec/qiniu/upload_spec.rb index 895d54a..7c886c4 100755 --- a/spec/qiniu/upload_spec.rb +++ b/spec/qiniu/upload_spec.rb @@ -19,26 +19,31 @@ module Qiniu @key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s) @key = make_unique_key_in_bucket(@key) + puts "key=#{@key}" @localfile_5m = "5M.txt" File.open(@localfile_5m, "w"){|f| 5242888.times{ f.write(rand(9).to_s) }} @key_5m = Digest::SHA1.hexdigest(@localfile_5m+Time.now.to_s) @key_5m = make_unique_key_in_bucket(@key_5m) + puts "key_5m=#{@key_5m}" @localfile_4m = "4M.txt" File.open(@localfile_4m, "w"){|f| (1 << 22).times{ f.write(rand(9).to_s) }} @key_4m = Digest::SHA1.hexdigest(@localfile_4m+Time.now.to_s) @key_4m = make_unique_key_in_bucket(@key_4m) + puts "key_4m=#{@key_4m}" @localfile_8m = "8M.txt" File.open(@localfile_8m, "w"){|f| (1 << 23).times{ f.write(rand(9).to_s) }} @key_8m = Digest::SHA1.hexdigest(@localfile_8m+Time.now.to_s) @key_8m = make_unique_key_in_bucket(@key_8m) + puts "key_8m=#{@key_8m}" @localfile_1m = "1M.txt" File.open(@localfile_1m, "w"){|f| (1 << 20).times{ f.write(rand(9).to_s) }} @key_1m = Digest::SHA1.hexdigest(@localfile_1m+Time.now.to_s) @key_1m = make_unique_key_in_bucket(@key_1m) + puts "key_1m=#{@key_1m}" end after :all do @@ -54,9 +59,17 @@ module Qiniu ### 测试单文件直传 context ".put_file" do it "should works" do - code, data = Qiniu::Storage.put_file(__FILE__, @bucket, @key, 'application/x-ruby', 'customMeta', true) + code, data, raw_headers = Qiniu::Storage.put_file( + __FILE__, + @bucket, + @key, + 'application/x-ruby', + 'customMeta', + true, + ) code.should == 200 puts data.inspect + puts raw_headers.inspect end end @@ -80,9 +93,19 @@ module Qiniu it "should works" do upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"} uptoken = Qiniu.generate_upload_token(upopts) - code, data = Qiniu::Storage.upload_with_token(uptoken, __FILE__, @bucket, @key, nil, nil, nil, true) + code, data, raw_headers = Qiniu::Storage.upload_with_token( + uptoken, + __FILE__, + @bucket, + @key, + nil, + nil, + nil, + true, + ) code.should == 200 puts data.inspect + puts raw_headers.inspect end end @@ -107,10 +130,15 @@ module Qiniu upopts = {:scope => @bucket, :expires_in => 3600, :endUser => "why404@gmail.com"} uptoken = Qiniu.generate_upload_token(upopts) - code, data = Qiniu::Storage.upload_with_token_2(uptoken, __FILE__, @key) + code, data, raw_headers = Qiniu::Storage.upload_with_token_2( + uptoken, + __FILE__, + @key, + ) code.should == 200 puts data.inspect + puts raw_headers.inspect end end # .upload_with_token_2 @@ -135,9 +163,16 @@ module Qiniu it "should works" do upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"} uptoken = Qiniu.generate_upload_token(upopts) - code, data = Qiniu::Storage.resumable_upload_with_token(uptoken, @localfile_5m, @bucket, @key_5m) - puts data.inspect + code, data, raw_headers = Qiniu::Storage.resumable_upload_with_token( + uptoken, + @localfile_5m, + @bucket, + @key_5m, + ) (code/100).should == 2 + puts data.inspect + puts raw_headers.inspect + puts "key_5m=#{@key_5m}" end end @@ -161,9 +196,16 @@ module Qiniu it "should works" do upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"} uptoken = Qiniu.generate_upload_token(upopts) - code, data = Qiniu::Storage.resumable_upload_with_token(uptoken, @localfile_4m, @bucket, @key_4m) - puts data.inspect + code, data, raw_headers = Qiniu::Storage.resumable_upload_with_token( + uptoken, + @localfile_4m, + @bucket, + @key_4m, + ) (code/100).should == 2 + puts data.inspect + puts raw_headers.inspect + puts "key_4m=#{@key_4m}" end end @@ -187,9 +229,16 @@ module Qiniu it "should works" do upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"} uptoken = Qiniu.generate_upload_token(upopts) - code, data = Qiniu::Storage.resumable_upload_with_token(uptoken, @localfile_8m, @bucket, @key_8m) - puts data.inspect + code, data, raw_headers = Qiniu::Storage.resumable_upload_with_token( + uptoken, + @localfile_8m, + @bucket, + @key_8m, + ) (code/100).should == 2 + puts data.inspect + puts raw_headers.inspect + puts "key_8m=#{@key_8m}" end end @@ -213,9 +262,16 @@ module Qiniu it "should works" do upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"} uptoken = Qiniu.generate_upload_token(upopts) - code, data = Qiniu::Storage.resumable_upload_with_token(uptoken, @localfile_1m, @bucket, @key_1m) - puts data.inspect + code, data, raw_headers = Qiniu::Storage.resumable_upload_with_token( + uptoken, + @localfile_1m, + @bucket, + @key_1m, + ) (code/100).should == 2 + puts data.inspect + puts raw_headers.inspect + puts "key_1m=#{@key_1m}" end end From 9374a451cdbbe8b4de85534821c18a1428c3511a Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Mon, 24 Mar 2014 18:26:56 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=97=A0=E6=84=8F?= =?UTF-8?q?=E4=B8=AD=E6=B7=BB=E5=8A=A0=E7=9A=84=E5=A4=9A=E4=BD=99=E9=80=97?= =?UTF-8?q?=E5=8F=B7=EF=BC=8C=E4=BF=9D=E8=AF=81=E5=90=91=E4=B8=8B=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/qiniu/upload_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/qiniu/upload_spec.rb b/spec/qiniu/upload_spec.rb index 7c886c4..f06e81d 100755 --- a/spec/qiniu/upload_spec.rb +++ b/spec/qiniu/upload_spec.rb @@ -65,7 +65,7 @@ module Qiniu @key, 'application/x-ruby', 'customMeta', - true, + true ) code.should == 200 puts data.inspect @@ -101,7 +101,7 @@ module Qiniu nil, nil, nil, - true, + true ) code.should == 200 puts data.inspect @@ -133,7 +133,7 @@ module Qiniu code, data, raw_headers = Qiniu::Storage.upload_with_token_2( uptoken, __FILE__, - @key, + @key ) code.should == 200 @@ -167,7 +167,7 @@ module Qiniu uptoken, @localfile_5m, @bucket, - @key_5m, + @key_5m ) (code/100).should == 2 puts data.inspect @@ -200,7 +200,7 @@ module Qiniu uptoken, @localfile_4m, @bucket, - @key_4m, + @key_4m ) (code/100).should == 2 puts data.inspect @@ -233,7 +233,7 @@ module Qiniu uptoken, @localfile_8m, @bucket, - @key_8m, + @key_8m ) (code/100).should == 2 puts data.inspect @@ -266,7 +266,7 @@ module Qiniu uptoken, @localfile_1m, @bucket, - @key_1m, + @key_1m ) (code/100).should == 2 puts data.inspect From 27eb25fc1115818cbec48eec6330b434987dbd95 Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Mon, 24 Mar 2014 18:34:29 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E4=B8=BAsend=5Frequest=5Fwith=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=9A=84HTTP=20Response=20Header=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=AF=B9=E6=AF=94=E6=95=B0=E6=8D=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/qiniu/utils_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/qiniu/utils_spec.rb b/spec/qiniu/utils_spec.rb index fb00074..5ef8625 100755 --- a/spec/qiniu/utils_spec.rb +++ b/spec/qiniu/utils_spec.rb @@ -28,7 +28,7 @@ module Qiniu FakeWeb.allow_net_connect = false FakeWeb.register_uri(:get, "http://docs.qiniutek.com/", :body => {:abc => 123}.to_json) res = Utils.send_request_with 'http://docs.qiniutek.com/', nil, :method => :get - res.should == [200, {"abc" => 123}] + res.should == [200, {"abc" => 123}, {}] end [400, 500].each do |code| From bcb8ad7392c73268132aa0569bd5f2b5da0fa0fd Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Tue, 25 Mar 2014 15:30:05 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=AF=B4=E6=98=8E=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 8 ++++++++ Gemfile.lock | 8 ++++---- lib/qiniu/version.rb | 2 +- qiniu.gemspec | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5568daa..f4a3547 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ ## CHANGE LOG +### v6.0.2 + +- Qiniu::Storage所有上传接口返回第三个值raw_headers,类型为Hash,包含已解析的HTTP响应报文中的所有Header信息。 + +该返回值主要用于调试。当遇到难以理解或解释的错误时,请将其中的X-Log和X-Reqid两项信息[通过邮件反馈](mailto:support@qiniu.com?subject=Ruby-SDK-Bug-Report)给我们。 + +- 更新Qiniu::Storage所有上传接口的测试用例,打印HTTP响应Header信息。 + ### v6.0.1 - 重新划分命名空间,存储相关归入Qiniu::Storage,数据处理相关归入Qiniu::Fop,杂项相关归入Qiniu::Misc。 diff --git a/Gemfile.lock b/Gemfile.lock index dddcc76..d6f7059 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,9 +1,9 @@ PATH remote: . specs: - qiniu (6.0.1) + qiniu (6.0.2) json (~> 1.7) - mime-types (~> 1.19) + mime-types (~> 2.2) rest-client (~> 1.6) ruby-hmac (~> 0.4) @@ -12,8 +12,8 @@ GEM specs: diff-lcs (1.1.3) fakeweb (1.3.0) - json (1.7.7) - mime-types (1.23) + json (1.8.1) + mime-types (2.2) rake (10.0.3) rest-client (1.6.7) mime-types (>= 1.16) diff --git a/lib/qiniu/version.rb b/lib/qiniu/version.rb index 8d779d8..2781dac 100755 --- a/lib/qiniu/version.rb +++ b/lib/qiniu/version.rb @@ -4,7 +4,7 @@ module Qiniu module Version MAJOR = 6 MINOR = 0 - PATCH = 1 + PATCH = 2 # Returns a version string by joining MAJOR, MINOR, and PATCH with '.' # # Example diff --git a/qiniu.gemspec b/qiniu.gemspec index 6e5e0a5..c437c42 100755 --- a/qiniu.gemspec +++ b/qiniu.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |gem| gem.add_development_dependency "fakeweb", "~> 1.3" gem.add_runtime_dependency "json", "~> 1.7" gem.add_runtime_dependency "rest-client", "~> 1.6" - gem.add_runtime_dependency "mime-types", "~> 1.19" + gem.add_runtime_dependency "mime-types", "~> 2.2" gem.add_runtime_dependency "ruby-hmac", "~> 0.4" gem.add_runtime_dependency "jruby-openssl", "~> 0.7" if RUBY_PLATFORM == "java" end From 8173b31b18f4f739f6e16cef582849b1fc8fd3c9 Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Tue, 25 Mar 2014 15:43:47 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E7=9A=84Badge=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ce900e..c65d8d5 100755 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ ## 状态 集成测试:[![Build Status](https://api.travis-ci.org/qiniu/ruby-sdk.png?branch=master)](https://travis-ci.org/qiniu/ruby-sdk) -版本:[![Gem Version](https://badge.fury.io/rb/qiniu-rs.png)](http://badge.fury.io/rb/qiniu-rs) +版本:[![Gem Version](https://badge.fury.io/rb/qiniu.png)](http://badge.fury.io/rb/qiniu) ## 安装 From 8ffee735245deaff6e39a43b86768352a3068a11 Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Tue, 25 Mar 2014 16:14:56 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E4=BE=9D=E8=B5=96=E5=9F=BA=E7=BA=BF=E4=B8=BA6.1.0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d6cb1b3..ec00b0d 100755 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ 在您 Ruby 应用程序的 `Gemfile` 文件中,添加如下一行代码: - gem 'qiniu', '~> 6.0.0' + gem 'qiniu', '~> 6.1.0' 然后,在应用程序所在的目录下,可以运行 `bundle` 安装依赖包: From 6aaacbe2e8c9cd482cabb6d9ef033895e775b8f2 Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Wed, 26 Mar 2014 13:24:45 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E5=B0=86mime-types=E7=9A=84=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E6=81=A2=E5=A4=8D=E5=88=B01.19=EF=BC=8C=E9=81=BF?= =?UTF-8?q?=E5=85=8D2.2=E7=89=88=E6=9C=AC=E5=9C=A8Ruby=201.8.7=E4=B8=8B?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=AE=89=E8=A3=85=E5=AF=BC=E8=87=B4=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E4=B8=8D=E9=80=9A=E8=BF=87=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qiniu.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiniu.gemspec b/qiniu.gemspec index c437c42..6e5e0a5 100755 --- a/qiniu.gemspec +++ b/qiniu.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |gem| gem.add_development_dependency "fakeweb", "~> 1.3" gem.add_runtime_dependency "json", "~> 1.7" gem.add_runtime_dependency "rest-client", "~> 1.6" - gem.add_runtime_dependency "mime-types", "~> 2.2" + gem.add_runtime_dependency "mime-types", "~> 1.19" gem.add_runtime_dependency "ruby-hmac", "~> 0.4" gem.add_runtime_dependency "jruby-openssl", "~> 0.7" if RUBY_PLATFORM == "java" end From d9ea68efa839cdc4820f815dbbe6b071b6a5a26a Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Wed, 26 Mar 2014 13:28:50 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E6=9B=B4=E6=96=B0Gemfile.lock=EF=BC=8C?= =?UTF-8?q?=E5=8F=8D=E6=98=A0mime-types=E7=9A=84downgrade=E5=8F=98?= =?UTF-8?q?=E5=8C=96=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index fb29223..e546604 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,7 +3,7 @@ PATH specs: qiniu (6.1.0) json (~> 1.7) - mime-types (~> 2.2) + mime-types (~> 1.19) rest-client (~> 1.6) ruby-hmac (~> 0.4) @@ -13,7 +13,7 @@ GEM diff-lcs (1.1.3) fakeweb (1.3.0) json (1.8.1) - mime-types (2.2) + mime-types (1.23) rake (10.0.3) rest-client (1.6.7) mime-types (>= 1.16) From cfad4ef53fd1a79d165fab0a6b4eebba5cbef0b5 Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Wed, 26 Mar 2014 14:23:27 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=98=B2=E5=BE=A1?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=EF=BC=8C=E5=AF=B9=E4=BA=8E=E4=B8=8D=E5=93=8D?= =?UTF-8?q?=E5=BA=94raw=5Fheaders=E6=96=B9=E6=B3=95=E7=9A=84=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=EF=BC=8C=E7=9B=B4=E6=8E=A5=E8=BF=94=E5=9B=9E=E7=A9=BA?= =?UTF-8?q?Hash=EF=BC=8C=E9=81=BF=E5=85=8D=E6=8A=9B=E5=87=BA=E6=84=8F?= =?UTF-8?q?=E6=96=99=E4=B9=8B=E5=A4=96=E7=9A=84=E5=BC=82=E5=B8=B8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/qiniu/utils.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/qiniu/utils.rb b/lib/qiniu/utils.rb index 8e1d252..3dd3005 100755 --- a/lib/qiniu/utils.rb +++ b/lib/qiniu/utils.rb @@ -74,8 +74,8 @@ module Qiniu else data = {} body = response.respond_to?(:body) ? response.body : {} + raw_headers = response.respond_to?(:raw_headers) ? response.raw_headers : {} data = safe_json_parse(body) unless body.empty? - raw_headers = response.raw_headers end [code, data, raw_headers] end # send_request_with @@ -100,8 +100,8 @@ module Qiniu res = e.response code = res.code.to_i if res.respond_to? :code body = res.respond_to?(:body) ? res.body : "" + raw_headers = res.respond_to?(:raw_headers) ? res.raw_headers : {} data = safe_json_parse(body) unless body.empty? - raw_headers = response.raw_headers end [code, data, raw_headers] end From bc1b8acea5ba42a7d3f41cb171b7dca36f58e1bd Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Wed, 26 Mar 2014 17:07:34 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=BF=87=E6=97=B6?= =?UTF-8?q?=E7=9A=84Qiniu::Storage.put=5Ffile=E6=96=B9=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++++ lib/qiniu.rb | 10 ---------- lib/qiniu/config.rb | 1 - lib/qiniu/upload.rb | 21 --------------------- spec/qiniu/management_spec.rb | 11 +++++++++-- spec/qiniu/qiniu_spec.rb | 11 ----------- spec/qiniu/upload_spec.rb | 32 -------------------------------- 7 files changed, 13 insertions(+), 77 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb274d6..41a0446 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ - 更新Qiniu::Storage所有上传接口的测试用例,打印HTTP响应Header信息。 +- 删除过时的Qiniu::Storage#put_file方法和相关测试用例。 + +该方法调用的API已过时并逐步废弃,建议用户尽快迁移到Qiniu::Storage#upload_with_token_2方法上。 + ### v6.0.1 - 重新划分命名空间,存储相关归入Qiniu::Storage,数据处理相关归入Qiniu::Fop,杂项相关归入Qiniu::Misc。 diff --git a/lib/qiniu.rb b/lib/qiniu.rb index 49c3658..337b78a 100755 --- a/lib/qiniu.rb +++ b/lib/qiniu.rb @@ -54,16 +54,6 @@ module Qiniu code == StatusOK end - def put_file opts = {} - code, data = Storage.put_file(opts[:file], - opts[:bucket], - opts[:key], - opts[:mime_type], - opts[:note], - opts[:enable_crc32_check]) - code == StatusOK - end - def upload_file opts = {} uncontained_opts = [:uptoken, :file, :bucket, :key] - opts.keys raise MissingArgsError, uncontained_opts unless uncontained_opts.empty? diff --git a/lib/qiniu/config.rb b/lib/qiniu/config.rb index 53216c3..7f230e4 100755 --- a/lib/qiniu/config.rb +++ b/lib/qiniu/config.rb @@ -20,7 +20,6 @@ module Qiniu :content_type => 'application/x-www-form-urlencoded', :auth_url => "https://acc.qbox.me/oauth2/token", :rs_host => "http://rs.qiniu.com", - :io_host => "http://iovip.qbox.me", :up_host => "http://up.qiniu.com", :pub_host => "http://pu.qbox.me:10200", :eu_host => "http://eu.qbox.me", diff --git a/lib/qiniu/upload.rb b/lib/qiniu/upload.rb index 73f9d98..faede91 100755 --- a/lib/qiniu/upload.rb +++ b/lib/qiniu/upload.rb @@ -5,27 +5,6 @@ module Qiniu class << self include Utils - def put_file(local_file, - bucket, - key = nil, - mime_type = nil, - custom_meta = nil, - enable_crc32_check = false) - action_params = _generate_action_params( - local_file, - bucket, - key, - mime_type, - custom_meta, - enable_crc32_check - ) - - url = Config.settings[:io_host] + action_params - options = {:content_type => 'application/octet-stream'} - - Auth.request url, ::IO.read(local_file), options - end # put_file - def upload_with_token(uptoken, local_file, bucket, diff --git a/spec/qiniu/management_spec.rb b/spec/qiniu/management_spec.rb index 34ab775..7023cc0 100755 --- a/spec/qiniu/management_spec.rb +++ b/spec/qiniu/management_spec.rb @@ -29,9 +29,16 @@ module Qiniu end ### 准备数据 - context ".put_file" do + context ".upload_with_token_2" do it "should works" do - code, data = Storage.put_file(__FILE__, @bucket, @key, 'application/x-ruby', 'customMeta', true) + upopts = {:scope => @bucket, :expires_in => 3600, :endUser => "why404@gmail.com"} + uptoken = Qiniu.generate_upload_token(upopts) + + code, data, raw_headers = Qiniu::Storage.upload_with_token_2( + uptoken, + __FILE__, + @key + ) code.should == 200 puts data.inspect end diff --git a/spec/qiniu/qiniu_spec.rb b/spec/qiniu/qiniu_spec.rb index 86a014e..1136432 100755 --- a/spec/qiniu/qiniu_spec.rb +++ b/spec/qiniu/qiniu_spec.rb @@ -37,17 +37,6 @@ module Qiniu ### 不删除Bucket以备下次使用 end - context ".put_file" do - it "should works" do - result = Qiniu.put_file :file => __FILE__, - :bucket => @bucket, - :key => @key, - :mime_type => 'application/x-ruby', - :enable_crc32_check => true - result.should be_true - end - end - context ".buckets" do it "should works" do result = Qiniu.buckets diff --git a/spec/qiniu/upload_spec.rb b/spec/qiniu/upload_spec.rb index f06e81d..e344c21 100755 --- a/spec/qiniu/upload_spec.rb +++ b/spec/qiniu/upload_spec.rb @@ -57,38 +57,6 @@ module Qiniu end ### 测试单文件直传 - context ".put_file" do - it "should works" do - code, data, raw_headers = Qiniu::Storage.put_file( - __FILE__, - @bucket, - @key, - 'application/x-ruby', - 'customMeta', - true - ) - code.should == 200 - puts data.inspect - puts raw_headers.inspect - end - end - - context ".stat" do - it "should exists" do - code, data = Qiniu::Storage.stat(@bucket, @key) - puts data.inspect - code.should == 200 - end - end - - context ".delete" do - it "should works" do - code, data = Qiniu::Storage.delete(@bucket, @key) - puts data.inspect - code.should == 200 - end - end - context ".upload_with_token" do it "should works" do upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}