Class CloudFiles::Connection
In: lib/cloudfiles/connection.rb
Parent: Object

Methods

External Aliases

cdn_available -> cdn_available?

Attributes

auth_url  [R]  API host to authenticate to
authkey  [R]  Authentication key provided when the CloudFiles class was instantiated
authok  [RW]  Instance variable that is set when authorization succeeds
authtoken  [RW]  Token returned after a successful authentication
authuser  [R]  Authentication username provided when the CloudFiles class was instantiated
cdn_available  [RW]  Set at auth to see if a CDN is available for use
cdnmgmthost  [RW]  Hostname of the CDN management server
cdnmgmtpath  [RW]  Path for managing containers on the CDN management server
cdnmgmtport  [RW]  Port number for the CDN server
cdnmgmtscheme  [RW]  URI scheme for the CDN server
proxy_host  [R]  Optional proxy variables
proxy_port  [R] 
storagehost  [RW]  Hostname of the storage server
storagepath  [RW]  Path for managing containers/objects on the storage server
storageport  [RW]  Port for managing the storage server
storagescheme  [RW]  URI scheme for the storage server

Public Class methods

Creates a new CloudFiles::Connection object. Uses CloudFiles::Authentication to perform the login for the connection. The authuser is the Rackspace Cloud username, the authkey is the Rackspace Cloud API key.

Setting the :retry_auth option to false will cause an exception to be thrown if your authorization token expires. Otherwise, it will attempt to reauthenticate.

Setting the :snet option to true or setting an environment variable of RACKSPACE_SERVICENET to any value will cause storage URLs to be returned with a prefix pointing them to the internal Rackspace service network, instead of a public URL.

This is useful if you are using the library on a Rackspace-hosted system, as it provides faster speeds, keeps traffic off of the public network, and the bandwidth is not billed.

If you need to connect to a Cloud Files installation that is NOT the standard Rackspace one, set the :auth_url option to the URL of your authentication endpoint. The old option name of :authurl is deprecated. The default is CloudFiles::AUTH_USA (auth.api.rackspacecloud.com/v1.0)

There are two predefined constants to represent the United States-based authentication endpoint and the United Kingdom-based endpoint: CloudFiles::AUTH_USA (the default) and CloudFiles::AUTH_UK - both can be passed to the :auth_url option to quickly choose one or the other.

This will likely be the base class for most operations.

With gem 1.4.8, the connection style has changed. It is now a hash of arguments. Note that the proxy options are currently only supported in the new style.

  cf = CloudFiles::Connection.new(:username => "MY_USERNAME", :api_key => "MY_API_KEY", :auth_url => CloudFiles::AUTH_UK, :retry_auth => true, :snet => false, :proxy_host => "localhost", :proxy_port => "1234")

The old style (positional arguments) is deprecated and will be removed at some point in the future.

  cf = CloudFiles::Connection.new(MY_USERNAME, MY_API_KEY, RETRY_AUTH, USE_SNET)

Public Instance methods

Returns true if the authentication was successful and returns false otherwise.

  cf.authok?
  => true

The total size in bytes under this connection

Returns an CloudFiles::Container object that can be manipulated easily. Throws a NoSuchContainerException if the container doesn‘t exist.

   container = cf.container('test')
   container.count
   => 2

Returns true if the requested container exists and returns false otherwise.

  cf.container_exists?('good_container')
  => true

  cf.container_exists?('bad_container')
  => false

Gathers a list of the containers that exist for the account and returns the list of container names as an array. If no containers exist, an empty array is returned. Throws an InvalidResponseException if the request fails.

If you supply the optional limit and marker parameters, the call will return the number of containers specified in limit, starting after the object named in marker.

  cf.containers
  => ["backup", "Books", "cftest", "test", "video", "webpics"]

  cf.containers(2,'cftest')
  => ["test", "video"]

Retrieves a list of containers on the account along with their sizes (in bytes) and counts of the objects held within them. If no containers exist, an empty hash is returned. Throws an InvalidResponseException if the request fails.

If you supply the optional limit and marker parameters, the call will return the number of containers specified in limit, starting after the object named in marker.

  cf.containers_detail
  => { "container1" => { :bytes => "36543", :count => "146" },
       "container2" => { :bytes => "105943", :count => "25" } }

The total number of containers under this connection

Creates a new container and returns the CloudFiles::Container object. Throws an InvalidResponseException if the request fails.

Slash (/) and question mark (?) are invalid characters, and will be stripped out. The container name is limited to 256 characters or less.

  container = cf.create_container('new_container')
  container.name
  => "new_container"

  container = cf.create_container('bad/name')
  => SyntaxException: Container name cannot contain the characters '/' or '?'

Deletes a container from the account. Throws a NonEmptyContainerException if the container still contains objects. Throws a NoSuchContainerException if the container doesn‘t exist.

  cf.delete_container('new_container')
  => true

  cf.delete_container('video')
  => NonEmptyContainerException: Container video is not empty

  cf.delete_container('nonexistent')
  => NoSuchContainerException: Container nonexistent does not exist
get_container(name)

Alias for container

Sets instance variables for the bytes of storage used for this account/connection, as well as the number of containers stored under the account. Returns a hash with :bytes and :count keys, and also sets the instance variables.

  cf.get_info
  => {:count=>8, :bytes=>42438527}
  cf.bytes
  => 42438527
list_containers(limit = 0, marker = "")

Alias for containers

list_containers_info(limit = 0, marker = "")

Alias for containers_detail

Gathers a list of public (CDN-enabled) containers that exist for an account and returns the list of container names as an array. If no containers are public, an empty array is returned. Throws a InvalidResponseException if the request fails.

If you pass the optional argument as true, it will only show containers that are CURRENTLY being shared on the CDN, as opposed to the default behavior which is to show all containers that have EVER been public.

  cf.public_containers
  => ["video", "webpics"]

Returns true if the library is requesting the use of the Rackspace service network

[Validate]