class Raca::Containers

Represents a collection of cloud files containers within a single region.

There’s a handful of methods that relate to the entire collection, but this is primarily used to retrieve a single Raca::Container object.

You probably don’t want to instantiate this directly, see Raca::Account#containers

Public Class Methods

new(account, region, opts = {}) click to toggle source
   # File lib/raca/containers.rb
11 def initialize(account, region, opts = {})
12   @account, @region = account, region
13   @storage_url = @account.public_endpoint("cloudFiles", region)
14   @logger = opts[:logger]
15   @logger ||= Rails.logger if defined?(Rails)
16 end

Public Instance Methods

get(container_name) click to toggle source
   # File lib/raca/containers.rb
18 def get(container_name)
19   Raca::Container.new(@account, @region, container_name)
20 end
inspect() click to toggle source
   # File lib/raca/containers.rb
48 def inspect
49   "#<Raca::Containers:#{__id__} region=#{@region}>"
50 end
metadata() click to toggle source

Return metadata on all containers

   # File lib/raca/containers.rb
24 def metadata
25   log "retrieving containers metadata from #{storage_path}"
26   response    = storage_client.head(storage_path)
27   {
28     :containers => response["X-Account-Container-Count"].to_i,
29     :objects    => response["X-Account-Object-Count"].to_i,
30     :bytes      => response["X-Account-Bytes-Used"].to_i
31   }
32 end
set_temp_url_key(secret) click to toggle source

Set the secret key that will be used to generate expiring URLs for all cloud files containers on the current account. This value should be passed to the expiring_url() method.

Use this with caution, this will invalidate all previously generated expiring URLS *FOR THE ENTIRE ACCOUNT*

   # File lib/raca/containers.rb
41 def set_temp_url_key(secret)
42   log "setting Account Temp URL Key on #{storage_path}"
43 
44   response = storage_client.post(storage_path, nil, "X-Account-Meta-Temp-Url-Key" => secret.to_s)
45   (200..299).cover?(response.code.to_i)
46 end

Private Instance Methods

log(msg) click to toggle source
   # File lib/raca/containers.rb
66 def log(msg)
67   if @logger.respond_to?(:debug)
68     @logger.debug msg
69   end
70 end
storage_client() click to toggle source
   # File lib/raca/containers.rb
62 def storage_client
63   @storage_client ||= @account.http_client(storage_host)
64 end
storage_host() click to toggle source
   # File lib/raca/containers.rb
54 def storage_host
55   URI.parse(@storage_url).host
56 end
storage_path() click to toggle source
   # File lib/raca/containers.rb
58 def storage_path
59   URI.parse(@storage_url).path
60 end