Created
December 18, 2013 01:42
-
-
Save ikbear/8016017 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PutPolicy | |
include Utils | |
attr_accessor :scope, :callback_url, :callback_body, :return_url, :return_body, :async_ops, :end_user, :expires, :save_key, :persistent_ops, :persistent_notify_url | |
def initialize(opts = {}) | |
@scope = opts[:scope] | |
@callback_url = opts[:callback_url] | |
@callback_body = opts[:callback_body] | |
@return_url = opts[:return_url] | |
@return_body = opts[:return_body] | |
@async_ops = opts[:async_ops] | |
@end_user = opts[:end_user] | |
@expires = opts[:expires] || 3600 | |
@save_key = opts[:save_key] | |
@persistent_ops = opts[:persistent_ops] | |
@persistent_notify_url = opts[:persistent_notify_url] | |
end | |
def token(mac = nil) | |
if mac.nil? then | |
mac = Qiniu::Auth::Digest::Mac.new() | |
end | |
policy_json = marshal_policy() | |
return mac.sign_with_data(policy_json) | |
end | |
def marshal_policy | |
params = {:scope => @scope, :deadline => Time.now.to_i + @expires} | |
params[:callbackUrl] = @callback_url unless @callback_url.nil? | |
params[:callbackBody] = @callback_body unless @callback_body.nil? | |
params[:returnUrl] = @return_url unless @return_url.nil? | |
params[:returnBody] = @return_body unless @return_body.nil? | |
params[:asyncOps] = @async_ops unless @async_ops.nil? | |
params[:endUser] = @end_user unless @end_user.nil? | |
params[:saveKey] = @save_key unless @save_key.nil? | |
params[:persistentOps] = @persistent_ops unless @persistent_ops.nil? | |
params[:persistentNotifyUrl] = @persistent_notify_url unless @persistent_notify_url.nil? | |
return params.to_json | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment