lib/fog/rackspace/cdn.rb in fog-1.19.0 vs lib/fog/rackspace/cdn.rb in fog-1.20.0
- old
+ new
@@ -1,6 +1,6 @@
-require 'fog/rackspace'
+require 'fog/rackspace/core'
require 'fog/cdn'
module Fog
module CDN
class Rackspace < Fog::Service
@@ -21,10 +21,21 @@
"X-Cdn-Uri" => :uri,
"X-Cdn-Streaming-Uri" => :streaming_uri,
"X-Cdn-Ssl-Uri" => :ssl_uri
}.freeze
+ def apply_options(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
+ end
+
def service_name
:cloudFilesCDN
end
def region
@@ -33,10 +44,16 @@
def request_id_header
"X-Trans-Id"
end
+ # Returns true if CDN service is enabled
+ # @return [Boolean]
+ def enabled?
+ @enabled
+ end
+
def endpoint_uri(service_endpoint_url=nil)
@uri = super(@rackspace_cdn_url || service_endpoint_url, :rackspace_cdn_url)
end
# Publish container to CDN
@@ -95,11 +112,13 @@
def self.reset
@data = nil
end
def initialize(options={})
- @rackspace_username = options[:rackspace_username]
+ apply_options(options)
+ authenticate(options)
+ @enabled = !! endpoint_uri
end
def data
self.class.data[@rackspace_username]
end
@@ -117,31 +136,18 @@
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
+ 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
-
- # Returns true if CDN service is enabled
- # @return [Boolean]
- def enabled?
- @enabled
end
# Resets CDN connection
def reload
@cdn_connection.reset