2010-10-04 17:02:08 -04:00
|
|
|
require 'fog/core/model'
|
2010-09-08 17:00:43 -04:00
|
|
|
require 'fog/rackspace/models/storage/files'
|
2010-03-19 21:29:42 -04:00
|
|
|
|
2010-02-27 16:39:33 -05:00
|
|
|
module Fog
|
|
|
|
module Rackspace
|
2010-09-08 16:50:23 -04:00
|
|
|
class Storage
|
2010-02-27 16:39:33 -05:00
|
|
|
|
|
|
|
class Directory < Fog::Model
|
2010-05-02 22:59:15 -04:00
|
|
|
extend Fog::Deprecation
|
|
|
|
deprecate(:name, :key)
|
2010-05-04 17:31:42 -04:00
|
|
|
deprecate(:name=, :key=)
|
2010-02-27 16:39:33 -05:00
|
|
|
|
2010-09-09 20:50:38 -04:00
|
|
|
identity :key, :aliases => 'name'
|
2010-02-27 16:39:33 -05:00
|
|
|
|
2010-10-18 14:09:19 -04:00
|
|
|
attribute :bytes, :aliases => 'X-Container-Bytes-Used'
|
|
|
|
attribute :count, :aliases => 'X-Container-Object-Count'
|
2010-02-27 16:39:33 -05:00
|
|
|
|
|
|
|
def destroy
|
2010-05-02 22:59:15 -04:00
|
|
|
requires :key
|
|
|
|
connection.delete_container(key)
|
2010-02-27 16:39:33 -05:00
|
|
|
true
|
|
|
|
rescue Excon::Errors::NotFound
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def files
|
|
|
|
@files ||= begin
|
2010-09-08 17:00:43 -04:00
|
|
|
Fog::Rackspace::Storage::Files.new(
|
2010-02-27 16:39:33 -05:00
|
|
|
:directory => self,
|
|
|
|
:connection => connection
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-11-05 14:37:12 -04:00
|
|
|
def public=(new_public)
|
|
|
|
@public = new_public
|
|
|
|
end
|
|
|
|
|
|
|
|
def public_url
|
|
|
|
requires :key
|
|
|
|
@public_url ||= begin
|
|
|
|
begin response = connection.cdn.head_container(key)
|
|
|
|
response.headers['X-CDN-URI']
|
|
|
|
rescue Fog::Service::NotFound
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-02-27 16:39:33 -05:00
|
|
|
def save
|
2010-05-02 22:59:15 -04:00
|
|
|
requires :key
|
|
|
|
connection.put_container(key)
|
2010-11-05 14:37:12 -04:00
|
|
|
if @public
|
|
|
|
@public_url = connection.cdn.put_container(key).headers['X-CDN-URI']
|
|
|
|
end
|
2010-02-27 16:39:33 -05:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|