From 33447b0d5fcaa4b6e16203d74ce226bc854b92ca Mon Sep 17 00:00:00 2001 From: 404 Date: Thu, 2 Aug 2012 13:36:46 +0800 Subject: [PATCH] new uptoken --- lib/qiniu/rs.rb | 3 ++- lib/qiniu/rs/eu.rb | 4 ++-- lib/qiniu/tokens/upload_token.rb | 8 +++++--- spec/qiniu/rs/io_spec.rb | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/qiniu/rs.rb b/lib/qiniu/rs.rb index c3a35bf..1a646ff 100755 --- a/lib/qiniu/rs.rb +++ b/lib/qiniu/rs.rb @@ -203,7 +203,8 @@ module Qiniu #token_obj.scope = opts[:scope] #token_obj.expires_in = opts[:expires_in] #token_obj.callback_url = opts[:callback_url] - #token_obj.return_url = opts[:return_url] + #token_obj.callback_body_type = opts[:callback_body_type] + #token_obj.customer = opts[:customer] token_obj.generate_token end diff --git a/lib/qiniu/rs/eu.rb b/lib/qiniu/rs/eu.rb index cd6b47b..fd437df 100755 --- a/lib/qiniu/rs/eu.rb +++ b/lib/qiniu/rs/eu.rb @@ -7,11 +7,11 @@ module Qiniu include Utils def set_watermark(customer_id, options = {}) - Auth.request Config.settings[:eu_host] + '/set', options.merge({:customer => customer_id}) + Auth.request Config.settings[:eu_host] + '/wmset', options.merge({:customer => customer_id}) end def get_watermark(customer_id) - Auth.request Config.settings[:eu_host] + '/get', {:customer => customer_id} + Auth.request Config.settings[:eu_host] + '/wmget', {:customer => customer_id} end end diff --git a/lib/qiniu/tokens/upload_token.rb b/lib/qiniu/tokens/upload_token.rb index 679cedb..0542762 100755 --- a/lib/qiniu/tokens/upload_token.rb +++ b/lib/qiniu/tokens/upload_token.rb @@ -10,19 +10,21 @@ module Qiniu include Utils - attr_accessor :scope, :expires_in, :callback_url, :return_url + attr_accessor :scope, :expires_in, :callback_url, :callback_body_type, :customer def initialize(opts = {}) @scope = opts[:scope] @expires_in = opts[:expires_in] @callback_url = opts[:callback_url] - @return_url = opts[:return_url] + @callback_body_type = opts[:callback_body_type] + @customer = opts[:customer] end def generate_signature params = {:scope => @scope, :deadline => Time.now.to_i + @expires_in} params[:callbackUrl] = @callback_url if !@callback_url.nil? && !@callback_url.empty? - params[:returnUrl] = @return_url if !@return_url.nil? && !@return_url.empty? + params[:callbackBodyType] = @callback_body_type if !@callback_body_type.nil? && !@callback_body_type.empty? + params[:customer] = @customer if !@customer.nil? && !@customer.empty? urlsafe_base64_encode(params.to_json) end diff --git a/spec/qiniu/rs/io_spec.rb b/spec/qiniu/rs/io_spec.rb index 7186f6b..9d8f558 100755 --- a/spec/qiniu/rs/io_spec.rb +++ b/spec/qiniu/rs/io_spec.rb @@ -46,7 +46,7 @@ module Qiniu context ".upload_with_token" do it "should works" do - upopts = {:scope => @bucket, :expires_in => 3600} + upopts = {:scope => @bucket, :expires_in => 3600, :customer => 1} uptoken = Qiniu::RS.generate_upload_token(upopts) code, data = Qiniu::RS::IO.upload_with_token(uptoken, __FILE__, @bucket, @key, nil, nil, nil, true) code.should == 200