diff --git a/lib/qiniu-rs.rb b/lib/qiniu-rs.rb index 75057b3..1c54a93 100755 --- a/lib/qiniu-rs.rb +++ b/lib/qiniu-rs.rb @@ -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') diff --git a/lib/qiniu.rb b/lib/qiniu.rb new file mode 100755 index 0000000..c766a04 --- /dev/null +++ b/lib/qiniu.rb @@ -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 diff --git a/lib/qiniu/rs/abstract.rb b/lib/qiniu/abstract.rb similarity index 92% rename from lib/qiniu/rs/abstract.rb rename to lib/qiniu/abstract.rb index d9fc671..af32cba 100644 --- a/lib/qiniu/rs/abstract.rb +++ b/lib/qiniu/abstract.rb @@ -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 diff --git a/lib/qiniu/rs/auth.rb b/lib/qiniu/auth.rb similarity index 88% rename from lib/qiniu/rs/auth.rb rename to lib/qiniu/auth.rb index 9c688c6..38b4813 100755 --- a/lib/qiniu/rs/auth.rb +++ b/lib/qiniu/auth.rb @@ -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 diff --git a/lib/qiniu/rs/config.rb b/lib/qiniu/config.rb similarity index 97% rename from lib/qiniu/rs/config.rb rename to lib/qiniu/config.rb index d7f65df..53216c3 100755 --- a/lib/qiniu/rs/config.rb +++ b/lib/qiniu/config.rb @@ -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 diff --git a/lib/qiniu/rs/exceptions.rb b/lib/qiniu/exceptions.rb similarity index 99% rename from lib/qiniu/rs/exceptions.rb rename to lib/qiniu/exceptions.rb index fa123f9..352da9c 100755 --- a/lib/qiniu/rs/exceptions.rb +++ b/lib/qiniu/exceptions.rb @@ -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 diff --git a/lib/qiniu/rs/image.rb b/lib/qiniu/image.rb similarity index 95% rename from lib/qiniu/rs/image.rb rename to lib/qiniu/image.rb index 9dbdf7c..0d7aa95 100755 --- a/lib/qiniu/rs/image.rb +++ b/lib/qiniu/image.rb @@ -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 diff --git a/lib/qiniu/rs/io.rb b/lib/qiniu/io.rb similarity index 97% rename from lib/qiniu/rs/io.rb rename to lib/qiniu/io.rb index 934d027..b8311b8 100755 --- a/lib/qiniu/rs/io.rb +++ b/lib/qiniu/io.rb @@ -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 diff --git a/lib/qiniu/rs/log.rb b/lib/qiniu/log.rb similarity index 83% rename from lib/qiniu/rs/log.rb rename to lib/qiniu/log.rb index 0a3c8a0..490fe56 100755 --- a/lib/qiniu/rs/log.rb +++ b/lib/qiniu/log.rb @@ -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 diff --git a/lib/qiniu/rs/pub.rb b/lib/qiniu/pub.rb similarity index 96% rename from lib/qiniu/rs/pub.rb rename to lib/qiniu/pub.rb index b1e4df2..b384d0c 100755 --- a/lib/qiniu/rs/pub.rb +++ b/lib/qiniu/pub.rb @@ -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 diff --git a/lib/qiniu/rs.rb b/lib/qiniu/rs.rb index d15216f..9ba9ff2 100755 --- a/lib/qiniu/rs.rb +++ b/lib/qiniu/rs.rb @@ -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 diff --git a/lib/qiniu/rs/rs.rb b/lib/qiniu/rs/rs.rb deleted file mode 100755 index d95c7b6..0000000 --- a/lib/qiniu/rs/rs.rb +++ /dev/null @@ -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 diff --git a/lib/qiniu/tokens/access_token.rb b/lib/qiniu/tokens/access_token.rb index 78aa99a..43534e0 100755 --- a/lib/qiniu/tokens/access_token.rb +++ b/lib/qiniu/tokens/access_token.rb @@ -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 diff --git a/lib/qiniu/tokens/download_token.rb b/lib/qiniu/tokens/download_token.rb index f681520..ccf75a5 100755 --- a/lib/qiniu/tokens/download_token.rb +++ b/lib/qiniu/tokens/download_token.rb @@ -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 diff --git a/lib/qiniu/tokens/qbox_token.rb b/lib/qiniu/tokens/qbox_token.rb index 8ccdb0c..bca67c2 100755 --- a/lib/qiniu/tokens/qbox_token.rb +++ b/lib/qiniu/tokens/qbox_token.rb @@ -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 diff --git a/lib/qiniu/tokens/upload_token.rb b/lib/qiniu/tokens/upload_token.rb index d2fae00..c5202f8 100755 --- a/lib/qiniu/tokens/upload_token.rb +++ b/lib/qiniu/tokens/upload_token.rb @@ -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 diff --git a/lib/qiniu/rs/up.rb b/lib/qiniu/up.rb similarity index 98% rename from lib/qiniu/rs/up.rb rename to lib/qiniu/up.rb index 55a603a..0ed2fe9 100755 --- a/lib/qiniu/rs/up.rb +++ b/lib/qiniu/up.rb @@ -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 diff --git a/lib/qiniu/rs/utils.rb b/lib/qiniu/utils.rb similarity index 98% rename from lib/qiniu/rs/utils.rb rename to lib/qiniu/utils.rb index 3c0d169..290d3db 100755 --- a/lib/qiniu/rs/utils.rb +++ b/lib/qiniu/utils.rb @@ -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 diff --git a/lib/qiniu/rs/version.rb b/lib/qiniu/version.rb similarity index 90% rename from lib/qiniu/rs/version.rb rename to lib/qiniu/version.rb index c74a1b0..c6e5ea3 100755 --- a/lib/qiniu/rs/version.rb +++ b/lib/qiniu/version.rb @@ -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 diff --git a/spec/qiniu/rs/abstract_spec.rb b/spec/qiniu/abstract_spec.rb similarity index 82% rename from spec/qiniu/rs/abstract_spec.rb rename to spec/qiniu/abstract_spec.rb index e69af62..372cf33 100755 --- a/spec/qiniu/rs/abstract_spec.rb +++ b/spec/qiniu/abstract_spec.rb @@ -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 diff --git a/spec/qiniu/rs/image_logo_for_test.png b/spec/qiniu/image_logo_for_test.png similarity index 100% rename from spec/qiniu/rs/image_logo_for_test.png rename to spec/qiniu/image_logo_for_test.png diff --git a/spec/qiniu/rs/image_spec.rb b/spec/qiniu/image_spec.rb similarity index 74% rename from spec/qiniu/rs/image_spec.rb rename to spec/qiniu/image_spec.rb index 5cfee7e..d21d347 100755 --- a/spec/qiniu/rs/image_spec.rb +++ b/spec/qiniu/image_spec.rb @@ -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 diff --git a/spec/qiniu/rs/io_spec.rb b/spec/qiniu/io_spec.rb similarity index 65% rename from spec/qiniu/rs/io_spec.rb rename to spec/qiniu/io_spec.rb index 1db2555..9b596fb 100755 --- a/spec/qiniu/rs/io_spec.rb +++ b/spec/qiniu/io_spec.rb @@ -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 diff --git a/spec/qiniu/rs/pub_spec.rb b/spec/qiniu/pub_spec.rb similarity index 63% rename from spec/qiniu/rs/pub_spec.rb rename to spec/qiniu/pub_spec.rb index 1addab7..03c2d60 100755 --- a/spec/qiniu/rs/pub_spec.rb +++ b/spec/qiniu/pub_spec.rb @@ -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 diff --git a/spec/qiniu/qiniu_spec.rb b/spec/qiniu/qiniu_spec.rb new file mode 100755 index 0000000..5f39dfb --- /dev/null +++ b/spec/qiniu/qiniu_spec.rb @@ -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 diff --git a/spec/qiniu/rs/rs_spec.rb b/spec/qiniu/rs/rs_spec.rb deleted file mode 100755 index 3954c85..0000000 --- a/spec/qiniu/rs/rs_spec.rb +++ /dev/null @@ -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 diff --git a/spec/qiniu/rs/version_spec.rb b/spec/qiniu/rs/version_spec.rb deleted file mode 100755 index 4df286b..0000000 --- a/spec/qiniu/rs/version_spec.rb +++ /dev/null @@ -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 diff --git a/spec/qiniu/rs_spec.rb b/spec/qiniu/rs_spec.rb index 4665b12..cc6bc31 100755 --- a/spec/qiniu/rs_spec.rb +++ b/spec/qiniu/rs_spec.rb @@ -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 diff --git a/spec/qiniu/rs/up_spec.rb b/spec/qiniu/up_spec.rb similarity index 66% rename from spec/qiniu/rs/up_spec.rb rename to spec/qiniu/up_spec.rb index 0c22a34..dd82c2e 100755 --- a/spec/qiniu/rs/up_spec.rb +++ b/spec/qiniu/up_spec.rb @@ -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 diff --git a/spec/qiniu/rs/utils_spec.rb b/spec/qiniu/utils_spec.rb similarity index 98% rename from spec/qiniu/rs/utils_spec.rb rename to spec/qiniu/utils_spec.rb index 74606c8..fb00074 100755 --- a/spec/qiniu/rs/utils_spec.rb +++ b/spec/qiniu/utils_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' require 'fakeweb' -require 'qiniu/rs/utils' +require 'qiniu/utils' module Qiniu module RS diff --git a/spec/qiniu/version_spec.rb b/spec/qiniu/version_spec.rb new file mode 100755 index 0000000..654ae04 --- /dev/null +++ b/spec/qiniu/version_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e4a899f..e695e04 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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