Class: Qiniu::UploadToken

Inherits:
AccessToken show all
Includes:
Utils
Defined in:
lib/qiniu/tokens/upload_token.rb

Instance Attribute Summary collapse

Attributes inherited from AccessToken

#access_key, #secret_key

Instance Method Summary collapse

Methods included from Utils

#crc32checksum, #debug, #encode_entry_uri, #http_request, #safe_json_parse, #send_request_with, #urlsafe_base64_decode, #urlsafe_base64_encode

Methods inherited from AccessToken

#generate_encoded_digest

Constructor Details

#initialize(opts = {}) ⇒ UploadToken

Returns a new instance of UploadToken.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/qiniu/tokens/upload_token.rb', line 16

def initialize(opts = {})
  @scope = opts[:scope]
  @expires_in = opts[:expires_in] || 3600
  @callback_url = opts[:callback_url]
  @callback_body = opts[:callback_body]
  @callback_body_type = opts[:callback_body_type]
  @customer = opts[:customer]
  @escape = opts[:escape]
  @persistent_ops = opts[:persistent_ops]
  @persistent_notify_url = opts[:persistent_notify_url]
  @persistent_pipeline = opts[:persistent_pipeline]
  @return_body = opts[:return_body]
  @return_url = opts[:return_url]
end

Instance Attribute Details

#async_optionsObject

Returns the value of attribute async_options.



14
15
16
# File 'lib/qiniu/tokens/upload_token.rb', line 14

def async_options
  @async_options
end

#callback_bodyObject

Returns the value of attribute callback_body.



14
15
16
# File 'lib/qiniu/tokens/upload_token.rb', line 14

def callback_body
  @callback_body
end

#callback_body_typeObject

Returns the value of attribute callback_body_type.



14
15
16
# File 'lib/qiniu/tokens/upload_token.rb', line 14

def callback_body_type
  @callback_body_type
end

#callback_urlObject

Returns the value of attribute callback_url.



14
15
16
# File 'lib/qiniu/tokens/upload_token.rb', line 14

def callback_url
  @callback_url
end

#customerObject

Returns the value of attribute customer.



14
15
16
# File 'lib/qiniu/tokens/upload_token.rb', line 14

def customer
  @customer
end

#escapeObject

Returns the value of attribute escape.



14
15
16
# File 'lib/qiniu/tokens/upload_token.rb', line 14

def escape
  @escape
end

#expires_inObject

Returns the value of attribute expires_in.



14
15
16
# File 'lib/qiniu/tokens/upload_token.rb', line 14

def expires_in
  @expires_in
end

#return_bodyObject

Returns the value of attribute return_body.



14
15
16
# File 'lib/qiniu/tokens/upload_token.rb', line 14

def return_body
  @return_body
end

#return_urlObject

Returns the value of attribute return_url.



14
15
16
# File 'lib/qiniu/tokens/upload_token.rb', line 14

def return_url
  @return_url
end

#scopeObject

Returns the value of attribute scope.



14
15
16
# File 'lib/qiniu/tokens/upload_token.rb', line 14

def scope
  @scope
end

Instance Method Details

#generate_signatureObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/qiniu/tokens/upload_token.rb', line 31

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[:callbackBody] = @callback_body if !@callback_body.nil? && !@callback_body.empty?
  params[:callbackBodyType] = @callback_body_type if !@callback_body_type.nil? && !@callback_body_type.empty?
  params[:customer] = @customer if !@customer.nil? && !@customer.empty?
  params[:escape] = 1 if @escape == 1 || @escape == true
  params[:returnBody] = @return_body if !@return_body.nil? && !@return_body.empty?
  params[:returnUrl] = @return_url if !@return_url.nil? && !@return_url.empty?

  params[:persistentOps] = @persistent_ops if !@persistent_ops.nil? && !@persistent_ops.empty?
  params[:persistentNotifyUrl] = @persistent_notify_url if !@persistent_notify_url.nil? && !@persistent_notify_url.empty?
  params[:persistentPipeline] = @persistent_pipeline if !@persistent_pipeline.nil? && !@persistent_pipeline.empty?

  Utils.urlsafe_base64_encode(params.to_json)
end

#generate_tokenObject



48
49
50
51
52
# File 'lib/qiniu/tokens/upload_token.rb', line 48

def generate_token
  signature = generate_signature
  encoded_digest = generate_encoded_digest(signature)
  %Q(#{@access_key}:#{encoded_digest}:#{signature})
end