Class: Raca::Containers

Inherits:
Object
  • Object
show all
Defined in:
lib/raca/containers.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(account, region, opts = {}) ⇒ Containers

Returns a new instance of Containers.



11
12
13
14
15
16
# File 'lib/raca/containers.rb', line 11

def initialize(, region, opts = {})
  @account, @region = , region
  @storage_url = @account.public_endpoint("cloudFiles", region)
  @logger = opts[:logger]
  @logger ||= Rails.logger if defined?(Rails)
end

Instance Method Details

#get(container_name) ⇒ Object



18
19
20
# File 'lib/raca/containers.rb', line 18

def get(container_name)
  Raca::Container.new(@account, @region, container_name)
end

#inspectObject



48
49
50
# File 'lib/raca/containers.rb', line 48

def inspect
  "#<Raca::Containers:#{__id__} region=#{@region}>"
end

#metadataObject

Return metadata on all containers



24
25
26
27
28
29
30
31
32
# File 'lib/raca/containers.rb', line 24

def 
  log "retrieving containers metadata from #{storage_path}"
  response    = storage_client.head(storage_path)
  {
    :containers => response["X-Account-Container-Count"].to_i,
    :objects    => response["X-Account-Object-Count"].to_i,
    :bytes      => response["X-Account-Bytes-Used"].to_i
  }
end

#set_temp_url_key(secret) ⇒ Object

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*



41
42
43
44
45
46
# File 'lib/raca/containers.rb', line 41

def set_temp_url_key(secret)
  log "setting Account Temp URL Key on #{storage_path}"

  response = storage_client.post(storage_path, nil, "X-Account-Meta-Temp-Url-Key" => secret.to_s)
  (200..299).cover?(response.code.to_i)
end