module Qiniu

vim: sw=2 ts=2

vim: sw=2 ts=2

Constants

StatusOK

Public Class Methods

batch(command, bucket, keys) click to toggle source
# File lib/qiniu.rb, line 120
def batch(command, bucket, keys)
  code, data = Storage.batch(command, bucket, keys)
  code == StatusOK ? data : false
end
batch_copy(*args) click to toggle source
# File lib/qiniu.rb, line 135
def batch_copy(*args)
  code, data = Storage.batch_copy(args)
  code == StatusOK
end
batch_delete(bucket, keys) click to toggle source
# File lib/qiniu.rb, line 153
def batch_delete(bucket, keys)
  code, data = Storage.batch_delete(bucket, keys)
  code == StatusOK ? data : false
end
batch_download(bucket, keys) click to toggle source
# File lib/qiniu.rb, line 145
def batch_download(bucket, keys)
  code, data = Storage.batch_get(bucket, keys)
  return false unless code == StatusOK
  links = []
  data.each { |e| links << e["data"]["url"] }
  links
end
batch_get(bucket, keys) click to toggle source
# File lib/qiniu.rb, line 130
def batch_get(bucket, keys)
  code, data = Storage.batch_get(bucket, keys)
  code == StatusOK ? data : false
end
batch_move(*args) click to toggle source
# File lib/qiniu.rb, line 140
def batch_move(*args)
  code, data = Storage.batch_move(args)
  code == StatusOK
end
batch_stat(bucket, keys) click to toggle source
# File lib/qiniu.rb, line 125
def batch_stat(bucket, keys)
  code, data = Storage.batch_stat(bucket, keys)
  code == StatusOK ? data : false
end
buckets() click to toggle source
# File lib/qiniu.rb, line 31
def buckets
  code, data = Storage.buckets
  code == StatusOK ? data : false
end
copy(source_bucket, source_key, target_bucket, target_key) click to toggle source
# File lib/qiniu.rb, line 105
def copy(source_bucket, source_key, target_bucket, target_key)
  code, data = Storage.copy(source_bucket, source_key, target_bucket, target_key)
  code == StatusOK
end
delete(bucket, key) click to toggle source
# File lib/qiniu.rb, line 115
def delete(bucket, key)
  code, data = Storage.delete(bucket, key)
  code == StatusOK
end
download(bucket, key, save_as = nil, expires_in = nil, version = nil) click to toggle source
# File lib/qiniu.rb, line 100
def download(bucket, key, save_as = nil, expires_in = nil, version = nil)
  code, data = Storage.get(bucket, key, save_as, expires_in, version)
  code == StatusOK ? data["url"] : false
end
drop(bucket) click to toggle source
# File lib/qiniu.rb, line 158
def drop(bucket)
  code, data = Storage.drop(bucket)
  code == StatusOK
end
establish_connection!(opts = {}) click to toggle source
# File lib/qiniu.rb, line 22
def establish_connection!(opts = {})
  Config.initialize_connect opts
end
generate_download_token(opts = {}) click to toggle source
# File lib/qiniu.rb, line 197
def generate_download_token(opts = {})
  token_obj = DownloadToken.new(opts)
  token_obj.access_key = Config.settings[:access_key]
  token_obj.secret_key = Config.settings[:secret_key]
  #token_obj.expires_in = opts[:expires_in]
  #token_obj.pattern = opts[:pattern]
  token_obj.generate_token
end
generate_upload_token(opts = {}) click to toggle source
# File lib/qiniu.rb, line 182
def generate_upload_token(opts = {})
  token_obj = UploadToken.new(opts)
  token_obj.access_key = Config.settings[:access_key]
  token_obj.secret_key = Config.settings[:secret_key]
  #token_obj.scope = opts[:scope]
  #token_obj.expires_in = opts[:expires_in]
  #token_obj.callback_url = opts[:callback_url]
  #token_obj.callback_body_type = opts[:callback_body_type]
  #token_obj.customer = opts[:customer]
  #token_obj.escape = opts[:escape]
  #token_obj.async_options = opts[:async_options]
  #token_obj.return_body = opts[:return_body]
  token_obj.generate_token
