Class: Fog::Rackspace::CDN::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/rackspace/cdn.rb

Instance Method Summary collapse

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(options={})
  require 'json'
  credentials = Fog::Rackspace.authenticate(options)
  @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}", options[:persistent])
end

Instance Method Details

#reloadObject



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