new uptoken

This commit is contained in:
404
2012-08-02 13:36:46 +08:00
parent e7f64fabae
commit 33447b0d5f
4 changed files with 10 additions and 7 deletions
+2 -1
View File
@@ -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
+2 -2
View File
@@ -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
+5 -3
View File
@@ -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
+1 -1
View File
@@ -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