class Qiniu::Auth::PutPolicy

Constants

PARAMS

Attributes

bucket[R]
key[R]

Public Class Methods

new(bucket, key = nil, expires_in = DEFAULT_AUTH_SECONDS, deadline = nil) click to toggle source
# File lib/qiniu/auth.rb, line 36
def initialize(bucket,
               key = nil,
               expires_in = DEFAULT_AUTH_SECONDS,
               deadline = nil)
  ### 设定scope参数(必填项目)
  self.scope!(bucket, key)

  ### 设定deadline参数(必填项目)
  @expires_in = expires_in
  @deadline   = Auth.calculate_deadline(expires_in, deadline)
end

Public Instance Methods

allow_mime_list!(list) click to toggle source
# File lib/qiniu/auth.rb, line 121
def allow_mime_list! (list)
  @mime_limit = list
end
deny_mime_list!(list) click to toggle source
# File lib/qiniu/auth.rb, line 125
def deny_mime_list! (list)
  @mime_limit = "!#{list}"
end
detect_mime!() click to toggle source
# File lib/qiniu/auth.rb, line 133
def detect_mime!
  @detect_mime = 1
end
expires_in() click to toggle source
# File lib/qiniu/auth.rb, line 117
def expires_in
  return @expires_in
end
expires_in!(seconds) click to toggle source
# File lib/qiniu/auth.rb, line 102
def expires_in!(seconds)
  if !seconds.nil? then
    return @expires_in
  end

  @epires_in = seconds
  @deadline  = Auth.calculate_deadline(seconds)

  return @expires_in
end
expires_in=(seconds) click to toggle source
# File lib/qiniu/auth.rb, line 113
def expires_in=(seconds)
  return expires_in!(seconds)
end
insert_only!() click to toggle source
# File lib/qiniu/auth.rb, line 129
def insert_only!
  @insert_only = 1
end
scope!(bucket, key = nil) click to toggle source
# File lib/qiniu/auth.rb, line 80
def scope!(bucket, key = nil)
  @bucket = bucket
  @key    = key

  if key.nil? then
    # 新增语义,文件已存在则失败
    @scope = bucket
  else
    # 覆盖语义,文件已存在则直接覆盖
    @scope = "#{bucket}:#{key}"
  end

  if Config.settings[:multi_region]
    begin
      @uphosts = Config.host_manager.up_hosts(bucket)
      @global = Config.host_manager.global(bucket)
    rescue
      # Do nothing
    end
  end
end
to_json() click to toggle source
# File lib/qiniu/auth.rb, line 137
def to_json
  args = {}

  PARAMS.each_pair do |key, fld|
    val = self.__send__(key)
    if !val.nil? then
      args[fld] = val
    end
  end

  return args.to_json
end