Class: Fog::CDN::Rackspace::Real

Inherits:
Rackspace::Service show all
Includes:
Base
Defined in:
lib/fog/rackspace/cdn.rb,
lib/fog/rackspace/requests/cdn/delete_object.rb,
lib/fog/rackspace/requests/cdn/put_container.rb,
lib/fog/rackspace/requests/cdn/get_containers.rb,
lib/fog/rackspace/requests/cdn/head_container.rb,
lib/fog/rackspace/requests/cdn/post_container.rb

Constant Summary

Constants included from Base

Base::URI_HEADERS

Instance Method Summary collapse

Methods included from Base

#apply_options, #enabled?, #endpoint_uri, #publish_container, #region, #request_id_header, #service_name, #urls

Methods inherited from Rackspace::Service

#endpoint_uri, #region, #request_without_retry, #service_name, #service_net?

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



140
141
142
143
144
145
146
147
148
149
150
# File 'lib/fog/rackspace/cdn.rb', line 140

def initialize(options={})
  apply_options(options)
  authenticate(options)
  @enabled = false
  @persistent = options[:persistent] || false

  if endpoint_uri
    @connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
    @enabled = true
  end
end

Instance Method Details

#delete_object(container, object) ⇒ Excon::Response

Delete an existing object

Parameters

  • container<~String> - Name of container to delete

  • object<~String> - Name of object to delete

Returns:

  • (Excon::Response)

    response

Raises:



16
17
18
19
20
21
22
# File 'lib/fog/rackspace/requests/cdn/delete_object.rb', line 16

def delete_object(container, object)
  request(
    :expects  => 204,
    :method   => 'DELETE',
    :path     => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}"
  )
end

#get_containers(options = {}) ⇒ Excon::Response

List existing cdn-enabled storage containers

Parameters

  • options<~Hash>:

    • ‘enabled_only’<~Boolean> - Set to true to limit results to cdn enabled containers

    • ‘limit’<~Integer> - Upper limit to number of results returned

    • ‘marker’<~String> - Only return objects with name greater than this value

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • container<~String>: Name of container

Returns:

  • (Excon::Response)

    response

Raises:



23
24
25
26
27
28
29
30
31
# File 'lib/fog/rackspace/requests/cdn/get_containers.rb', line 23

def get_containers(options = {})
  response = request(
    :expects  => [200, 204],
    :method   => 'GET',
    :path     => '',
    :query    => {'format' => 'json'}.merge!(options)
  )
  response
end

#head_container(container) ⇒ Excon::Response

List cdn properties for a container

Parameters

  • container<~String> - Name of container to retrieve info for

Returns

  • response<~Excon::Response>:

    • headers<~Hash>:

      • ‘X-CDN-Enabled’<~Boolean> - cdn status for container

      • ‘X-CDN-URI’<~String> - cdn url for this container

      • ‘X-TTL’<~String> - integer seconds before data expires, defaults to 86400 (1 day)

      • ‘X-Log-Retention’<~Boolean> - ?

      • ‘X-User-Agent-ACL’<~String> - ?

      • ‘X-Referrer-ACL’<~String> - ?

Returns:

  • (Excon::Response)

    response

Raises:



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

def head_container(container)
  response = request(
    :expects  => 204,
    :method   => 'HEAD',
    :path     => container,
    :query    => {'format' => 'json'}
  )
  response
end

#post_container(name, options = {}) ⇒ Excon::Response

modify CDN properties for a container

Parameters

  • name<~String> - Name for container, should be < 256 bytes and must not contain ‘/’

  • options<~Hash>:

    • ‘X-CDN-Enabled’<~Boolean> - cdn status for container

    • ‘X-CDN-URI’<~String> - cdn url for this container

    • ‘X-TTL’<~String> - integer seconds before data expires, defaults to 86400 (1 day), in 3600..259200

    • ‘X-Log-Retention’<~Boolean> - ?

    • ‘X-User-Agent-ACL’<~String> - ?

    • ‘X-Referrer-ACL’<~String> - ?

Returns:

  • (Excon::Response)

    response

Raises:



22
23
24
25
26
27
28
29
30
# File 'lib/fog/rackspace/requests/cdn/post_container.rb', line 22

def post_container(name, options = {})
  response = request(
    :expects  => [201, 202],
    :headers  => options,
    :method   => 'POST',
    :path     => CGI.escape(name)
  )
  response
end

#purge(file) ⇒ Object

Purges File

Parameters:

Raises:



160
161
162
163
164
165
166
167
# File 'lib/fog/rackspace/cdn.rb', line 160

def purge(file)
  unless file.is_a? Fog::Storage::Rackspace::File
    raise Fog::Errors::NotImplemented.new("#{object.class} does not support CDN purging")  if object
  end

  delete_object file.directory.key, file.key
  true
end

#put_container(name, options = {}) ⇒ Excon::Response

enable CDN for a container

Parameters

  • name<~String> - Name for container, should be < 256 bytes and must not contain ‘/’

  • options<~Hash>:

    • ‘X-CDN-Enabled’<~Boolean> - cdn status for container

    • ‘X-CDN-URI’<~String> - cdn url for this container

    • ‘X-TTL’<~String> - integer seconds before data expires, defaults to 86400 (1 day), in 3600..259200

    • ‘X-Log-Retention’<~Boolean> - ?

    • ‘X-User-Agent-ACL’<~String> - ?

    • ‘X-Referrer-ACL’<~String> - ?

Returns:

  • (Excon::Response)

    response

Raises:



22
23
24
25
26
27
28
29
30
# File 'lib/fog/rackspace/requests/cdn/put_container.rb', line 22

def put_container(name, options = {})
  response = request(
    :expects  => [201, 202],
    :headers  => options,
    :method   => 'PUT',
    :path     => CGI.escape(name)
  )
  response
end

#reloadObject

Resets CDN connection



153
154
155
# File 'lib/fog/rackspace/cdn.rb', line 153

def reload
  @cdn_connection.reset
end

#request(params, parse_json = true) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
# File 'lib/fog/rackspace/cdn.rb', line 169

def request(params, parse_json = true)
  super
rescue Excon::Errors::NotFound => error
  raise Fog::Storage::Rackspace::NotFound.slurp(error, self)
rescue Excon::Errors::BadRequest => error
  raise Fog::Storage::Rackspace::BadRequest.slurp(error, self)
rescue Excon::Errors::InternalServerError => error
  raise Fog::Storage::Rackspace::InternalServerError.slurp(error, self)
rescue Excon::Errors::HTTPStatusError => error
  raise Fog::Storage::Rackspace::ServiceError.slurp(error, self)
end