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) ⇒ Object
Methods included from Base
#endpoint_uri, #publish_container, #region, #service_name, #urls
Methods inherited from Rackspace::Service
#authenticate, #endpoint_uri, #region, #service_name
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/fog/rackspace/cdn.rb', line 118 def initialize(={}) @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
135 136 137 |
# File 'lib/fog/rackspace/cdn.rb', line 135 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
147 148 149 150 151 152 153 154 |
# File 'lib/fog/rackspace/cdn.rb', line 147 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
140 141 142 |
# File 'lib/fog/rackspace/cdn.rb', line 140 def reload @cdn_connection.reset end |
#request(params, parse_json = true) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/fog/rackspace/cdn.rb', line 156 def request(params, parse_json = true) begin response = @connection.request(params.merge!({ :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Auth-Token' => auth_token }.merge!(params[:headers] || {}), :host => endpoint_uri.host, :path => "#{endpoint_uri.path}/#{params[:path]}", })) rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::Storage::Rackspace::NotFound.slurp(error) else error end end if !response.body.empty? && parse_json && response.headers['Content-Type'] =~ %r{application/json} response.body = Fog::JSON.decode(response.body) end response end |