lib/fog/rackspace/cdn.rb in fog-1.15.0 vs lib/fog/rackspace/cdn.rb in fog-1.16.0
- old
+ new
@@ -11,17 +11,17 @@
request :get_containers
request :head_container
request :post_container
request :put_container
request :delete_object
-
-
+
+
module Base
- URI_HEADERS = {
+ URI_HEADERS = {
"X-Cdn-Ios-Uri" => :ios_uri,
"X-Cdn-Uri" => :uri,
- "X-Cdn-Streaming-Uri" => :streaming_uri,
+ "X-Cdn-Streaming-Uri" => :streaming_uri,
"X-Cdn-Ssl-Uri" => :ssl_uri
}.freeze
def service_name
:cloudFilesCDN
@@ -51,38 +51,38 @@
enabled = publish ? 'True' : 'False'
response = put_container(container.key, 'X-Cdn-Enabled' => enabled)
return {} unless publish
urls_from_headers(response.headers)
end
-
+
# Returns hash of urls for container
# @param [Fog::Storage::Rackspace::Directory] container to retrieve urls for
# @return [Hash] hash containing urls for published container
# @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400
# @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500
# @raise [Fog::Storage::Rackspace::ServiceError]
# @note If unable to find container or container is not published this method will return an empty hash.
def urls(container)
- begin
+ 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
-
+
private
-
+
def urls_from_headers(headers)
h = {}
URI_HEADERS.keys.each do | header |
- key = URI_HEADERS[header]
+ key = URI_HEADERS[header]
h[key] = headers[header]
end
h
- end
+ end
end
class Mock < Fog::Rackspace::Service
include Base
@@ -101,30 +101,30 @@
end
def data
self.class.data[@rackspace_username]
end
-
+
def purge(object)
- return true if object.is_a? Fog::Storage::Rackspace::File
- raise Fog::Errors::NotImplemented.new("#{object.class} does not support CDN purging") if object
+ return true if object.is_a? Fog::Storage::Rackspace::File
+ raise Fog::Errors::NotImplemented.new("#{object.class} does not support CDN purging") if object
end
def reset_data
self.class.data.delete(@rackspace_username)
end
-
+
end
class Real < Fog::Rackspace::Service
include Base
def initialize(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
authenticate(options)
@@ -145,36 +145,36 @@
# Resets CDN connection
def reload
@cdn_connection.reset
end
-
+
# Purges File
# @param [Fog::Storage::Rackspace::File] file to be purged from the CDN
# @raise [Fog::Errors::NotImplemented] returned when non file parameters are specified
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
+ end
- def request(params, parse_json = true, &block)
- super(params, parse_json, &block)
+ 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
-
- private
-
+
+ private
+
def authenticate_v1(options)
credentials = Fog::Rackspace.authenticate(options, @connection_options)
endpoint_uri credentials['X-CDN-Management-Url']
@auth_token = credentials['X-Auth-Token']
end