Skip to content

Commit

Permalink
改进 Upyun 初始化,将少连接的过程;
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Aug 20, 2012
1 parent e045b96 commit e4b0fb6
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions lib/carrierwave/storage/upyun.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,35 @@ module Storage
#
#
class UpYun < Abstract

class Connection
def initialize(options={})
@upyun_username = options[:upyun_username]
@upyun_password = options[:upyun_password]
@upyun_bucket = options[:upyun_bucket]
@connection_options = options[:connection_options] || {}
@host = options[:api_host] || 'http://v0.api.upyun.com'
@http = RestClient::Resource.new("#{@host}/#{@upyun_bucket}",
:user => @upyun_username,
@@http ||= RestClient::Resource.new("#{@host}/#{@upyun_bucket}",
:user => @upyun_username,
:password => @upyun_password)
end

def put(path, payload, headers = {})
@http["#{escaped(path)}"].put(payload, headers)
@@http["#{escaped(path)}"].put(payload, headers)
end

def get(path, headers = {})
@http["#{escaped(path)}"].get(headers)
@@http["#{escaped(path)}"].get(headers)
end

def delete(path, headers = {})
@http["#{escaped(path)}"].delete(headers)
@@http["#{escaped(path)}"].delete(headers)
end

def post(path, payload, headers = {})
@http["#{escaped(path)}"].post(payload, headers)
@@http["#{escaped(path)}"].post(payload, headers)
end

def escaped(path)
CGI.escape(path)
end
Expand Down Expand Up @@ -116,7 +116,7 @@ def url
nil
end
end

def content_type
headers[:content_type]
end
Expand Down Expand Up @@ -155,8 +155,8 @@ def uy_connection
if @uy_connection
@uy_connection
else
config = {:upyun_username => @uploader.upyun_username,
:upyun_password => @uploader.upyun_password,
config = {:upyun_username => @uploader.upyun_username,
:upyun_password => @uploader.upyun_password,
:upyun_bucket => @uploader.upyun_bucket
}
config[:api_host] = @uploader.upyun_api_host if @uploader.respond_to?(:upyun_api_host)
Expand Down

0 comments on commit e4b0fb6

Please sign in to comment.