Module: Fog::CDN::Rackspace::Base

Included in:
Mock, Real
Defined in:
lib/fog/rackspace/cdn.rb

Constant Summary collapse

URI_HEADERS =
{
  "X-Cdn-Ios-Uri" => :ios_uri,
  "X-Cdn-Uri" => :uri,
  "X-Cdn-Streaming-Uri" => :streaming_uri,
  "X-Cdn-Ssl-Uri" => :ssl_uri
}.freeze

Instance Method Summary collapse

Instance Method Details

#apply_options(options) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/fog/rackspace/cdn.rb', line 26

def apply_options(options)
  # api_key and username missing from instance variable sets
  @rackspace_api_key = options[:rackspace_api_key]
  @rackspace_username = options[:rackspace_username]

  @connection_options = options[:connection_options] || {}
  @rackspace_auth_url = options[:rackspace_auth_url]
  @rackspace_cdn_url = options[:rackspace_cdn_url]
  @rackspace_region = options[:rackspace_region] || :dfw
end

#enabled?Boolean

Returns true if CDN service is enabled

Returns:

  • (Boolean)


51
52
53
# File 'lib/fog/rackspace/cdn.rb', line 51

def enabled?
  @enabled
end

#endpoint_uri(service_endpoint_url = nil) ⇒ Object



55
56
57
# File 'lib/fog/rackspace/cdn.rb', line 55

def endpoint_uri(service_endpoint_url=nil)
  @uri = super(@rackspace_cdn_url || service_endpoint_url, :rackspace_cdn_url)
end

#publish_container(container, publish = true) ⇒ Hash

Publish container to CDN

Parameters:

  • container (Fog::Storage::Rackspace::Directory)

    directory to publish

  • publish (Boolean) (defaults to: true)

    If true directory is published. If false directory is unpublished.

Returns:

  • (Hash)

    hash containing urls for published container

Raises:



67
68
69
70
71
72
# File 'lib/fog/rackspace/cdn.rb', line 67

def publish_container(container, publish = true)
  enabled = publish ? 'True' : 'False'
  response = put_container(container.key, 'X-Cdn-Enabled' => enabled)
  return {} unless publish
  urls_from_headers(response.headers)
end

#regionObject



41
42
43
# File 'lib/fog/rackspace/cdn.rb', line 41

def region
  @rackspace_region
end

#request_id_headerObject



45
46
47
# File 'lib/fog/rackspace/cdn.rb', line 45

def request_id_header
  "X-Trans-Id"
end

#service_nameObject



37
38
39
# File 'lib/fog/rackspace/cdn.rb', line 37

def service_name
  :cloudFilesCDN
end

#urls(container) ⇒ Hash

Note:

If unable to find container or container is not published this method will return an empty hash.

Returns hash of urls for container

Parameters:

Returns:

  • (Hash)

    hash containing urls for published container

Raises:



81
82
83
84
85
86
87
88
89
# File 'lib/fog/rackspace/cdn.rb', line 81

def urls(container)
  begin
    response = head_container(container.key)
    return {} unless response.headers['X-Cdn-Enabled'] == 'True'
    urls_from_headers response.headers
  rescue Fog::Service::NotFound
    {}
  end
end