Class: Fog::CDN::Rackspace::Real
- Inherits:
-
Rackspace::Service
- Object
- Rackspace::Service
- Fog::CDN::Rackspace::Real
- 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
Instance Method Summary collapse
-
#delete_object(container, object) ⇒ Excon::Response
Delete an existing object.
-
#enabled? ⇒ Boolean
Returns true if CDN service is enabled.
-
#get_containers(options = {}) ⇒ Excon::Response
List existing cdn-enabled storage containers.
-
#head_container(container) ⇒ Excon::Response
List cdn properties for a container.
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
-
#post_container(name, options = {}) ⇒ Excon::Response
modify CDN properties for a container.
-
#purge(file) ⇒ Object
Purges File.
-
#put_container(name, options = {}) ⇒ Excon::Response
enable CDN for a container.
-
#reload ⇒ Object
Resets CDN connection.
- #request(params, parse_json = true, &block) ⇒ Object
Methods included from Base
#endpoint_uri, #publish_container, #region, #request_id_header, #service_name, #urls
Methods inherited from Rackspace::Service
#endpoint_uri, #region, #service_name
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/fog/rackspace/cdn.rb', line 121 def initialize(={}) # api_key and username missing from instance variable sets @rackspace_api_key = [:rackspace_api_key] @rackspace_username = [:rackspace_username] @connection_options = [:connection_options] || {} @rackspace_auth_url = [:rackspace_auth_url] @rackspace_cdn_url = [:rackspace_cdn_url] @rackspace_region = [:rackspace_region] || :dfw authenticate() @enabled = false @persistent = [: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
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 |
#enabled? ⇒ Boolean
Returns true if CDN service is enabled
142 143 144 |
# File 'lib/fog/rackspace/cdn.rb', line 142 def enabled? @enabled 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
-
-
23 24 25 26 27 28 29 30 31 |
# File 'lib/fog/rackspace/requests/cdn/get_containers.rb', line 23 def get_containers( = {}) response = request( :expects => [200, 204], :method => 'GET', :path => '', :query => {'format' => 'json'}.merge!() ) 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> - ?
-
-
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> - ?
-
22 23 24 25 26 27 28 29 30 |
# File 'lib/fog/rackspace/requests/cdn/post_container.rb', line 22 def post_container(name, = {}) response = request( :expects => [201, 202], :headers => , :method => 'POST', :path => CGI.escape(name) ) response end |
#purge(file) ⇒ Object
Purges File
154 155 156 157 158 159 160 161 |
# File 'lib/fog/rackspace/cdn.rb', line 154 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> - ?
-
22 23 24 25 26 27 28 29 30 |
# File 'lib/fog/rackspace/requests/cdn/put_container.rb', line 22 def put_container(name, = {}) response = request( :expects => [201, 202], :headers => , :method => 'PUT', :path => CGI.escape(name) ) response end |
#reload ⇒ Object
Resets CDN connection
147 148 149 |
# File 'lib/fog/rackspace/cdn.rb', line 147 def reload @cdn_connection.reset end |
#request(params, parse_json = true, &block) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/fog/rackspace/cdn.rb', line 163 def request(params, parse_json = true, &block) super(params, parse_json, &block) 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 |