lib/paperclip/storage/qiniu.rb in paperclip-qiniu-0.1.0 vs lib/paperclip/storage/qiniu.rb in paperclip-qiniu-0.2.0

- old
+ new

@@ -3,13 +3,13 @@ module Paperclip module Storage module Qiniu def self.extended base begin - require 'qiniu-rs' + require 'qiniu' rescue LoadError => e - e.message << " (You may need to install the qiniu-rs gem)" + e.message << " (You may need to install the qiniu gem)" raise e end unless defined?(::Qiniu) base.instance_eval do unless @options[:url].to_s.match(/^:fog.*url$/) @@ -23,11 +23,11 @@ end def exists?(style = default_style) init - !!::Qiniu::RS.stat(bucket, path(style)) + !!::Qiniu.stat(bucket, path(style)) end def flush_writes init for style, file in @queued_for_write do @@ -46,21 +46,21 @@ end def flush_deletes init for path in @queued_for_delete do - ::Qiniu::RS.delete(bucket, path) + ::Qiniu.delete(bucket, path) end @queued_for_delete = [] end def public_url(style = default_style) init if @options[:qiniu_host] "#{dynamic_fog_host_for_style(style)}/#{path(style)}" else - res = ::Qiniu::RS.get(bucket, path(style)) + res = ::Qiniu.get(bucket, path(style)) if res res["url"] else nil end @@ -69,22 +69,22 @@ private def init return if @inited - ::Qiniu::RS.establish_connection! @options[:qiniu_credentials] + ::Qiniu.establish_connection! @options[:qiniu_credentials] inited = true end def upload(file, path) - upload_token = ::Qiniu::RS.generate_upload_token :scope => bucket + upload_token = ::Qiniu.generate_upload_token :scope => bucket opts = {:uptoken => upload_token, :file => file.path, :key => path, :bucket => bucket, :mime_type => file.content_type, :enable_crc32_check => true} - unless ::Qiniu::RS.upload_file(opts) + unless ::Qiniu.upload_file(opts) raise Paperclip::Qiniu::UploadFailed end end def bucket