Class: Qiniu::RS::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, #generate_qbox_signature, #generate_query_string, #http_request, #is_response_ok?, #response_error, #safe_json_parse, #send_request_with, #upload_multipart_data, #urlsafe_base64_decode, #urlsafe_base64_encode

Methods inherited from AccessToken

#generate_encoded_digest

Constructor Details

#initialize(opts = {}) ⇒ UploadToken

Returns a new instance of UploadToken.



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

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]
  @async_options = opts[:async_options]
  @return_body = opts[:return_body]
  @return_url = opts[:return_url]
end

Instance Attribute Details

#async_optionsObject

Returns the value of attribute async_options.



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

def async_options
  @async_options
end

#callback_bodyObject

Returns the value of attribute callback_body.



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

def callback_body
  @callback_body
end

#callback_body_typeObject

Returns the value of attribute callback_body_type.



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

def callback_body_type
  @callback_body_type
end

#callback_urlObject

Returns the value of attribute callback_url.



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

def callback_url
  @callback_url
end

#customerObject

Returns the value of attribute customer.



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

def customer
  @customer
end

#escapeObject

Returns the value of attribute escape.



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

def escape
  @escape
end

#expires_inObject

Returns the value of attribute expires_in.



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

def expires_in
  @expires_in
end

#return_bodyObject

Returns the value of attribute return_body.



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

def return_body
  @return_body
end

#return_urlObject

Returns the value of attribute return_url.



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

def return_url
  @return_url
end

#scopeObject

Returns the value of attribute scope.



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

def scope
  @scope
end

Instance Method Details

#generate_signatureObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/qiniu/tokens/upload_token.rb', line 28

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[:asyncOps] = @async_options if !@async_options.nil? && !@async_options.empty?
  params[:returnBody] = @return_body if !@return_body.nil? && !@return_body.empty?
  params[:returnUrl] = @return_url if !@return_url.nil? && !@return_url.empty?
  Utils.urlsafe_base64_encode(params.to_json)
end

#generate_tokenObject



41
42
43
44
45
# File 'lib/qiniu/tokens/upload_token.rb', line 41

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