Class: Qiniu::DownloadToken
- Inherits:
-
AccessToken
- Object
- AccessToken
- Qiniu::DownloadToken
- Includes:
- Utils
- Defined in:
- lib/qiniu/tokens/download_token.rb
Instance Attribute Summary collapse
-
#expires_in ⇒ Object
Returns the value of attribute expires_in.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
Attributes inherited from AccessToken
Instance Method Summary collapse
- #generate_signature ⇒ Object
- #generate_token ⇒ Object
-
#initialize(opts = {}) ⇒ DownloadToken
constructor
A new instance of DownloadToken.
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
Constructor Details
#initialize(opts = {}) ⇒ DownloadToken
Returns a new instance of DownloadToken.
17 18 19 20 |
# File 'lib/qiniu/tokens/download_token.rb', line 17 def initialize(opts = {}) @pattern = opts[:pattern] @expires_in = opts[:expires_in] || 3600 end |
Instance Attribute Details
#expires_in ⇒ Object
Returns the value of attribute expires_in.
15 16 17 |
# File 'lib/qiniu/tokens/download_token.rb', line 15 def expires_in @expires_in end |
#pattern ⇒ Object
Returns the value of attribute pattern.
15 16 17 |
# File 'lib/qiniu/tokens/download_token.rb', line 15 def pattern @pattern end |
Instance Method Details
#generate_signature ⇒ Object
22 23 24 25 |
# File 'lib/qiniu/tokens/download_token.rb', line 22 def generate_signature params = {"S" => @pattern, "E" => Time.now.to_i + @expires_in} Utils.urlsafe_base64_encode(params.to_json) end |
#generate_token ⇒ Object
27 28 29 30 31 |
# File 'lib/qiniu/tokens/download_token.rb', line 27 def generate_token signature = generate_signature encoded_digest = generate_encoded_digest(signature) %Q(#{@access_key}:#{encoded_digest}:#{signature}) end |