class Fog::Storage::Rackspace::Directory

Attributes

public[W]

@!attribute [w] public Required for compatibility with other Fog providers. Not Used.

public_url[W]

@!attribute [w] public_url Required for compatibility with other Fog providers. Not Used.

Public Instance Methods

destroy() click to toggle source

Destroy the directory and remove it from CDN @return [Boolean] returns true if directory was deleted @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError] @note Directory must be empty before it is destroyed. @see docs.rackspace.com/files/api/v1/cf-devguide/content/Delete_Container-d1e1765.html

# File lib/fog/rackspace/models/storage/directory.rb, line 65
def destroy
  requires :key
  service.delete_container(key)
  service.cdn.publish_container(self, false) if cdn_enabled?
  true
rescue Excon::Errors::NotFound
  false
end
files() click to toggle source

Returns collection of files in directory @return [Fog::Storage::Rackspace::Files] collection of files in directory @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError]

# File lib/fog/rackspace/models/storage/directory.rb, line 80
def files
  @files ||= begin
    Fog::Storage::Rackspace::Files.new(
      :directory    => self,
      :service   => service
    )
  end
end
ios_url() click to toggle source

URL used to stream video to iOS devices. Cloud Files will auto convert to the approprate format. @return [String] iOS URL @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError] @see docs.rackspace.com/files/api/v1/cf-devguide/content/iOS-Streaming-d1f3725.html

# File lib/fog/rackspace/models/storage/directory.rb, line 141
def ios_url
  urls[:ios_uri]
end
metadata() click to toggle source

Retrieve directory metadata @return [Fog::Storage::Rackspace::Metadata] metadata key value pairs.

# File lib/fog/rackspace/models/storage/directory.rb, line 49
def metadata
  unless attributes[:metadata]
     response = service.head_container(key)
     attributes[:metadata] = Fog::Storage::Rackspace::Metadata.from_headers(self, response.headers)
  end
  attributes[:metadata]
end
metadata=(hash) click to toggle source

Set directory metadata @param [Hash,Fog::Storage::Rackspace::Metadata] hash contains key value pairs

# File lib/fog/rackspace/models/storage/directory.rb, line 38
def metadata=(hash)
  if hash.is_a? Fog::Storage::Rackspace::Metadata
    attributes[:metadata] = hash
  else
    attributes[:metadata] = Fog::Storage::Rackspace::Metadata.new(self, hash)
  end
  attributes[:metadata]
end
public?() click to toggle source

Is directory published to CDN @return [Boolean] return true if published to CDN @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError]

# File lib/fog/rackspace/models/storage/directory.rb, line 95
def public?
  if @public.nil?
    @public ||= (key && public_url) ? true : false
  end
  @public
end
public_url() click to toggle source

Returns the public url for the directory. If the directory has not been published to the CDN, this method will return nil as it is not publically accessible. This method will return the approprate url in the following order:

  1. If the service used to access this directory was created with the option :rackspace_cdn_ssl => true, this method will return the SSL-secured URL.

  2. If the cdn_cname attribute is populated this method will return the cname.

  3. return the default CDN url.

@return [String] public url for directory @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError]

# File lib/fog/rackspace/models/storage/directory.rb, line 128
def public_url
  return nil if urls.empty?
  return urls[:ssl_uri] if service.ssl?
  cdn_cname || urls[:uri]
end
reload() click to toggle source

Reload directory with latest data from Cloud Files @return [Fog::Storage::Rackspace::Directory] returns itself @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError]

Calls superclass method
# File lib/fog/rackspace/models/storage/directory.rb, line 108
def reload
  @public = nil
  @urls = nil
  @files = nil
  super
end
save() click to toggle source

Create or update directory and associated metadata @return [Boolean] returns true if directory was saved @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError] @note If public attribute is true, directory will be CDN enabled @see docs.rackspace.com/files/api/v1/cf-devguide/content/Create_Container-d1e1694.html

# File lib/fog/rackspace/models/storage/directory.rb, line 164
def save
  requires :key
  create_or_update_container
  if cdn_enabled?
    @urls = service.cdn.publish_container(self, public?)
  else
    raise Fog::Storage::Rackspace::Error.new("Directory can not be set as :public without a CDN provided") if public?
  end
  true
end
streaming_url() click to toggle source

URL used to stream resources @return [String] streaming url @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError] @see docs.rackspace.com/files/api/v1/cf-devguide/content/Streaming-CDN-Enabled_Containers-d1f3721.html

# File lib/fog/rackspace/models/storage/directory.rb, line 152
def streaming_url
  urls[:streaming_uri]
end

Private Instance Methods

cdn_enabled?() click to toggle source
# File lib/fog/rackspace/models/storage/directory.rb, line 177
def cdn_enabled?
  service.cdn && service.cdn.enabled?
end
create_or_update_container() click to toggle source
# File lib/fog/rackspace/models/storage/directory.rb, line 187
def create_or_update_container
  headers = attributes[:metadata].nil? ? {} : metadata.to_headers
  service.put_container(key, headers)
end
urls() click to toggle source
# File lib/fog/rackspace/models/storage/directory.rb, line 181
def urls
  requires :key
  return {} unless cdn_enabled?
  @urls ||= service.cdn.urls(self)
end