Class CloudFiles::Container
In: lib/cloudfiles/container.rb
Parent: Object

Methods

Attributes

bytes  [R]  Size of the container (in bytes)
cdn_enabled  [R]  True if container is public, false if container is private
cdn_ttl  [R]  CDN container TTL (if container is public)
cdn_url  [R]  CDN container URL (if container if public)
connection  [R]  The parent CloudFiles::Connection object for this container
count  [R]  Number of objects in the container
name  [R]  Name of the container which corresponds to the instantiated container class
referrer_acl  [R]  The container ACL on the site Referrer
user_agent_acl  [R]  The container ACL on the User Agent

Public Class methods

Retrieves an existing CloudFiles::Container object tied to the current CloudFiles::Connection. If the requested container does not exist, it will raise a NoSuchContainerException.

Will likely not be called directly, instead use connection.container(‘container_name’) to retrieve the object.

Public Instance methods

Creates a new CloudFiles::StorageObject in the current container.

If an object with the specified name exists in the current container, that object will be returned. Otherwise, an empty new object will be returned.

Passing in the optional make_path argument as true will create zero-byte objects to simulate a filesystem path to the object, if an objectname with path separators ("/path/to/myfile.mp3") is supplied. These path objects can be used in the Container.objects method.

Removes an CloudFiles::StorageObject from a container. True is returned if the removal is successful. Throws NoSuchObjectException if the object doesn‘t exist. Throws InvalidResponseException if the request fails.

  container.delete_object('new.txt')
  => true

  container.delete_object('nonexistent_file.txt')
  => NoSuchObjectException: Object nonexistent_file.txt does not exist

Returns true if a container is empty and returns false otherwise.

  new_container.empty?
  => true

  full_container.empty?
  => false
get_object(objectname)

Alias for object

list_objects(params = {})

Alias for objects

list_objects_info(params = {})

Alias for objects_detail

Change the log retention status for this container. Values are true or false.

These logs will be periodically (at unpredictable intervals) compressed and uploaded to a “.CDN_ACCESS_LOGS” container in the form of “container_name.YYYYMMDDHH-XXXX.gz”.

Returns true if log retention is enabled on this container, false otherwise

Makes a container private and returns true upon success. Throws NoSuchContainerException if the container doesn‘t exist or if the request fails.

Note that if the container was previously public, it will continue to exist out on the CDN until it expires.

  container.make_private
  => true

Makes a container publicly available via the Cloud Files CDN and returns true upon success. Throws NoSuchContainerException if the container doesn‘t exist or if the request fails.

Takes an optional hash of options, including:

:ttl, which is the CDN cache TTL in seconds (default 86400 seconds or 1 day, minimum 3600 or 1 hour, maximum 259200 or 3 days)

:user_agent_acl, a Perl-compatible regular expression limiting access to this container to user agents matching the given regular expression

:referrer_acl, a Perl-compatible regular expression limiting access to this container to HTTP referral URLs matching the given regular expression

  container.make_public(:ttl => 8900, :user_agent_acl => "/Mozilla/", :referrer_acl => "/^http://rackspace.com")
  => true

Returns the CloudFiles::StorageObject for the named object. Refer to the CloudFiles::StorageObject class for available methods. If the object exists, it will be returned. If the object does not exist, a NoSuchObjectException will be thrown.

  object = container.object('test.txt')
  object.data
  => "This is test data"

  object = container.object('newfile.txt')
  => NoSuchObjectException: Object newfile.txt does not exist

Returns true if object exists and returns false otherwise.

  container.object_exists?('goodfile.txt')
  => true

  container.object_exists?('badfile.txt')
  => false

Gathers a list of all available objects in the current container and returns an array of object names.

  container = cf.container("My Container")
  container.objects                     #=> [ "cat", "dog", "donkey", "monkeydir", "monkeydir/capuchin"]

Pass a limit argument to limit the list to a number of objects:

  container.objects(:limit => 1)                  #=> [ "cat" ]

Pass an marker with or without a limit to start the list at a certain object:

  container.objects(:limit => 1, :marker => 'dog')                #=> [ "donkey" ]

Pass a prefix to search for objects that start with a certain string:

  container.objects(:prefix => "do")       #=> [ "dog", "donkey" ]

Only search within a certain pseudo-filesystem path:

  container.objects(:path => 'monkeydir')     #=> ["monkeydir/capuchin"]

All arguments to this method are optional.

Returns an empty array if no object exist in the container. Throws an InvalidResponseException if the request fails.

Retrieves a list of all objects in the current container along with their size in bytes, hash, and content_type. If no objects exist, an empty hash is returned. Throws an InvalidResponseException if the request fails. Takes a parameter hash as an argument, in the same form as the objects method.

Returns a hash in the same format as the containers_detail from the CloudFiles class.

  container.objects_detail
  => {"test.txt"=>{:content_type=>"application/octet-stream",
                   :hash=>"e2a6fcb4771aa3509f6b27b6a97da55b",
                   :last_modified=>Mon Jan 19 10:43:36 -0600 2009,
                   :bytes=>"16"},
      "new.txt"=>{:content_type=>"application/octet-stream",
                  :hash=>"0aa820d91aed05d2ef291d324e47bc96",
                  :last_modified=>Wed Jan 28 10:16:26 -0600 2009,
                  :bytes=>"22"}
     }

Retrieves data about the container and populates class variables. It is automatically called when the Container class is instantiated. If you need to refresh the variables, such as size, count, cdn_enabled, cdn_ttl, and cdn_url, this method can be called again.

  container.count
  => 2
  [Upload new file to the container]
  container.count
  => 2
  container.populate
  container.count
  => 3

Returns true if the container is public and CDN-enabled. Returns false otherwise.

  public_container.public?
  => true

  private_container.public?
  => false
refresh()

Alias for populate

[Validate]