Class: Fog::Rackspace::CDN::Real
- Inherits:
-
Object
- Object
- Fog::Rackspace::CDN::Real
- Defined in:
- lib/fog/rackspace/cdn.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
- #reload ⇒ Object
- #request(params, parse_json = true) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fog/rackspace/cdn.rb', line 37 def initialize(={}) require 'json' credentials = Fog::Rackspace.authenticate() @auth_token = credentials['X-Auth-Token'] 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]) end |
Instance Method Details
#reload ⇒ Object
50 51 52 |
# File 'lib/fog/rackspace/cdn.rb', line 50 def reload @cdn_connection.reset end |
#request(params, parse_json = true) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fog/rackspace/cdn.rb', line 54 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::Error => error raise case error when Excon::Errors::NotFound Fog::Rackspace::Storage::NotFound.slurp(error) else error end end if !response.body.empty? && parse_json && response.headers['Content-Type'] =~ %r{application/json} response.body = JSON.parse(response.body) end response end |