Class: Fog::CDN::Rackspace::Real
- Inherits:
-
Object
- Object
- Fog::CDN::Rackspace::Real
- Defined in:
- lib/fog/rackspace/cdn.rb,
lib/fog/rackspace/requests/cdn/purge.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
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#get_containers(options = {}) ⇒ Object
List existing cdn-enabled storage containers.
-
#head_container(container) ⇒ Object
List cdn properties for a container.
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
-
#post_container(name, options = {}) ⇒ Object
modify CDN properties for a container.
-
#purge_from_cdn(distribution_id, name, email = nil) ⇒ Object
Purges CDN Edge Cache for all objects inside of this container.
-
#put_container(name, options = {}) ⇒ Object
enable CDN for a container.
- #reload ⇒ Object
- #request(params, parse_json = true) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fog/rackspace/cdn.rb', line 57 def initialize(={}) require 'multi_json' @connection_options = [:connection_options] || {} credentials = Fog::Rackspace.authenticate(, @connection_options) @auth_token = credentials['X-Auth-Token'] @enabled = false @persistent = [:persistent] || false if credentials['X-CDN-Management-Url'] uri = URI.parse(credentials['X-CDN-Management-Url']) @host = uri.host @path = uri.path @port = uri.port @scheme = uri.scheme @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) @enabled = true end end |
Instance Method Details
#enabled? ⇒ Boolean
76 77 78 |
# File 'lib/fog/rackspace/cdn.rb', line 76 def enabled? @enabled end |
#get_containers(options = {}) ⇒ Object
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
-
-
18 19 20 21 22 23 24 25 26 |
# File 'lib/fog/rackspace/requests/cdn/get_containers.rb', line 18 def get_containers( = {}) response = request( :expects => [200, 204], :method => 'GET', :path => '', :query => {'format' => 'json'}.merge!() ) response end |
#head_container(container) ⇒ Object
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> - ?
-
-
20 21 22 23 24 25 26 27 28 |
# File 'lib/fog/rackspace/requests/cdn/head_container.rb', line 20 def head_container(container) response = request( :expects => 204, :method => 'HEAD', :path => container, :query => {'format' => 'json'} ) response end |
#post_container(name, options = {}) ⇒ Object
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> - ?
17 18 19 20 21 22 23 24 25 |
# File 'lib/fog/rackspace/requests/cdn/post_container.rb', line 17 def post_container(name, = {}) response = request( :expects => [201, 202], :headers => , :method => 'POST', :path => CGI.escape(name) ) response end |
#purge_from_cdn(distribution_id, name, email = nil) ⇒ Object
Purges CDN Edge Cache for all objects inside of this container
:email, An valid email address or comma seperated list of emails to be notified once purge is complete .
obj.purge_from_cdn
=> true
or
obj.purge_from_cdn("[email protected]")
=> true
or
obj.purge_from_cdn("[email protected], [email protected]")
=> true
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fog/rackspace/requests/cdn/purge.rb', line 24 def purge_from_cdn(distribution_id, name, email=nil) # raise Exception::CDNNotAvailable unless cdn_available? auth_token = self.instance_variable_get("@auth_token") path = self.instance_variable_get("@path") host = self.instance_variable_get("@host") scheme = self. instance_variable_get("@connection"). instance_variable_get("@excon"). instance_variable_get("@connection")[:scheme] headers = {} headers = {"X-Purge-Email" => email} if email url = scheme + "://" + host + path begin SwiftClient.delete_object(url, auth_token, distribution_id, name, nil, {}) true rescue ClientException => e raise StandardError, "Error Unable to Purge Object: #{@name}" unless (e.status.to_s =~ /^20.$/) false end end |
#put_container(name, options = {}) ⇒ Object
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> - ?
17 18 19 20 21 22 23 24 25 |
# File 'lib/fog/rackspace/requests/cdn/put_container.rb', line 17 def put_container(name, = {}) response = request( :expects => [201, 202], :headers => , :method => 'PUT', :path => CGI.escape(name) ) response end |
#reload ⇒ Object
80 81 82 |
# File 'lib/fog/rackspace/cdn.rb', line 80 def reload @cdn_connection.reset end |
#request(params, parse_json = true) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/fog/rackspace/cdn.rb', line 84 def request(params, parse_json = true) begin response = @connection.request(params.merge!({ :headers => { 'Content-Type' => 'application/json', 'X-Auth-Token' => @auth_token }.merge!(params[:headers] || {}), :host => @host, :path => "#{@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 = MultiJson.decode(response.body) end response end |