From cfad4ef53fd1a79d165fab0a6b4eebba5cbef0b5 Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Wed, 26 Mar 2014 14:23:27 +0800 Subject: [PATCH 1/2] =?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 2/2] =?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"}