mirror of
https://github.com/wahyd4/ruby-sdk.git
synced 2026-08-09 21:06:19 +10:00
去除统一的RS空间。
This commit is contained in:
+1
-1
@@ -1,2 +1,2 @@
|
||||
# More logical way to require 'qiniu-rs'
|
||||
require File.join(File.dirname(__FILE__), 'qiniu', 'rs')
|
||||
require File.join(File.dirname(__FILE__), 'qiniu', 'qiniu')
|
||||
|
||||
Executable
+231
@@ -0,0 +1,231 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
module Qiniu
|
||||
autoload :Version, 'qiniu/version'
|
||||
autoload :Utils, 'qiniu/utils'
|
||||
autoload :Auth, 'qiniu/auth'
|
||||
autoload :Config, 'qiniu/config'
|
||||
autoload :Log, 'qiniu/log'
|
||||
autoload :Exception, 'qiniu/exceptions'
|
||||
autoload :IO, 'qiniu/io'
|
||||
autoload :UP, 'qiniu/up'
|
||||
autoload :RS, 'qiniu/rs'
|
||||
autoload :Pub, 'qiniu/pub'
|
||||
autoload :Image, 'qiniu/image'
|
||||
autoload :AccessToken, 'qiniu/tokens/access_token'
|
||||
autoload :QboxToken, 'qiniu/tokens/qbox_token'
|
||||
autoload :UploadToken, 'qiniu/tokens/upload_token'
|
||||
autoload :DownloadToken, 'qiniu/tokens/download_token'
|
||||
autoload :Abstract, 'qiniu/abstract'
|
||||
|
||||
class << self
|
||||
|
||||
StatusOK = 200
|
||||
|
||||
def establish_connection!(opts = {})
|
||||
Config.initialize_connect opts
|
||||
end
|
||||
|
||||
def mkbucket(bucket_name)
|
||||
code, data = RS.mkbucket(bucket_name)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def buckets
|
||||
code, data = RS.buckets
|
||||
code == StatusOK ? data : false
|
||||
end
|
||||
|
||||
def set_protected(bucket, protected_mode)
|
||||
code, data = Pub.set_protected(bucket, protected_mode)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def set_separator(bucket, separator)
|
||||
code, data = Pub.set_separator(bucket, separator)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def set_style(bucket, name, style)
|
||||
code, data = Pub.set_style(bucket, name, style)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def unset_style(bucket, name)
|
||||
code, data = Pub.unset_style(bucket, name)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def put_file opts = {}
|
||||
code, data = IO.put_file(opts[:file],
|
||||
opts[:bucket],
|
||||
opts[:key],
|
||||
opts[:mime_type],
|
||||
opts[:note],
|
||||
opts[:enable_crc32_check])
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
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 = UP.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 = IO.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
|
||||
|
||||
def stat(bucket, key)
|
||||
code, data = RS.stat(bucket, key)
|
||||
code == StatusOK ? data : false
|
||||
end
|
||||
|
||||
def get(bucket, key, save_as = nil, expires_in = nil, version = nil)
|
||||
code, data = RS.get(bucket, key, save_as, expires_in, version)
|
||||
code == StatusOK ? data : false
|
||||
end
|
||||
|
||||
def download(bucket, key, save_as = nil, expires_in = nil, version = nil)
|
||||
code, data = RS.get(bucket, key, save_as, expires_in, version)
|
||||
code == StatusOK ? data["url"] : false
|
||||
end
|
||||
|
||||
def copy(source_bucket, source_key, target_bucket, target_key)
|
||||
code, data = RS.copy(source_bucket, source_key, target_bucket, target_key)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def move(source_bucket, source_key, target_bucket, target_key)
|
||||
code, data = RS.move(source_bucket, source_key, target_bucket, target_key)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def delete(bucket, key)
|
||||
code, data = RS.delete(bucket, key)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def batch(command, bucket, keys)
|
||||
code, data = RS.batch(command, bucket, keys)
|
||||
code == StatusOK ? data : false
|
||||
end
|
||||
|
||||
def batch_stat(bucket, keys)
|
||||
code, data = RS.batch_stat(bucket, keys)
|
||||
code == StatusOK ? data : false
|
||||
end
|
||||
|
||||
def batch_get(bucket, keys)
|
||||
code, data = RS.batch_get(bucket, keys)
|
||||
code == StatusOK ? data : false
|
||||
end
|
||||
|
||||
def batch_copy(*args)
|
||||
code, data = RS.batch_copy(args)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def batch_move(*args)
|
||||
code, data = RS.batch_move(args)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def batch_download(bucket, keys)
|
||||
code, data = RS.batch_get(bucket, keys)
|
||||
return false unless code == StatusOK
|
||||
links = []
|
||||
data.each { |e| links << e["data"]["url"] }
|
||||
links
|
||||
end
|
||||
|
||||
def batch_delete(bucket, keys)
|
||||
code, data = RS.batch_delete(bucket, keys)
|
||||
code == StatusOK ? data : false
|
||||
end
|
||||
|
||||
def publish(domain, bucket)
|
||||
code, data = RS.publish(domain, bucket)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def unpublish(domain)
|
||||
code, data = RS.unpublish(domain)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def drop(bucket)
|
||||
code, data = RS.drop(bucket)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def image_info(url)
|
||||
code, data = Image.info(url)
|
||||
code == StatusOK ? data : false
|
||||
end
|
||||
|
||||
def image_exif(url)
|
||||
code, data = Image.exif(url)
|
||||
code == StatusOK ? data : false
|
||||
end
|
||||
|
||||
def image_mogrify_preview_url(source_image_url, options)
|
||||
Image.mogrify_preview_url(source_image_url, options)
|
||||
end
|
||||
|
||||
def image_mogrify_save_as(bucket, key, source_image_url, options)
|
||||
code, data = RS.image_mogrify_save_as(bucket, key, source_image_url, options)
|
||||
code == StatusOK ? data : false
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
end
|
||||
|
||||
end # module Qiniu
|
||||
@@ -1,7 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
module Abstract
|
||||
def self.included(base)
|
||||
base.extend(ClassMethods)
|
||||
@@ -19,6 +18,5 @@ module Qiniu
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end # module Abstract
|
||||
end # module Qiniu
|
||||
@@ -1,9 +1,8 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
require 'qiniu/rs/exceptions'
|
||||
require 'qiniu/exceptions'
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
module Auth
|
||||
|
||||
class << self
|
||||
@@ -21,5 +20,4 @@ module Qiniu
|
||||
end
|
||||
|
||||
end # module Auth
|
||||
end # module RS
|
||||
end # module Qiniu
|
||||
@@ -11,7 +11,6 @@
|
||||
require 'tmpdir'
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
module Config
|
||||
class << self
|
||||
|
||||
@@ -58,6 +57,5 @@ module Qiniu
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end # module Config
|
||||
end # module Qiniu
|
||||
@@ -1,7 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
|
||||
class Exception < RuntimeError
|
||||
end
|
||||
@@ -118,5 +117,4 @@ module Qiniu
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end # module Qiniu
|
||||
@@ -1,7 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
module Image
|
||||
class << self
|
||||
include Utils
|
||||
@@ -33,6 +32,5 @@ module Qiniu
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end # module Image
|
||||
end # module Qiniu
|
||||
@@ -2,10 +2,9 @@
|
||||
|
||||
require 'mime/types'
|
||||
require 'digest/sha1'
|
||||
require 'qiniu/rs/exceptions'
|
||||
require 'qiniu/exceptions'
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
module IO
|
||||
class << self
|
||||
include Utils
|
||||
@@ -67,6 +66,5 @@ module Qiniu
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end # module IO
|
||||
end # module Qiniu
|
||||
@@ -3,7 +3,6 @@
|
||||
require 'logger'
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
module Log
|
||||
class << self
|
||||
attr_accessor :logger
|
||||
@@ -12,6 +11,5 @@ module Qiniu
|
||||
@logger ||= Logger.new(STDERR)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end # module Log
|
||||
end # module Qiniu
|
||||
@@ -1,7 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
module Pub
|
||||
class << self
|
||||
include Utils
|
||||
@@ -31,7 +30,6 @@ module Qiniu
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end # module Pub
|
||||
end # module Qiniu
|
||||
|
||||
+111
-228
@@ -1,234 +1,117 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
autoload :Version, 'qiniu/rs/version'
|
||||
autoload :Config, 'qiniu/rs/config'
|
||||
autoload :Log, 'qiniu/rs/log'
|
||||
autoload :Exception, 'qiniu/rs/exceptions'
|
||||
autoload :Utils, 'qiniu/rs/utils'
|
||||
autoload :Auth, 'qiniu/rs/auth'
|
||||
autoload :IO, 'qiniu/rs/io'
|
||||
autoload :UP, 'qiniu/rs/up'
|
||||
autoload :RS, 'qiniu/rs/rs'
|
||||
autoload :EU, 'qiniu/rs/eu'
|
||||
autoload :Pub, 'qiniu/rs/pub'
|
||||
autoload :Image, 'qiniu/rs/image'
|
||||
autoload :AccessToken, 'qiniu/tokens/access_token'
|
||||
autoload :QboxToken, 'qiniu/tokens/qbox_token'
|
||||
autoload :UploadToken, 'qiniu/tokens/upload_token'
|
||||
autoload :DownloadToken, 'qiniu/tokens/download_token'
|
||||
autoload :Abstract, 'qiniu/rs/abstract'
|
||||
module RS
|
||||
class << self
|
||||
include Utils
|
||||
|
||||
class << self
|
||||
|
||||
StatusOK = 200
|
||||
|
||||
def establish_connection!(opts = {})
|
||||
Config.initialize_connect opts
|
||||
end
|
||||
|
||||
def mkbucket(bucket_name)
|
||||
code, data = RS.mkbucket(bucket_name)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def buckets
|
||||
code, data = RS.buckets
|
||||
code == StatusOK ? data : false
|
||||
end
|
||||
|
||||
def set_protected(bucket, protected_mode)
|
||||
code, data = Pub.set_protected(bucket, protected_mode)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def set_separator(bucket, separator)
|
||||
code, data = Pub.set_separator(bucket, separator)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def set_style(bucket, name, style)
|
||||
code, data = Pub.set_style(bucket, name, style)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def unset_style(bucket, name)
|
||||
code, data = Pub.unset_style(bucket, name)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def put_file opts = {}
|
||||
code, data = IO.put_file(opts[:file],
|
||||
opts[:bucket],
|
||||
opts[:key],
|
||||
opts[:mime_type],
|
||||
opts[:note],
|
||||
opts[:enable_crc32_check])
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
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 = UP.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 = IO.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])
|
||||
def buckets
|
||||
Auth.request Config.settings[:rs_host] + '/buckets'
|
||||
end
|
||||
raise UploadFailedError.new(code, data) if code != StatusOK
|
||||
return data
|
||||
|
||||
def mkbucket(bucket_name)
|
||||
Auth.request Config.settings[:rs_host] + '/mkbucket/' + bucket_name
|
||||
end
|
||||
|
||||
def stat(bucket, key)
|
||||
Auth.request Config.settings[:rs_host] + '/stat/' + encode_entry_uri(bucket, key)
|
||||
end
|
||||
|
||||
def get(bucket, key, save_as = nil, expires_in = nil, version = nil)
|
||||
url = Config.settings[:rs_host] + '/get/' + encode_entry_uri(bucket, key)
|
||||
url += '/base/' + version unless version.nil?
|
||||
url += '/attName/' + Utils.urlsafe_base64_encode(save_as) unless save_as.nil?
|
||||
url += '/expires/' + expires_in.to_s if !expires_in.nil? && expires_in > 0
|
||||
Auth.request url
|
||||
end
|
||||
|
||||
def copy(source_bucket, source_key, target_bucket, target_key)
|
||||
uri = _generate_cp_or_mv_opstr('copy', source_bucket, source_key, target_bucket, target_key)
|
||||
Auth.request Config.settings[:rs_host] + uri
|
||||
end
|
||||
|
||||
def move(source_bucket, source_key, target_bucket, target_key)
|
||||
uri = _generate_cp_or_mv_opstr('move', source_bucket, source_key, target_bucket, target_key)
|
||||
Auth.request Config.settings[:rs_host] + uri
|
||||
end
|
||||
|
||||
def delete(bucket, key)
|
||||
Auth.request Config.settings[:rs_host] + '/delete/' + encode_entry_uri(bucket, key)
|
||||
end
|
||||
|
||||
def publish(domain, bucket)
|
||||
encoded_domain = Utils.urlsafe_base64_encode(domain)
|
||||
Auth.request Config.settings[:rs_host] + "/publish/#{encoded_domain}/from/#{bucket}"
|
||||
end
|
||||
|
||||
def unpublish(domain)
|
||||
encoded_domain = Utils.urlsafe_base64_encode(domain)
|
||||
Auth.request Config.settings[:rs_host] + "/unpublish/#{encoded_domain}"
|
||||
end
|
||||
|
||||
def drop(bucket)
|
||||
Auth.request Config.settings[:rs_host] + "/drop/#{bucket}"
|
||||
end
|
||||
|
||||
def batch(command, bucket, keys)
|
||||
execs = []
|
||||
keys.each do |key|
|
||||
encoded_uri = encode_entry_uri(bucket, key)
|
||||
execs << "op=/#{command}/#{encoded_uri}"
|
||||
end
|
||||
Auth.request Config.settings[:rs_host] + "/batch?" + execs.join("&")
|
||||
end
|
||||
|
||||
def batch_get(bucket, keys)
|
||||
batch("get", bucket, keys)
|
||||
end
|
||||
|
||||
def batch_stat(bucket, keys)
|
||||
batch("stat", bucket, keys)
|
||||
end
|
||||
|
||||
def batch_copy(*args)
|
||||
_batch_cp_or_mv('copy', args)
|
||||
end
|
||||
|
||||
def batch_move(*args)
|
||||
_batch_cp_or_mv('move', args)
|
||||
end
|
||||
|
||||
def batch_delete(bucket, keys)
|
||||
batch("delete", bucket, keys)
|
||||
end
|
||||
|
||||
def save_as(bucket, key, source_url, op_params_string)
|
||||
encoded_uri = encode_entry_uri(bucket, key)
|
||||
save_as_string = '/save-as/' + encoded_uri
|
||||
new_url = source_url + '?' + op_params_string + save_as_string
|
||||
Auth.request new_url
|
||||
end
|
||||
|
||||
def image_mogrify_save_as(bucket, key, source_image_url, options)
|
||||
mogrify_params_string = Image.generate_mogrify_params_string(options)
|
||||
save_as(bucket, key, source_image_url, mogrify_params_string)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def _generate_cp_or_mv_opstr(command, source_bucket, source_key, target_bucket, target_key)
|
||||
source_encoded_entry_uri = encode_entry_uri(source_bucket, source_key)
|
||||
target_encoded_entry_uri = encode_entry_uri(target_bucket, target_key)
|
||||
%Q(/#{command}/#{source_encoded_entry_uri}/#{target_encoded_entry_uri})
|
||||
end
|
||||
|
||||
=begin
|
||||
def _batch_cp_or_mv(command, *op_args)
|
||||
execs = []
|
||||
op_args.each do |e|
|
||||
execs << 'op=' + _generate_cp_or_mv_opstr(command, e[0], e[1], e[2], e[3]) if e.size == 4
|
||||
end
|
||||
Auth.request Config.settings[:rs_host] + "/batch?" + execs.join("&")
|
||||
end
|
||||
=end
|
||||
|
||||
end
|
||||
|
||||
def stat(bucket, key)
|
||||
code, data = RS.stat(bucket, key)
|
||||
code == StatusOK ? data : false
|
||||
end
|
||||
|
||||
def get(bucket, key, save_as = nil, expires_in = nil, version = nil)
|
||||
code, data = RS.get(bucket, key, save_as, expires_in, version)
|
||||
code == StatusOK ? data : false
|
||||
end
|
||||
|
||||
def download(bucket, key, save_as = nil, expires_in = nil, version = nil)
|
||||
code, data = RS.get(bucket, key, save_as, expires_in, version)
|
||||
code == StatusOK ? data["url"] : false
|
||||
end
|
||||
|
||||
def copy(source_bucket, source_key, target_bucket, target_key)
|
||||
code, data = RS.copy(source_bucket, source_key, target_bucket, target_key)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def move(source_bucket, source_key, target_bucket, target_key)
|
||||
code, data = RS.move(source_bucket, source_key, target_bucket, target_key)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def delete(bucket, key)
|
||||
code, data = RS.delete(bucket, key)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def batch(command, bucket, keys)
|
||||
code, data = RS.batch(command, bucket, keys)
|
||||
code == StatusOK ? data : false
|
||||
end
|
||||
|
||||
def batch_stat(bucket, keys)
|
||||
code, data = RS.batch_stat(bucket, keys)
|
||||
code == StatusOK ? data : false
|
||||
end
|
||||
|
||||
def batch_get(bucket, keys)
|
||||
code, data = RS.batch_get(bucket, keys)
|
||||
code == StatusOK ? data : false
|
||||
end
|
||||
|
||||
def batch_copy(*args)
|
||||
code, data = RS.batch_copy(args)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def batch_move(*args)
|
||||
code, data = RS.batch_move(args)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def batch_download(bucket, keys)
|
||||
code, data = RS.batch_get(bucket, keys)
|
||||
return false unless code == StatusOK
|
||||
links = []
|
||||
data.each { |e| links << e["data"]["url"] }
|
||||
links
|
||||
end
|
||||
|
||||
def batch_delete(bucket, keys)
|
||||
code, data = RS.batch_delete(bucket, keys)
|
||||
code == StatusOK ? data : false
|
||||
end
|
||||
|
||||
def publish(domain, bucket)
|
||||
code, data = RS.publish(domain, bucket)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def unpublish(domain)
|
||||
code, data = RS.unpublish(domain)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def drop(bucket)
|
||||
code, data = RS.drop(bucket)
|
||||
code == StatusOK
|
||||
end
|
||||
|
||||
def image_info(url)
|
||||
code, data = Image.info(url)
|
||||
code == StatusOK ? data : false
|
||||
end
|
||||
|
||||
def image_exif(url)
|
||||
code, data = Image.exif(url)
|
||||
code == StatusOK ? data : false
|
||||
end
|
||||
|
||||
def image_mogrify_preview_url(source_image_url, options)
|
||||
Image.mogrify_preview_url(source_image_url, options)
|
||||
end
|
||||
|
||||
def image_mogrify_save_as(bucket, key, source_image_url, options)
|
||||
code, data = RS.image_mogrify_save_as(bucket, key, source_image_url, options)
|
||||
code == StatusOK ? data : false
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end # module RS
|
||||
end # module Qiniu
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
module RS
|
||||
class << self
|
||||
include Utils
|
||||
|
||||
def buckets
|
||||
Auth.request Config.settings[:rs_host] + '/buckets'
|
||||
end
|
||||
|
||||
def mkbucket(bucket_name)
|
||||
Auth.request Config.settings[:rs_host] + '/mkbucket/' + bucket_name
|
||||
end
|
||||
|
||||
def stat(bucket, key)
|
||||
Auth.request Config.settings[:rs_host] + '/stat/' + encode_entry_uri(bucket, key)
|
||||
end
|
||||
|
||||
def get(bucket, key, save_as = nil, expires_in = nil, version = nil)
|
||||
url = Config.settings[:rs_host] + '/get/' + encode_entry_uri(bucket, key)
|
||||
url += '/base/' + version unless version.nil?
|
||||
url += '/attName/' + Utils.urlsafe_base64_encode(save_as) unless save_as.nil?
|
||||
url += '/expires/' + expires_in.to_s if !expires_in.nil? && expires_in > 0
|
||||
Auth.request url
|
||||
end
|
||||
|
||||
def copy(source_bucket, source_key, target_bucket, target_key)
|
||||
uri = _generate_cp_or_mv_opstr('copy', source_bucket, source_key, target_bucket, target_key)
|
||||
Auth.request Config.settings[:rs_host] + uri
|
||||
end
|
||||
|
||||
def move(source_bucket, source_key, target_bucket, target_key)
|
||||
uri = _generate_cp_or_mv_opstr('move', source_bucket, source_key, target_bucket, target_key)
|
||||
Auth.request Config.settings[:rs_host] + uri
|
||||
end
|
||||
|
||||
def delete(bucket, key)
|
||||
Auth.request Config.settings[:rs_host] + '/delete/' + encode_entry_uri(bucket, key)
|
||||
end
|
||||
|
||||
def publish(domain, bucket)
|
||||
encoded_domain = Utils.urlsafe_base64_encode(domain)
|
||||
Auth.request Config.settings[:rs_host] + "/publish/#{encoded_domain}/from/#{bucket}"
|
||||
end
|
||||
|
||||
def unpublish(domain)
|
||||
encoded_domain = Utils.urlsafe_base64_encode(domain)
|
||||
Auth.request Config.settings[:rs_host] + "/unpublish/#{encoded_domain}"
|
||||
end
|
||||
|
||||
def drop(bucket)
|
||||
Auth.request Config.settings[:rs_host] + "/drop/#{bucket}"
|
||||
end
|
||||
|
||||
def batch(command, bucket, keys)
|
||||
execs = []
|
||||
keys.each do |key|
|
||||
encoded_uri = encode_entry_uri(bucket, key)
|
||||
execs << "op=/#{command}/#{encoded_uri}"
|
||||
end
|
||||
Auth.request Config.settings[:rs_host] + "/batch?" + execs.join("&")
|
||||
end
|
||||
|
||||
def batch_get(bucket, keys)
|
||||
batch("get", bucket, keys)
|
||||
end
|
||||
|
||||
def batch_stat(bucket, keys)
|
||||
batch("stat", bucket, keys)
|
||||
end
|
||||
|
||||
def batch_copy(*args)
|
||||
_batch_cp_or_mv('copy', args)
|
||||
end
|
||||
|
||||
def batch_move(*args)
|
||||
_batch_cp_or_mv('move', args)
|
||||
end
|
||||
|
||||
def batch_delete(bucket, keys)
|
||||
batch("delete", bucket, keys)
|
||||
end
|
||||
|
||||
def save_as(bucket, key, source_url, op_params_string)
|
||||
encoded_uri = encode_entry_uri(bucket, key)
|
||||
save_as_string = '/save-as/' + encoded_uri
|
||||
new_url = source_url + '?' + op_params_string + save_as_string
|
||||
Auth.request new_url
|
||||
end
|
||||
|
||||
def image_mogrify_save_as(bucket, key, source_image_url, options)
|
||||
mogrify_params_string = Image.generate_mogrify_params_string(options)
|
||||
save_as(bucket, key, source_image_url, mogrify_params_string)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def _generate_cp_or_mv_opstr(command, source_bucket, source_key, target_bucket, target_key)
|
||||
source_encoded_entry_uri = encode_entry_uri(source_bucket, source_key)
|
||||
target_encoded_entry_uri = encode_entry_uri(target_bucket, target_key)
|
||||
%Q(/#{command}/#{source_encoded_entry_uri}/#{target_encoded_entry_uri})
|
||||
end
|
||||
|
||||
=begin
|
||||
def _batch_cp_or_mv(command, *op_args)
|
||||
execs = []
|
||||
op_args.each do |e|
|
||||
execs << 'op=' + _generate_cp_or_mv_opstr(command, e[0], e[1], e[2], e[3]) if e.size == 4
|
||||
end
|
||||
Auth.request Config.settings[:rs_host] + "/batch?" + execs.join("&")
|
||||
end
|
||||
=end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,11 +1,10 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
require 'hmac-sha1'
|
||||
require 'qiniu/rs/config'
|
||||
require 'qiniu/rs/utils'
|
||||
require 'qiniu/config'
|
||||
require 'qiniu/utils'
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
class AccessToken
|
||||
|
||||
include Utils
|
||||
@@ -18,6 +17,5 @@ module Qiniu
|
||||
urlsafe_base64_encode(hmac.digest)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end # AccessToken
|
||||
end # module Qiniu
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
|
||||
require 'json'
|
||||
require 'qiniu/tokens/access_token'
|
||||
require 'qiniu/rs/utils'
|
||||
require 'qiniu/utils'
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
class DownloadToken < AccessToken
|
||||
|
||||
include Utils
|
||||
@@ -28,6 +27,5 @@ module Qiniu
|
||||
%Q(#{@access_key}:#{encoded_digest}:#{signature})
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end # moidule DownloadToken
|
||||
end # module Qiniu
|
||||
|
||||
@@ -5,7 +5,6 @@ require 'json'
|
||||
require 'qiniu/tokens/access_token'
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
class QboxToken < AccessToken
|
||||
|
||||
include Utils
|
||||
@@ -35,6 +34,5 @@ module Qiniu
|
||||
%Q(#{@access_key}:#{encoded_digest})
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end # module QboxToken
|
||||
end # module Qiniu
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
|
||||
require 'json'
|
||||
require 'qiniu/tokens/access_token'
|
||||
require 'qiniu/rs/utils'
|
||||
require 'qiniu/utils'
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
class UploadToken < AccessToken
|
||||
|
||||
include Utils
|
||||
@@ -44,6 +43,5 @@ module Qiniu
|
||||
%Q(#{@access_key}:#{encoded_digest}:#{signature})
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end # module UploadToken
|
||||
end # module Qiniu
|
||||
|
||||
@@ -6,23 +6,22 @@ require 'tmpdir'
|
||||
require 'fileutils'
|
||||
require 'mime/types'
|
||||
require 'digest/sha1'
|
||||
require 'qiniu/rs/abstract'
|
||||
require 'qiniu/rs/exceptions'
|
||||
require 'qiniu/rs/io'
|
||||
require 'qiniu/abstract'
|
||||
require 'qiniu/exceptions'
|
||||
require 'qiniu/io'
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
module UP
|
||||
|
||||
module AbstractClass
|
||||
class ChunkProgressNotifier
|
||||
include Qiniu::RS::Abstract
|
||||
include Qiniu::Abstract
|
||||
abstract_methods :notify
|
||||
# def notify(block_index, block_put_progress); end
|
||||
end
|
||||
|
||||
class BlockProgressNotifier
|
||||
include Qiniu::RS::Abstract
|
||||
include Qiniu::Abstract
|
||||
abstract_methods :notify
|
||||
# def notify(block_index, checksum); end
|
||||
end
|
||||
@@ -276,6 +275,5 @@ module Qiniu
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end # module UP
|
||||
end # module Qiniu
|
||||
@@ -7,10 +7,9 @@ require 'zlib'
|
||||
require 'base64'
|
||||
require 'rest_client'
|
||||
require 'hmac-sha1'
|
||||
require 'qiniu/rs/exceptions'
|
||||
require 'qiniu/exceptions'
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
module Utils extend self
|
||||
|
||||
def urlsafe_base64_encode content
|
||||
@@ -145,6 +144,5 @@ module Qiniu
|
||||
%Q(#{access_key}:#{encoded_digest})
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end # module Utils
|
||||
end # module Qiniu
|
||||
@@ -1,7 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
module Version
|
||||
MAJOR = 3
|
||||
MINOR = 4
|
||||
@@ -14,6 +13,5 @@ module Qiniu
|
||||
def self.to_s
|
||||
[MAJOR, MINOR, PATCH].join('.')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end # Version
|
||||
end # module Qiniu
|
||||
@@ -1,12 +1,12 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
require 'spec_helper'
|
||||
require 'qiniu/rs/abstract'
|
||||
require 'qiniu/abstract'
|
||||
|
||||
describe Qiniu::RS::Abstract do
|
||||
describe Qiniu::Abstract do
|
||||
before(:each) do
|
||||
@klass = Class.new do
|
||||
include Qiniu::RS::Abstract
|
||||
include Qiniu::Abstract
|
||||
|
||||
abstract_methods :foo, :bar
|
||||
end
|
||||
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
@@ -1,12 +1,12 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
require 'spec_helper'
|
||||
require 'qiniu/rs/auth'
|
||||
require 'qiniu/auth'
|
||||
require 'qiniu/rs'
|
||||
require 'qiniu/rs/image'
|
||||
require 'qiniu/image'
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
module Image
|
||||
describe Image do
|
||||
|
||||
before :all do
|
||||
@@ -14,7 +14,7 @@ module Qiniu
|
||||
@bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s
|
||||
@key = "image_logo_for_test.png"
|
||||
|
||||
result = Qiniu::RS.mkbucket(@bucket)
|
||||
result = Qiniu.mkbucket(@bucket)
|
||||
puts result.inspect
|
||||
result.should be_true
|
||||
|
||||
@@ -27,8 +27,8 @@ module Qiniu
|
||||
:async_options => "imageView/1/w/120/h/120",
|
||||
:return_body => '{"size":$(fsize), "hash":$(etag), "width":$(imageInfo.width), "height":$(imageInfo.height)}'
|
||||
}
|
||||
uptoken = Qiniu::RS.generate_upload_token(upopts)
|
||||
data = Qiniu::RS.upload_file :uptoken => uptoken, :file => local_file, :bucket => @bucket, :key => @key
|
||||
uptoken = Qiniu.generate_upload_token(upopts)
|
||||
data = Qiniu.upload_file :uptoken => uptoken, :file => local_file, :bucket => @bucket, :key => @key
|
||||
puts data.inspect
|
||||
|
||||
data["size"].should_not be_zero
|
||||
@@ -36,7 +36,7 @@ module Qiniu
|
||||
data["width"].should_not be_zero
|
||||
data["height"].should_not be_zero
|
||||
|
||||
result = Qiniu::RS.get(@bucket, @key)
|
||||
result = Qiniu.get(@bucket, @key)
|
||||
result["url"].should_not be_empty
|
||||
puts result.inspect
|
||||
@source_image_url = result["url"]
|
||||
@@ -53,14 +53,14 @@ module Qiniu
|
||||
end
|
||||
|
||||
after :all do
|
||||
result = Qiniu::RS.drop(@bucket)
|
||||
result = Qiniu.drop(@bucket)
|
||||
puts result.inspect
|
||||
result.should_not be_false
|
||||
end
|
||||
|
||||
context ".info" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::Image.info(@source_image_url)
|
||||
code, data = Qiniu::Image.info(@source_image_url)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
@@ -69,7 +69,7 @@ module Qiniu
|
||||
=begin
|
||||
context ".exif" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::Image.exif(@source_image_url)
|
||||
code, data = Qiniu::Image.exif(@source_image_url)
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
@@ -77,11 +77,11 @@ module Qiniu
|
||||
|
||||
context ".mogrify_preview_url" do
|
||||
it "should works" do
|
||||
mogrify_preview_url = Qiniu::RS::Image.mogrify_preview_url(@source_image_url, @mogrify_options)
|
||||
mogrify_preview_url = Qiniu::Image.mogrify_preview_url(@source_image_url, @mogrify_options)
|
||||
puts mogrify_preview_url.inspect
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end # module Image
|
||||
end # module Qiniu
|
||||
@@ -1,32 +1,32 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
require 'spec_helper'
|
||||
require 'qiniu/rs/auth'
|
||||
require 'qiniu/rs/io'
|
||||
require 'qiniu/auth'
|
||||
require 'qiniu/io'
|
||||
require 'digest/sha1'
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
module IO
|
||||
describe IO do
|
||||
|
||||
before :all do
|
||||
@bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s
|
||||
@key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s)
|
||||
|
||||
result = Qiniu::RS.mkbucket(@bucket)
|
||||
result = Qiniu.mkbucket(@bucket)
|
||||
puts result.inspect
|
||||
result.should be_true
|
||||
end
|
||||
|
||||
after :all do
|
||||
result = Qiniu::RS.drop(@bucket)
|
||||
result = Qiniu.drop(@bucket)
|
||||
puts result.inspect
|
||||
result.should_not be_false
|
||||
end
|
||||
|
||||
context ".put_file" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::IO.put_file(__FILE__, @bucket, @key, 'application/x-ruby', 'customMeta', true)
|
||||
code, data = Qiniu::IO.put_file(__FILE__, @bucket, @key, 'application/x-ruby', 'customMeta', true)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
@@ -35,8 +35,8 @@ module Qiniu
|
||||
context ".upload_with_token" do
|
||||
it "should works" do
|
||||
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
|
||||
uptoken = Qiniu::RS.generate_upload_token(upopts)
|
||||
code, data = Qiniu::RS::IO.upload_with_token(uptoken, __FILE__, @bucket, @key, nil, nil, nil, true)
|
||||
uptoken = Qiniu.generate_upload_token(upopts)
|
||||
code, data = Qiniu::IO.upload_with_token(uptoken, __FILE__, @bucket, @key, nil, nil, nil, true)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
@@ -45,9 +45,9 @@ module Qiniu
|
||||
context ".upload_with_token_2" do
|
||||
it "should works" do
|
||||
upopts = {:scope => @bucket, :expires_in => 3600, :endUser => "why404@gmail.com"}
|
||||
uptoken = Qiniu::RS.generate_upload_token(upopts)
|
||||
uptoken = Qiniu.generate_upload_token(upopts)
|
||||
|
||||
code, data = Qiniu::RS::IO.upload_with_token_2(uptoken, __FILE__, @key)
|
||||
code, data = Qiniu::IO.upload_with_token_2(uptoken, __FILE__, @key)
|
||||
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
@@ -55,5 +55,5 @@ module Qiniu
|
||||
end # .upload_with_token_2
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end # module IO
|
||||
end # module Qiniu
|
||||
@@ -1,30 +1,30 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
require 'spec_helper'
|
||||
require 'qiniu/rs/auth'
|
||||
require 'qiniu/rs/rs'
|
||||
require 'qiniu/rs/pub'
|
||||
require 'qiniu/auth'
|
||||
require 'qiniu'
|
||||
require 'qiniu/pub'
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
module Pub
|
||||
describe Pub do
|
||||
|
||||
before :all do
|
||||
@bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s
|
||||
result = Qiniu::RS.mkbucket(@bucket)
|
||||
result = Qiniu.mkbucket(@bucket)
|
||||
puts result.inspect
|
||||
result.should_not be_false
|
||||
end
|
||||
|
||||
after :all do
|
||||
result = Qiniu::RS.drop(@bucket)
|
||||
result = Qiniu.drop(@bucket)
|
||||
puts result.inspect
|
||||
result.should_not be_false
|
||||
end
|
||||
|
||||
context ".set_protected" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::Pub.set_protected(@bucket, 1)
|
||||
code, data = Qiniu::Pub.set_protected(@bucket, 1)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
@@ -32,7 +32,7 @@ module Qiniu
|
||||
|
||||
context ".set_separator" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::Pub.set_separator(@bucket, "-")
|
||||
code, data = Qiniu::Pub.set_separator(@bucket, "-")
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
@@ -40,7 +40,7 @@ module Qiniu
|
||||
|
||||
context ".set_style" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::Pub.set_style(@bucket, "small.jpg", "imageMogr/auto-orient/thumbnail/!120x120r/gravity/center/crop/!120x120/quality/80")
|
||||
code, data = Qiniu::Pub.set_style(@bucket, "small.jpg", "imageMogr/auto-orient/thumbnail/!120x120r/gravity/center/crop/!120x120/quality/80")
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
@@ -48,12 +48,12 @@ module Qiniu
|
||||
|
||||
context ".unset_style" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::Pub.unset_style(@bucket, "small.jpg")
|
||||
code, data = Qiniu::Pub.unset_style(@bucket, "small.jpg")
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end # module Pub
|
||||
end # module Qiniu
|
||||
Executable
+385
@@ -0,0 +1,385 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
require 'digest/sha1'
|
||||
require 'spec_helper'
|
||||
require 'qiniu/rs'
|
||||
require 'qiniu/exceptions'
|
||||
|
||||
module Qiniu
|
||||
describe RS do
|
||||
|
||||
before :all do
|
||||
@bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s
|
||||
@key = Digest::SHA1.hexdigest Time.now.to_s
|
||||
@key2 = @key + rand(100).to_s
|
||||
#@domain = @bucket + '.dn.qbox.me'
|
||||
|
||||
result = Qiniu.mkbucket(@bucket)
|
||||
result.should_not be_false
|
||||
|
||||
@test_image_bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s
|
||||
result2 = Qiniu.mkbucket(@test_image_bucket)
|
||||
puts result2.inspect
|
||||
result2.should be_true
|
||||
|
||||
@test_image_key = 'image_logo_for_test.png'
|
||||
local_file = File.expand_path('./' + @test_image_key, File.dirname(__FILE__))
|
||||
puts local_file.inspect
|
||||
upopts = {:scope => @test_image_bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
|
||||
uptoken = Qiniu.generate_upload_token(upopts)
|
||||
data = Qiniu.upload_file :uptoken => uptoken, :file => local_file, :bucket => @test_image_bucket, :key => @test_image_key
|
||||
puts data.inspect
|
||||
end
|
||||
|
||||
after :all do
|
||||
#result = Qiniu.unpublish(@domain)
|
||||
#result.should_not be_false
|
||||
|
||||
result1 = Qiniu.drop(@bucket)
|
||||
puts result1.inspect
|
||||
result1.should_not be_false
|
||||
|
||||
result2 = Qiniu.drop(@test_image_bucket)
|
||||
puts result2.inspect
|
||||
result2.should_not be_false
|
||||
end
|
||||
|
||||
context ".put_file" do
|
||||
it "should works" do
|
||||
result = Qiniu.put_file :file => __FILE__,
|
||||
:bucket => @bucket,
|
||||
:key => @key,
|
||||
:mime_type => 'application/x-ruby',
|
||||
:enable_crc32_check => true
|
||||
result.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context ".buckets" do
|
||||
it "should works" do
|
||||
result = Qiniu.buckets
|
||||
result.should_not be_false
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".set_protected" do
|
||||
it "should works" do
|
||||
result = Qiniu.set_protected(@bucket, 1)
|
||||
result.should_not be_false
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".set_separator" do
|
||||
it "should works" do
|
||||
result = Qiniu.set_separator(@bucket, "-")
|
||||
result.should_not be_false
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".set_style" do
|
||||
it "should works" do
|
||||
result = Qiniu.set_style(@bucket, "small.jpg", "imageMogr/auto-orient/thumbnail/!120x120r/gravity/center/crop/!120x120/quality/80")
|
||||
result.should_not be_false
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".unset_style" do
|
||||
it "should works" do
|
||||
result = Qiniu.unset_style(@bucket, "small.jpg")
|
||||
result.should_not be_false
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".upload_file" do
|
||||
it "should works" do
|
||||
uptoken_opts = {:scope => @bucket, :escape => 0}
|
||||
upload_opts = {
|
||||
:uptoken => Qiniu.generate_upload_token(uptoken_opts),
|
||||
:file => __FILE__,
|
||||
:bucket => @bucket,
|
||||
:key => @key,
|
||||
:enable_crc32_check => true
|
||||
}
|
||||
result = Qiniu.upload_file(upload_opts)
|
||||
result.should_not be_false
|
||||
puts result.inspect
|
||||
end
|
||||
|
||||
it "should raise MissingArgsError" do
|
||||
uptoken_opts = {:scope => @bucket, :escape => 0}
|
||||
upload_opts = {
|
||||
:uptoken => Qiniu.generate_upload_token(uptoken_opts),
|
||||
:file => __FILE__,
|
||||
:key => @key,
|
||||
:enable_crc32_check => true
|
||||
}
|
||||
lambda { Qiniu.upload_file(upload_opts) }.should raise_error(MissingArgsError)
|
||||
end
|
||||
|
||||
it "should raise NoSuchFileError" do
|
||||
uptoken_opts = {:scope => @bucket, :escape => 0}
|
||||
upload_opts = {
|
||||
:uptoken => Qiniu.generate_upload_token(uptoken_opts),
|
||||
:file => 'no_this_file',
|
||||
:bucket => @bucket,
|
||||
:key => @key,
|
||||
:enable_crc32_check => true
|
||||
}
|
||||
lambda { Qiniu.upload_file(upload_opts) }.should raise_error(NoSuchFileError)
|
||||
end
|
||||
end
|
||||
|
||||
context ".resumable_upload_file" do
|
||||
it "should works" do
|
||||
# generate bigfile for testing
|
||||
localfile = "test_bigfile"
|
||||
File.open(localfile, "w"){|f| 5242888.times{f.write(rand(9).to_s)}}
|
||||
key = Digest::SHA1.hexdigest(localfile+Time.now.to_s)
|
||||
# generate the upload token
|
||||
uptoken_opts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com", :escape => 0}
|
||||
uptoken = Qiniu.generate_upload_token(uptoken_opts)
|
||||
# uploading
|
||||
upload_opts = {
|
||||
:uptoken => uptoken,
|
||||
:file => localfile,
|
||||
:bucket => @bucket,
|
||||
:key => key
|
||||
}
|
||||
#uploading
|
||||
result1 = Qiniu.upload_file(upload_opts)
|
||||
#drop the bigfile
|
||||
File.unlink(localfile) if File.exists?(localfile)
|
||||
#expect
|
||||
puts result1.inspect
|
||||
result1.should_not be_false
|
||||
result1.should_not be_empty
|
||||
#stat
|
||||
result2 = Qiniu.stat(@bucket, key)
|
||||
puts result2.inspect
|
||||
result2.should_not be_false
|
||||
#delete
|
||||
result3 = Qiniu.delete(@bucket, key)
|
||||
puts result3.inspect
|
||||
result3.should_not be_false
|
||||
end
|
||||
end
|
||||
|
||||
context ".stat" do
|
||||
it "should works" do
|
||||
result = Qiniu.stat(@bucket, @key)
|
||||
result.should_not be_false
|
||||
result.should_not be_empty
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".get" do
|
||||
it "should works" do
|
||||
result = Qiniu.get(@bucket, @key, "rs_spec.rb", 10)
|
||||
result.should_not be_false
|
||||
result.should_not be_empty
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".download" do
|
||||
it "should works" do
|
||||
result = Qiniu.download(@bucket, @key, "rs_spec.rb", 10)
|
||||
result.should_not be_false
|
||||
result.should_not be_empty
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".batch" do
|
||||
it "should works" do
|
||||
result = Qiniu.batch("stat", @bucket, [@key])
|
||||
result.should_not be_false
|
||||
result.should_not be_empty
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".batch_stat" do
|
||||
it "should works" do
|
||||
result = Qiniu.batch_stat(@bucket, [@key])
|
||||
result.should_not be_false
|
||||
result.should_not be_empty
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".batch_get" do
|
||||
it "should works" do
|
||||
result = Qiniu.batch_get(@bucket, [@key])
|
||||
result.should_not be_false
|
||||
result.should_not be_empty
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".batch_download" do
|
||||
it "should works" do
|
||||
result = Qiniu.batch_download(@bucket, [@key])
|
||||
result.should_not be_false
|
||||
result.should_not be_empty
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
=begin
|
||||
context ".publish" do
|
||||
it "should works" do
|
||||
result = Qiniu.publish(@domain, @bucket)
|
||||
result.should_not be_false
|
||||
end
|
||||
end
|
||||
=end
|
||||
|
||||
=begin
|
||||
context ".unpublish" do
|
||||
it "should works" do
|
||||
result = Qiniu.unpublish(@domain)
|
||||
result.should_not be_false
|
||||
end
|
||||
end
|
||||
=end
|
||||
|
||||
=begin
|
||||
context ".batch_copy" do
|
||||
it "should works" do
|
||||
result = Qiniu.batch_copy [@bucket, @key, @bucket, @key2]
|
||||
result.should_not be_false
|
||||
|
||||
#result2 = Qiniu.stat(@bucket, @key2)
|
||||
#result2.should_not be_false
|
||||
end
|
||||
end
|
||||
|
||||
context ".batch_move" do
|
||||
it "should works" do
|
||||
result = Qiniu.batch_move [@bucket, @key, @bucket, @key2]
|
||||
result.should_not be_false
|
||||
|
||||
#result2 = Qiniu.stat(@bucket, @key2)
|
||||
#result2.should_not be_false
|
||||
|
||||
result3 = Qiniu.batch_move [@bucket, @key2, @bucket, @key]
|
||||
result3.should_not be_false
|
||||
end
|
||||
end
|
||||
=end
|
||||
|
||||
context ".move" do
|
||||
it "should works" do
|
||||
result = Qiniu.move(@bucket, @key, @bucket, @key2)
|
||||
result.should_not be_false
|
||||
|
||||
result2 = Qiniu.stat(@bucket, @key2)
|
||||
result2.should_not be_false
|
||||
|
||||
result3 = Qiniu.move(@bucket, @key2, @bucket, @key)
|
||||
result3.should_not be_false
|
||||
end
|
||||
end
|
||||
|
||||
context ".copy" do
|
||||
it "should works" do
|
||||
result = Qiniu.copy(@bucket, @key, @bucket, @key2)
|
||||
result.should_not be_false
|
||||
|
||||
#result2 = Qiniu.stat(@bucket, @key2)
|
||||
#result2.should_not be_false
|
||||
end
|
||||
end
|
||||
|
||||
context ".delete" do
|
||||
it "should works" do
|
||||
result = Qiniu.delete(@bucket, @key)
|
||||
result.should_not be_false
|
||||
end
|
||||
end
|
||||
|
||||
context ".drop" do
|
||||
it "should works" do
|
||||
result = Qiniu.drop(@bucket)
|
||||
result.should_not be_false
|
||||
end
|
||||
end
|
||||
|
||||
context ".image_info" do
|
||||
it "should works" do
|
||||
data = Qiniu.get(@test_image_bucket, @test_image_key)
|
||||
data.should_not be_false
|
||||
data.should_not be_empty
|
||||
puts data.inspect
|
||||
result = Qiniu.image_info(data["url"])
|
||||
result.should_not be_false
|
||||
result.should_not be_empty
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
=begin
|
||||
context ".image_exif" do
|
||||
it "should works" do
|
||||
data = Qiniu.get(@test_image_bucket, @test_image_key)
|
||||
data.should_not be_false
|
||||
data.should_not be_empty
|
||||
puts data.inspect
|
||||
result = Qiniu.image_exif(data["url"])
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
=end
|
||||
|
||||
context ".image_mogrify_save_as" do
|
||||
it "should works" do
|
||||
data = Qiniu.get(@test_image_bucket, @test_image_key)
|
||||
data.should_not be_false
|
||||
data.should_not be_empty
|
||||
puts data.inspect
|
||||
|
||||
dest_key = "cropped-" + @test_image_key
|
||||
src_img_url = data["url"]
|
||||
mogrify_options = {
|
||||
:thumbnail => "!120x120>",
|
||||
:gravity => "center",
|
||||
:crop => "!120x120a0a0",
|
||||
:quality => 85,
|
||||
:rotate => 45,
|
||||
:format => "jpg",
|
||||
:auto_orient => true
|
||||
}
|
||||
result2 = Qiniu.image_mogrify_save_as(@test_image_bucket, dest_key, src_img_url, mogrify_options)
|
||||
result2.should_not be_false
|
||||
result2.should_not be_empty
|
||||
puts result2.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".generate_upload_token" do
|
||||
it "should works" do
|
||||
data = Qiniu.generate_upload_token({:scope => @bucket, :expires_in => 3600, :escape => 0})
|
||||
data.should_not be_empty
|
||||
puts data.inspect
|
||||
data.split(":").length.should == 3
|
||||
end
|
||||
end
|
||||
|
||||
context ".generate_download_token" do
|
||||
it "should works" do
|
||||
data = Qiniu.generate_download_token({:expires_in => 1, :pattern => 'http://*.dn.qbox.me/*'})
|
||||
data.should_not be_empty
|
||||
puts data.inspect
|
||||
data.split(":").length.should == 3
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end # module Qiniu
|
||||
@@ -1,180 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
require 'digest/sha1'
|
||||
require 'spec_helper'
|
||||
require 'qiniu/rs/auth'
|
||||
require 'qiniu/rs/io'
|
||||
require 'qiniu/rs/rs'
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
describe RS do
|
||||
|
||||
before :all do
|
||||
@bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s
|
||||
@key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s)
|
||||
@key2 = @key + rand(100).to_s
|
||||
#@domain = @bucket + '.dn.qbox.me'
|
||||
|
||||
code, data = Qiniu::RS::RS.mkbucket(@bucket)
|
||||
puts [code, data].inspect
|
||||
code.should == 200
|
||||
end
|
||||
|
||||
after :all do
|
||||
code, data = Qiniu::RS::RS.drop(@bucket)
|
||||
puts [code, data].inspect
|
||||
code.should == 200
|
||||
end
|
||||
|
||||
context ".put_file" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::IO.put_file(__FILE__, @bucket, @key, 'application/x-ruby', 'customMeta', true)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".buckets" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::RS.buckets
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".stat" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::RS.stat(@bucket, @key)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".get" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::RS.get(@bucket, @key, "rs_spec.rb", 1)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".batch" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::RS.batch("stat", @bucket, [@key])
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".batch_stat" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::RS.batch_stat(@bucket, [@key])
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".batch_get" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::RS.batch_get(@bucket, [@key])
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
|
||||
=begin
|
||||
context ".batch_copy" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::RS.batch_copy [@bucket, @key, @bucket, @key2]
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
|
||||
#code2, data2 = Qiniu::RS::RS.stat(@bucket, @key2)
|
||||
#code2.should == 200
|
||||
#puts data2.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".batch_move" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::RS.batch_move [@bucket, @key, @bucket, @key2]
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
|
||||
#code2, data2 = Qiniu::RS::RS.stat(@bucket, @key2)
|
||||
#code2.should == 200
|
||||
#puts data2.inspect
|
||||
|
||||
code3, data3 = Qiniu::RS::RS.batch_move [@bucket, @key2, @bucket, @key]
|
||||
code3.should == 200
|
||||
puts data3.inspect
|
||||
end
|
||||
end
|
||||
=end
|
||||
|
||||
=begin
|
||||
context ".publish" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::RS.publish(@domain, @bucket)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".unpublish" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::RS.unpublish(@domain)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
=end
|
||||
|
||||
context ".move" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::RS.move(@bucket, @key, @bucket, @key2)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
|
||||
code2, data2 = Qiniu::RS::RS.stat(@bucket, @key2)
|
||||
code2.should == 200
|
||||
puts data2.inspect
|
||||
|
||||
code3, data3 = Qiniu::RS::RS.move(@bucket, @key2, @bucket, @key)
|
||||
code3.should == 200
|
||||
puts data3.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".copy" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::RS.copy(@bucket, @key, @bucket, @key2)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
|
||||
#code2, data2 = Qiniu::RS::RS.stat(@bucket, @key2)
|
||||
#code2.should == 200
|
||||
#puts data2.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".delete" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::RS.delete(@bucket, @key)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".drop" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::RS.drop(@bucket)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,10 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
require 'spec_helper'
|
||||
require 'qiniu/rs/version'
|
||||
|
||||
describe Qiniu::RS::Version do
|
||||
it "should has a VERSION" do
|
||||
Qiniu::RS::Version.to_s.should =~ /^\d+\.\d+\.\d+?$/
|
||||
end
|
||||
end
|
||||
+134
-339
@@ -2,384 +2,179 @@
|
||||
|
||||
require 'digest/sha1'
|
||||
require 'spec_helper'
|
||||
require 'qiniu/rs'
|
||||
require 'qiniu/rs/exceptions'
|
||||
require 'qiniu/auth'
|
||||
require 'qiniu/io'
|
||||
require 'qiniu'
|
||||
|
||||
module Qiniu
|
||||
describe RS do
|
||||
module RS
|
||||
describe RS do
|
||||
|
||||
before :all do
|
||||
@bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s
|
||||
@key = Digest::SHA1.hexdigest Time.now.to_s
|
||||
@key2 = @key + rand(100).to_s
|
||||
#@domain = @bucket + '.dn.qbox.me'
|
||||
before :all do
|
||||
@bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s
|
||||
@key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s)
|
||||
@key2 = @key + rand(100).to_s
|
||||
#@domain = @bucket + '.dn.qbox.me'
|
||||
|
||||
result = Qiniu::RS.mkbucket(@bucket)
|
||||
result.should_not be_false
|
||||
|
||||
@test_image_bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s
|
||||
result2 = Qiniu::RS.mkbucket(@test_image_bucket)
|
||||
puts result2.inspect
|
||||
result2.should be_true
|
||||
|
||||
@test_image_key = 'image_logo_for_test.png'
|
||||
local_file = File.expand_path('./rs/' + @test_image_key, File.dirname(__FILE__))
|
||||
puts local_file.inspect
|
||||
upopts = {:scope => @test_image_bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
|
||||
uptoken = Qiniu::RS.generate_upload_token(upopts)
|
||||
data = Qiniu::RS.upload_file :uptoken => uptoken, :file => local_file, :bucket => @test_image_bucket, :key => @test_image_key
|
||||
puts data.inspect
|
||||
end
|
||||
|
||||
after :all do
|
||||
#result = Qiniu::RS.unpublish(@domain)
|
||||
#result.should_not be_false
|
||||
|
||||
result1 = Qiniu::RS.drop(@bucket)
|
||||
puts result1.inspect
|
||||
result1.should_not be_false
|
||||
|
||||
result2 = Qiniu::RS.drop(@test_image_bucket)
|
||||
puts result2.inspect
|
||||
result2.should_not be_false
|
||||
end
|
||||
|
||||
context ".put_file" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.put_file :file => __FILE__,
|
||||
:bucket => @bucket,
|
||||
:key => @key,
|
||||
:mime_type => 'application/x-ruby',
|
||||
:enable_crc32_check => true
|
||||
result.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context ".buckets" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.buckets
|
||||
result.should_not be_false
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".set_protected" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.set_protected(@bucket, 1)
|
||||
result.should_not be_false
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".set_separator" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.set_separator(@bucket, "-")
|
||||
result.should_not be_false
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".set_style" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.set_style(@bucket, "small.jpg", "imageMogr/auto-orient/thumbnail/!120x120r/gravity/center/crop/!120x120/quality/80")
|
||||
result.should_not be_false
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".unset_style" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.unset_style(@bucket, "small.jpg")
|
||||
result.should_not be_false
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".upload_file" do
|
||||
it "should works" do
|
||||
uptoken_opts = {:scope => @bucket, :escape => 0}
|
||||
upload_opts = {
|
||||
:uptoken => Qiniu::RS.generate_upload_token(uptoken_opts),
|
||||
:file => __FILE__,
|
||||
:bucket => @bucket,
|
||||
:key => @key,
|
||||
:enable_crc32_check => true
|
||||
}
|
||||
result = Qiniu::RS.upload_file(upload_opts)
|
||||
result.should_not be_false
|
||||
puts result.inspect
|
||||
code, data = Qiniu::RS.mkbucket(@bucket)
|
||||
puts [code, data].inspect
|
||||
code.should == 200
|
||||
end
|
||||
|
||||
it "should raise MissingArgsError" do
|
||||
uptoken_opts = {:scope => @bucket, :escape => 0}
|
||||
upload_opts = {
|
||||
:uptoken => Qiniu::RS.generate_upload_token(uptoken_opts),
|
||||
:file => __FILE__,
|
||||
:key => @key,
|
||||
:enable_crc32_check => true
|
||||
}
|
||||
lambda { Qiniu::RS.upload_file(upload_opts) }.should raise_error(RS::MissingArgsError)
|
||||
after :all do
|
||||
code, data = Qiniu::RS.drop(@bucket)
|
||||
puts [code, data].inspect
|
||||
code.should == 200
|
||||
end
|
||||
|
||||
it "should raise NoSuchFileError" do
|
||||
uptoken_opts = {:scope => @bucket, :escape => 0}
|
||||
upload_opts = {
|
||||
:uptoken => Qiniu::RS.generate_upload_token(uptoken_opts),
|
||||
:file => 'no_this_file',
|
||||
:bucket => @bucket,
|
||||
:key => @key,
|
||||
:enable_crc32_check => true
|
||||
}
|
||||
lambda { Qiniu::RS.upload_file(upload_opts) }.should raise_error(RS::NoSuchFileError)
|
||||
context ".put_file" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::IO.put_file(__FILE__, @bucket, @key, 'application/x-ruby', 'customMeta', true)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context ".resumable_upload_file" do
|
||||
it "should works" do
|
||||
# generate bigfile for testing
|
||||
localfile = "test_bigfile"
|
||||
File.open(localfile, "w"){|f| 5242888.times{f.write(rand(9).to_s)}}
|
||||
key = Digest::SHA1.hexdigest(localfile+Time.now.to_s)
|
||||
# generate the upload token
|
||||
uptoken_opts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com", :escape => 0}
|
||||
uptoken = Qiniu::RS.generate_upload_token(uptoken_opts)
|
||||
# uploading
|
||||
upload_opts = {
|
||||
:uptoken => uptoken,
|
||||
:file => localfile,
|
||||
:bucket => @bucket,
|
||||
:key => key
|
||||
}
|
||||
#uploading
|
||||
result1 = Qiniu::RS.upload_file(upload_opts)
|
||||
#drop the bigfile
|
||||
File.unlink(localfile) if File.exists?(localfile)
|
||||
#expect
|
||||
puts result1.inspect
|
||||
result1.should_not be_false
|
||||
result1.should_not be_empty
|
||||
#stat
|
||||
result2 = Qiniu::RS.stat(@bucket, key)
|
||||
puts result2.inspect
|
||||
result2.should_not be_false
|
||||
#delete
|
||||
result3 = Qiniu::RS.delete(@bucket, key)
|
||||
puts result3.inspect
|
||||
result3.should_not be_false
|
||||
context ".buckets" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS.buckets
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context ".stat" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.stat(@bucket, @key)
|
||||
result.should_not be_false
|
||||
result.should_not be_empty
|
||||
puts result.inspect
|
||||
context ".stat" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS.stat(@bucket, @key)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context ".get" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.get(@bucket, @key, "rs_spec.rb", 10)
|
||||
result.should_not be_false
|
||||
result.should_not be_empty
|
||||
puts result.inspect
|
||||
context ".get" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS.get(@bucket, @key, "rs_spec.rb", 1)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context ".download" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.download(@bucket, @key, "rs_spec.rb", 10)
|
||||
result.should_not be_false
|
||||
result.should_not be_empty
|
||||
puts result.inspect
|
||||
context ".batch" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS.batch("stat", @bucket, [@key])
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context ".batch" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.batch("stat", @bucket, [@key])
|
||||
result.should_not be_false
|
||||
result.should_not be_empty
|
||||
puts result.inspect
|
||||
context ".batch_stat" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS.batch_stat(@bucket, [@key])
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context ".batch_stat" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.batch_stat(@bucket, [@key])
|
||||
result.should_not be_false
|
||||
result.should_not be_empty
|
||||
puts result.inspect
|
||||
context ".batch_get" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS.batch_get(@bucket, [@key])
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context ".batch_get" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.batch_get(@bucket, [@key])
|
||||
result.should_not be_false
|
||||
result.should_not be_empty
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".batch_download" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.batch_download(@bucket, [@key])
|
||||
result.should_not be_false
|
||||
result.should_not be_empty
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
=begin
|
||||
context ".publish" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.publish(@domain, @bucket)
|
||||
result.should_not be_false
|
||||
context ".batch_copy" do
|
||||
it "should works" do
|
||||
code, data = Qiniu.batch_copy [@bucket, @key, @bucket, @key2]
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
|
||||
#code2, data2 = Qiniu.stat(@bucket, @key2)
|
||||
#code2.should == 200
|
||||
#puts data2.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".batch_move" do
|
||||
it "should works" do
|
||||
code, data = Qiniu.batch_move [@bucket, @key, @bucket, @key2]
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
|
||||
#code2, data2 = Qiniu.stat(@bucket, @key2)
|
||||
#code2.should == 200
|
||||
#puts data2.inspect
|
||||
|
||||
code3, data3 = Qiniu.batch_move [@bucket, @key2, @bucket, @key]
|
||||
code3.should == 200
|
||||
puts data3.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
=end
|
||||
|
||||
=begin
|
||||
context ".unpublish" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.unpublish(@domain)
|
||||
result.should_not be_false
|
||||
context ".publish" do
|
||||
it "should works" do
|
||||
code, data = Qiniu.publish(@domain, @bucket)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".unpublish" do
|
||||
it "should works" do
|
||||
code, data = Qiniu.unpublish(@domain)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
=end
|
||||
|
||||
=begin
|
||||
context ".batch_copy" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.batch_copy [@bucket, @key, @bucket, @key2]
|
||||
result.should_not be_false
|
||||
context ".move" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS.move(@bucket, @key, @bucket, @key2)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
|
||||
#result2 = Qiniu::RS.stat(@bucket, @key2)
|
||||
#result2.should_not be_false
|
||||
code2, data2 = Qiniu::RS.stat(@bucket, @key2)
|
||||
code2.should == 200
|
||||
puts data2.inspect
|
||||
|
||||
code3, data3 = Qiniu::RS.move(@bucket, @key2, @bucket, @key)
|
||||
code3.should == 200
|
||||
puts data3.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context ".batch_move" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS::RS.batch_move [@bucket, @key, @bucket, @key2]
|
||||
result.should_not be_false
|
||||
context ".copy" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS.copy(@bucket, @key, @bucket, @key2)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
|
||||
#result2 = Qiniu::RS.stat(@bucket, @key2)
|
||||
#result2.should_not be_false
|
||||
|
||||
result3 = Qiniu::RS.batch_move [@bucket, @key2, @bucket, @key]
|
||||
result3.should_not be_false
|
||||
#code2, data2 = Qiniu.stat(@bucket, @key2)
|
||||
#code2.should == 200
|
||||
#puts data2.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
=end
|
||||
|
||||
context ".move" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.move(@bucket, @key, @bucket, @key2)
|
||||
result.should_not be_false
|
||||
|
||||
result2 = Qiniu::RS.stat(@bucket, @key2)
|
||||
result2.should_not be_false
|
||||
|
||||
result3 = Qiniu::RS.move(@bucket, @key2, @bucket, @key)
|
||||
result3.should_not be_false
|
||||
context ".delete" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS.delete(@bucket, @key)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context ".copy" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.copy(@bucket, @key, @bucket, @key2)
|
||||
result.should_not be_false
|
||||
|
||||
#result2 = Qiniu::RS.stat(@bucket, @key2)
|
||||
#result2.should_not be_false
|
||||
context ".drop" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS.drop(@bucket)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context ".delete" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.delete(@bucket, @key)
|
||||
result.should_not be_false
|
||||
end
|
||||
end
|
||||
|
||||
context ".drop" do
|
||||
it "should works" do
|
||||
result = Qiniu::RS.drop(@bucket)
|
||||
result.should_not be_false
|
||||
end
|
||||
end
|
||||
|
||||
context ".image_info" do
|
||||
it "should works" do
|
||||
data = Qiniu::RS.get(@test_image_bucket, @test_image_key)
|
||||
data.should_not be_false
|
||||
data.should_not be_empty
|
||||
puts data.inspect
|
||||
result = Qiniu::RS.image_info(data["url"])
|
||||
result.should_not be_false
|
||||
result.should_not be_empty
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
|
||||
=begin
|
||||
context ".image_exif" do
|
||||
it "should works" do
|
||||
data = Qiniu::RS.get(@test_image_bucket, @test_image_key)
|
||||
data.should_not be_false
|
||||
data.should_not be_empty
|
||||
puts data.inspect
|
||||
result = Qiniu::RS.image_exif(data["url"])
|
||||
puts result.inspect
|
||||
end
|
||||
end
|
||||
=end
|
||||
|
||||
context ".image_mogrify_save_as" do
|
||||
it "should works" do
|
||||
data = Qiniu::RS.get(@test_image_bucket, @test_image_key)
|
||||
data.should_not be_false
|
||||
data.should_not be_empty
|
||||
puts data.inspect
|
||||
|
||||
dest_key = "cropped-" + @test_image_key
|
||||
src_img_url = data["url"]
|
||||
mogrify_options = {
|
||||
:thumbnail => "!120x120>",
|
||||
:gravity => "center",
|
||||
:crop => "!120x120a0a0",
|
||||
:quality => 85,
|
||||
:rotate => 45,
|
||||
:format => "jpg",
|
||||
:auto_orient => true
|
||||
}
|
||||
result2 = Qiniu::RS.image_mogrify_save_as(@test_image_bucket, dest_key, src_img_url, mogrify_options)
|
||||
result2.should_not be_false
|
||||
result2.should_not be_empty
|
||||
puts result2.inspect
|
||||
end
|
||||
end
|
||||
|
||||
context ".generate_upload_token" do
|
||||
it "should works" do
|
||||
data = Qiniu::RS.generate_upload_token({:scope => @bucket, :expires_in => 3600, :escape => 0})
|
||||
data.should_not be_empty
|
||||
puts data.inspect
|
||||
data.split(":").length.should == 3
|
||||
end
|
||||
end
|
||||
|
||||
context ".generate_download_token" do
|
||||
it "should works" do
|
||||
data = Qiniu::RS.generate_download_token({:expires_in => 1, :pattern => 'http://*.dn.qbox.me/*'})
|
||||
data.should_not be_empty
|
||||
puts data.inspect
|
||||
data.split(":").length.should == 3
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,32 +2,32 @@
|
||||
|
||||
require 'digest/sha1'
|
||||
require 'spec_helper'
|
||||
require 'qiniu/rs/rs'
|
||||
require 'qiniu/rs/up'
|
||||
require 'qiniu'
|
||||
require 'qiniu/up'
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
module UP
|
||||
describe UP do
|
||||
|
||||
before :all do
|
||||
@localfile = "bigfile.txt"
|
||||
File.open(@localfile, "w"){|f| 5242888.times{f.write(rand(9).to_s)}}
|
||||
File.open(@localfile, "w"){|f| 5242888.times{ f.write(rand(9).to_s) }}
|
||||
@bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s
|
||||
@key = Digest::SHA1.hexdigest(@localfile+Time.now.to_s)
|
||||
|
||||
@localfile2 = "bigfile2.txt"
|
||||
File.open(@localfile2, "w"){|f| (1 << 22).times{f.write(rand(9).to_s)}}
|
||||
File.open(@localfile2, "w"){|f| (1 << 22).times{ f.write(rand(9).to_s) }}
|
||||
@key2 = Digest::SHA1.hexdigest(@localfile2+Time.now.to_s)
|
||||
|
||||
@localfile3 = "bigfile3.txt"
|
||||
File.open(@localfile3, "w"){|f| (1 << 23).times{f.write(rand(9).to_s)}}
|
||||
File.open(@localfile3, "w"){|f| (1 << 23).times{ f.write(rand(9).to_s) }}
|
||||
@key3 = Digest::SHA1.hexdigest(@localfile3+Time.now.to_s)
|
||||
|
||||
@localfile4 = "smallfile.txt"
|
||||
File.open(@localfile4, "w"){|f| (1 << 20).times{f.write(rand(9).to_s)}}
|
||||
File.open(@localfile4, "w"){|f| (1 << 20).times{ f.write(rand(9).to_s) }}
|
||||
@key4 = Digest::SHA1.hexdigest(@localfile4+Time.now.to_s)
|
||||
|
||||
code, data = Qiniu::RS::RS.mkbucket(@bucket)
|
||||
code, data = Qiniu::RS.mkbucket(@bucket)
|
||||
puts [code, data].inspect
|
||||
code.should == 200
|
||||
end
|
||||
@@ -38,7 +38,7 @@ module Qiniu
|
||||
File.unlink(@localfile3) if File.exists?(@localfile3)
|
||||
File.unlink(@localfile4) if File.exists?(@localfile4)
|
||||
|
||||
code, data = Qiniu::RS::RS.drop(@bucket)
|
||||
code, data = Qiniu::RS.drop(@bucket)
|
||||
puts [code, data].inspect
|
||||
code.should == 200
|
||||
end
|
||||
@@ -46,8 +46,8 @@ module Qiniu
|
||||
context ".upload_with_token" do
|
||||
it "should works" do
|
||||
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
|
||||
uptoken = Qiniu::RS.generate_upload_token(upopts)
|
||||
code, data = Qiniu::RS::UP.upload_with_token(uptoken, @localfile, @bucket, @key)
|
||||
uptoken = Qiniu.generate_upload_token(upopts)
|
||||
code, data = Qiniu::UP.upload_with_token(uptoken, @localfile, @bucket, @key)
|
||||
puts data.inspect
|
||||
(code/100).should == 2
|
||||
end
|
||||
@@ -55,7 +55,7 @@ module Qiniu
|
||||
|
||||
context ".stat" do
|
||||
it "should exists" do
|
||||
code, data = Qiniu::RS::RS.stat(@bucket, @key)
|
||||
code, data = Qiniu::RS.stat(@bucket, @key)
|
||||
puts data.inspect
|
||||
code.should == 200
|
||||
end
|
||||
@@ -63,7 +63,7 @@ module Qiniu
|
||||
|
||||
context ".delete" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::RS.delete(@bucket, @key)
|
||||
code, data = Qiniu::RS.delete(@bucket, @key)
|
||||
puts data.inspect
|
||||
code.should == 200
|
||||
end
|
||||
@@ -72,8 +72,8 @@ module Qiniu
|
||||
context ".upload_with_token2" do
|
||||
it "should works" do
|
||||
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
|
||||
uptoken = Qiniu::RS.generate_upload_token(upopts)
|
||||
code, data = Qiniu::RS::UP.upload_with_token(uptoken, @localfile2, @bucket, @key2)
|
||||
uptoken = Qiniu.generate_upload_token(upopts)
|
||||
code, data = Qiniu::UP.upload_with_token(uptoken, @localfile2, @bucket, @key2)
|
||||
puts data.inspect
|
||||
(code/100).should == 2
|
||||
end
|
||||
@@ -81,7 +81,7 @@ module Qiniu
|
||||
|
||||
context ".stat" do
|
||||
it "should exists" do
|
||||
code, data = Qiniu::RS::RS.stat(@bucket, @key2)
|
||||
code, data = Qiniu::RS.stat(@bucket, @key2)
|
||||
puts data.inspect
|
||||
code.should == 200
|
||||
end
|
||||
@@ -89,7 +89,7 @@ module Qiniu
|
||||
|
||||
context ".delete" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::RS.delete(@bucket, @key2)
|
||||
code, data = Qiniu::RS.delete(@bucket, @key2)
|
||||
puts data.inspect
|
||||
code.should == 200
|
||||
end
|
||||
@@ -98,8 +98,8 @@ module Qiniu
|
||||
context ".upload_with_token3" do
|
||||
it "should works" do
|
||||
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
|
||||
uptoken = Qiniu::RS.generate_upload_token(upopts)
|
||||
code, data = Qiniu::RS::UP.upload_with_token(uptoken, @localfile3, @bucket, @key3)
|
||||
uptoken = Qiniu.generate_upload_token(upopts)
|
||||
code, data = Qiniu::UP.upload_with_token(uptoken, @localfile3, @bucket, @key3)
|
||||
puts data.inspect
|
||||
(code/100).should == 2
|
||||
end
|
||||
@@ -107,7 +107,7 @@ module Qiniu
|
||||
|
||||
context ".stat" do
|
||||
it "should exists" do
|
||||
code, data = Qiniu::RS::RS.stat(@bucket, @key3)
|
||||
code, data = Qiniu::RS.stat(@bucket, @key3)
|
||||
puts data.inspect
|
||||
code.should == 200
|
||||
end
|
||||
@@ -115,7 +115,7 @@ module Qiniu
|
||||
|
||||
context ".delete" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::RS.delete(@bucket, @key3)
|
||||
code, data = Qiniu::RS.delete(@bucket, @key3)
|
||||
puts data.inspect
|
||||
code.should == 200
|
||||
end
|
||||
@@ -124,8 +124,8 @@ module Qiniu
|
||||
context ".upload_with_token4" do
|
||||
it "should works" do
|
||||
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
|
||||
uptoken = Qiniu::RS.generate_upload_token(upopts)
|
||||
code, data = Qiniu::RS::UP.upload_with_token(uptoken, @localfile4, @bucket, @key4)
|
||||
uptoken = Qiniu.generate_upload_token(upopts)
|
||||
code, data = Qiniu::UP.upload_with_token(uptoken, @localfile4, @bucket, @key4)
|
||||
puts data.inspect
|
||||
(code/100).should == 2
|
||||
end
|
||||
@@ -133,7 +133,7 @@ module Qiniu
|
||||
|
||||
context ".stat" do
|
||||
it "should exists" do
|
||||
code, data = Qiniu::RS::RS.stat(@bucket, @key4)
|
||||
code, data = Qiniu::RS.stat(@bucket, @key4)
|
||||
puts data.inspect
|
||||
code.should == 200
|
||||
end
|
||||
@@ -141,12 +141,12 @@ module Qiniu
|
||||
|
||||
context ".delete" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::RS::RS.delete(@bucket, @key4)
|
||||
code, data = Qiniu::RS.delete(@bucket, @key4)
|
||||
puts data.inspect
|
||||
code.should == 200
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end # module UP
|
||||
end # module Qiniu
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
require 'spec_helper'
|
||||
require 'fakeweb'
|
||||
require 'qiniu/rs/utils'
|
||||
require 'qiniu/utils'
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
require 'spec_helper'
|
||||
require 'qiniu/version'
|
||||
|
||||
describe Qiniu::Version do
|
||||
it "should has a VERSION" do
|
||||
Qiniu::Version.to_s.should =~ /^\d+\.\d+\.\d+?$/
|
||||
end
|
||||
end
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
require 'bundler/setup'
|
||||
require 'qiniu/rs'
|
||||
require 'qiniu'
|
||||
require 'rspec'
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.before :all do
|
||||
Qiniu::RS.establish_connection! :access_key => ENV["QINIU_ACCESS_KEY"], :secret_key => ENV["QINIU_SECRET_KEY"]
|
||||
Qiniu.establish_connection! :access_key => ENV["QINIU_ACCESS_KEY"], :secret_key => ENV["QINIU_SECRET_KEY"]
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user