Class: CarrierWave::Storage::UpYun::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/carrierwave/storage/upyun.rb

Constant Summary collapse

@@shared_connections =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket, options = {}) ⇒ Connection

Returns a new instance of Connection.



35
36
37
38
39
40
41
# File 'lib/carrierwave/storage/upyun.rb', line 35

def initialize(bucket, options = {})
  @upyun_bucket   = bucket
  @upyun_username = options[:upyun_username]
  @upyun_password = options[:upyun_password]

  @host = options[:api_host] || 'http://v0.api.upyun.com'
end

Instance Attribute Details

#upyun_bucketObject (readonly)

Returns the value of attribute upyun_bucket.



27
28
29
# File 'lib/carrierwave/storage/upyun.rb', line 27

def upyun_bucket
  @upyun_bucket
end

Class Method Details

.find_or_initialize(bucket, options) ⇒ Object



31
32
33
# File 'lib/carrierwave/storage/upyun.rb', line 31

def self.find_or_initialize(bucket, options)
  @@shared_connections[bucket.to_sym] ||= new(bucket, options)
end

Instance Method Details

#delete(path, headers = {}) ⇒ Object



56
57
58
# File 'lib/carrierwave/storage/upyun.rb', line 56

def delete(path, headers = {})
  rest_client[escaped(path)].delete(headers)
end

#escaped(path) ⇒ Object



64
65
66
# File 'lib/carrierwave/storage/upyun.rb', line 64

def escaped(path)
  CGI.escape(path)
end

#get(path, headers = {}) ⇒ Object



52
53
54
# File 'lib/carrierwave/storage/upyun.rb', line 52

def get(path, headers = {})
  rest_client[escaped(path)].get(headers)
end

#post(path, payload, headers = {}) ⇒ Object



60
61
62
# File 'lib/carrierwave/storage/upyun.rb', line 60

def post(path, payload, headers = {})
  rest_client[escaped(path)].post(payload, headers)
end

#put(path, payload, headers = {}) ⇒ Object



48
49
50
# File 'lib/carrierwave/storage/upyun.rb', line 48

def put(path, payload, headers = {})
  rest_client[escaped(path)].put(payload, headers)
end

#rest_clientObject



44
45
46
# File 'lib/carrierwave/storage/upyun.rb', line 44

def rest_client
  @rest_client ||= RestClient::Resource.new("#{@host}/#{@upyun_bucket}", :user => @upyun_username, :password => @upyun_password)
end