From ab81095c0cc9e943fefff6b00ea14b781a683836 Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Thu, 6 Mar 2014 15:33:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=92=E5=88=86=E5=87=BAFop=E4=B8=8EMisc?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/qiniu.rb | 18 +++++++++--------- lib/qiniu/fop.rb | 3 +++ lib/qiniu/image.rb | 2 ++ lib/qiniu/management.rb | 2 +- lib/qiniu/{pub.rb => misc.rb} | 4 ++-- spec/qiniu/image_spec.rb | 14 +++++++------- spec/qiniu/{pub_spec.rb => misc_spec.rb} | 16 ++++++++-------- 7 files changed, 32 insertions(+), 27 deletions(-) create mode 100755 lib/qiniu/fop.rb rename lib/qiniu/{pub.rb => misc.rb} (96%) rename spec/qiniu/{pub_spec.rb => misc_spec.rb} (70%) diff --git a/lib/qiniu.rb b/lib/qiniu.rb index dd66f06..49c3658 100755 --- a/lib/qiniu.rb +++ b/lib/qiniu.rb @@ -7,14 +7,14 @@ module Qiniu autoload :Config, 'qiniu/config' autoload :Log, 'qiniu/log' autoload :Exception, 'qiniu/exceptions' - 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' autoload :Storage, 'qiniu/storage' + autoload :Fop, 'qiniu/fop' + autoload :Misc, 'qiniu/misc' class << self @@ -35,22 +35,22 @@ module Qiniu end def set_protected(bucket, protected_mode) - code, data = Pub.set_protected(bucket, protected_mode) + code, data = Misc.set_protected(bucket, protected_mode) code == StatusOK end def set_separator(bucket, separator) - code, data = Pub.set_separator(bucket, separator) + code, data = Misc.set_separator(bucket, separator) code == StatusOK end def set_style(bucket, name, style) - code, data = Pub.set_style(bucket, name, style) + code, data = Misc.set_style(bucket, name, style) code == StatusOK end def unset_style(bucket, name) - code, data = Pub.unset_style(bucket, name) + code, data = Misc.unset_style(bucket, name) code == StatusOK end @@ -182,17 +182,17 @@ module Qiniu end def image_info(url) - code, data = Image.info(url) + code, data = Fop::Image.info(url) code == StatusOK ? data : false end def image_exif(url) - code, data = Image.exif(url) + code, data = Fop::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) + Fop::Image.mogrify_preview_url(source_image_url, options) end def image_mogrify_save_as(bucket, key, source_image_url, options) diff --git a/lib/qiniu/fop.rb b/lib/qiniu/fop.rb new file mode 100755 index 0000000..0abe87e --- /dev/null +++ b/lib/qiniu/fop.rb @@ -0,0 +1,3 @@ +# -*- encoding: utf-8 -*- + +require 'qiniu/image' diff --git a/lib/qiniu/image.rb b/lib/qiniu/image.rb index 0d7aa95..146dcc4 100755 --- a/lib/qiniu/image.rb +++ b/lib/qiniu/image.rb @@ -1,6 +1,7 @@ # -*- encoding: utf-8 -*- module Qiniu + module Fop module Image class << self include Utils @@ -33,4 +34,5 @@ module Qiniu end end # module Image + end # module Fop end # module Qiniu diff --git a/lib/qiniu/management.rb b/lib/qiniu/management.rb index 85d61ff..ce8cc97 100755 --- a/lib/qiniu/management.rb +++ b/lib/qiniu/management.rb @@ -90,7 +90,7 @@ module Qiniu end # save_as def image_mogrify_save_as(bucket, key, source_image_url, options) - mogrify_params_string = Image.generate_mogrify_params_string(options) + mogrify_params_string = Fop::Image.generate_mogrify_params_string(options) save_as(bucket, key, source_image_url, mogrify_params_string) end # image_mogrify_save_as diff --git a/lib/qiniu/pub.rb b/lib/qiniu/misc.rb similarity index 96% rename from lib/qiniu/pub.rb rename to lib/qiniu/misc.rb index b384d0c..d9d61b9 100755 --- a/lib/qiniu/pub.rb +++ b/lib/qiniu/misc.rb @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- module Qiniu - module Pub + module Misc class << self include Utils @@ -30,6 +30,6 @@ module Qiniu end end - end # module Pub + end # module Misc end # module Qiniu diff --git a/spec/qiniu/image_spec.rb b/spec/qiniu/image_spec.rb index 28b6bfb..986c9c0 100755 --- a/spec/qiniu/image_spec.rb +++ b/spec/qiniu/image_spec.rb @@ -3,11 +3,11 @@ require 'spec_helper' require 'qiniu/auth' require 'qiniu' -require 'qiniu/image' +require 'qiniu/fop' module Qiniu - module Image - describe Image do + module Fop + describe Fop do before :all do @@ -60,7 +60,7 @@ module Qiniu context ".info" do it "should works" do - code, data = Qiniu::Image.info(@source_image_url) + code, data = Qiniu::Fop::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::Image.exif(@source_image_url) + code, data = Qiniu::Fop::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::Image.mogrify_preview_url(@source_image_url, @mogrify_options) + mogrify_preview_url = Qiniu::Fop::Image.mogrify_preview_url(@source_image_url, @mogrify_options) puts mogrify_preview_url.inspect end end end - end # module Image + end # module Fop end # module Qiniu diff --git a/spec/qiniu/pub_spec.rb b/spec/qiniu/misc_spec.rb similarity index 70% rename from spec/qiniu/pub_spec.rb rename to spec/qiniu/misc_spec.rb index 03c2d60..f9fa2c5 100755 --- a/spec/qiniu/pub_spec.rb +++ b/spec/qiniu/misc_spec.rb @@ -3,11 +3,11 @@ require 'spec_helper' require 'qiniu/auth' require 'qiniu' -require 'qiniu/pub' +require 'qiniu/misc' module Qiniu - module Pub - describe Pub do + module Misc + describe Misc do before :all do @bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s @@ -24,7 +24,7 @@ module Qiniu context ".set_protected" do it "should works" do - code, data = Qiniu::Pub.set_protected(@bucket, 1) + code, data = Qiniu::Misc.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::Pub.set_separator(@bucket, "-") + code, data = Qiniu::Misc.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::Pub.set_style(@bucket, "small.jpg", "imageMogr/auto-orient/thumbnail/!120x120r/gravity/center/crop/!120x120/quality/80") + code, data = Qiniu::Misc.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::Pub.unset_style(@bucket, "small.jpg") + code, data = Qiniu::Misc.unset_style(@bucket, "small.jpg") code.should == 200 puts data.inspect end end end - end # module Pub + end # module Misc end # module Qiniu