end
get(bucket, key, save_as = nil, expires_in = nil, version = nil) click to toggle source
# File lib/qiniu.rb, line 95
def get(bucket, key, save_as = nil, expires_in = nil, version = nil)
  code, data = Storage.get(bucket, key, save_as, expires_in, version)
  code == StatusOK ? data : false
end
image_exif(url) click to toggle source
# File lib/qiniu.rb, line 168
def image_exif(url)
  code, data = Fop::Image.exif(url)
  code == StatusOK ? data : false
end
image_info(url) click to toggle source
# File lib/qiniu.rb, line 163
def image_info(url)
  code, data = Fop::Image.info(url)
  code == StatusOK ? data : false
end
image_mogrify_preview_url(source_image_url, options) click to toggle source
# File lib/qiniu.rb, line 173
def image_mogrify_preview_url(source_image_url, options)
  Fop::Image.mogrify_preview_url(source_image_url, options)
end
image_mogrify_save_as(bucket, key, source_image_url, options) click to toggle source
# File lib/qiniu.rb, line 177
def image_mogrify_save_as(bucket, key, source_image_url, options)
  code, data = Storage.image_mogrify_save_as(bucket, key, source_image_url, options)
  code == StatusOK ? data : false
end
mkbucket(bucket_name) click to toggle source
# File lib/qiniu.rb, line 26
def mkbucket(bucket_name)
  code, data = Storage.mkbucket(bucket_name)
  code == StatusOK
end
move(source_bucket, source_key, target_bucket, target_key) click to toggle source
# File lib/qiniu.rb, line 110
def move(source_bucket, source_key, target_bucket, target_key)
  code, data = Storage.move(source_bucket, source_key, target_bucket, target_key)
  code == StatusOK
end
set_protected(bucket, protected_mode) click to toggle source
# File lib/qiniu.rb, line 36
def set_protected(bucket, protected_mode)
  code, data = Misc.set_protected(bucket, protected_mode)
  code == StatusOK
end
set_separator(bucket, separator) click to toggle source
# File lib/qiniu.rb, line 41
def set_separator(bucket, separator)
  code, data = Misc.set_separator(bucket, separator)
  code == StatusOK
end
set_style(bucket, name, style) click to toggle source
# File lib/qiniu.rb, line 46
def set_style(bucket, name, style)
  code, data = Misc.set_style(bucket, name, style)
  code == StatusOK
end
stat(bucket, key) click to toggle source
# File lib/qiniu.rb, line 90
def stat(bucket, key)
  code, data = Storage.stat(bucket, key)
  code == StatusOK ? data : false
end
unset_style(bucket, name) click to toggle source
# File lib/qiniu.rb, line 51
def unset_style(bucket, name)
  code, data = Misc.unset_style(bucket, name)
  code == StatusOK
end
upload_file(opts = {}) click to toggle source
# File lib/qiniu.rb, line 56
def upload_file opts = {}
  uncontained_opts = [:uptoken, :file, :bucket, :key] - opts.keys
  raise MissingArgsError, uncontained_opts unless uncontained_opts.empty?

  source_file = opts[:file]
  raise NoSuchFileError, source_file unless File.exist?(source_file)

  opts[:enable_resumable_upload] = true unless opts.has_key?(:enable_resumable_upload)

  if opts[:enable_resumable_upload] && File::size(source_file) > Config.settings[:block_size]
    code, data, raw_headers = Storage.upload_with_token(opts[:uptoken],
                                      opts[:file],
                                      opts[:bucket],
                                      opts[:key],
                                      opts[:mime_type],
                                      opts[:note],
                                      opts[:customer],
                                      opts[:callback_params],
                                      opts[:rotate])
  else
    code, data, raw_headers = Storage.upload_with_token(opts[:uptoken],
                                      opts[:file],
                                      opts[:bucket],
                                      opts[:key],
                                      opts[:mime_type],
                                      opts[:note],
                                      opts[:callback_params],
                                      opts[:enable_crc32_check],
                                      opts[:rotate])
  end
  raise UploadFailedError.new(code, data) if code != StatusOK
  return data
end