Class: CarrierWave::Storage::UpYun::Connection
- Inherits:
-
Object
- Object
- CarrierWave::Storage::UpYun::Connection
- Defined in:
- lib/carrierwave/storage/upyun.rb
Constant Summary collapse
{}
Instance Attribute Summary collapse
-
#upyun_bucket ⇒ Object
readonly
Returns the value of attribute upyun_bucket.
Class Method Summary collapse
Instance Method Summary collapse
- #delete(path, headers = {}) ⇒ Object
- #escaped(path) ⇒ Object
- #get(path, headers = {}) ⇒ Object
-
#initialize(bucket, options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #post(path, payload, headers = {}) ⇒ Object
- #put(path, payload, headers = {}) ⇒ Object
- #rest_client ⇒ Object
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, = {}) @upyun_bucket = bucket @upyun_username = [:upyun_username] @upyun_password = [:upyun_password] @host = [:api_host] || 'http://v0.api.upyun.com' end |
Instance Attribute Details
#upyun_bucket ⇒ Object (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, ) @@shared_connections[bucket.to_sym] ||= new(bucket, ) 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_client ⇒ Object
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 |