def initialize(connection)
request = Typhoeus::Request.new(connection.auth_url,
:method => :get,
:headers => { "X-Auth-User" => connection.authuser, "X-Auth-Key" => connection.authkey, "User-Agent" => "Cloud Databases Ruby API #{VERSION}" },
:verbose => ENV['DATABASES_VERBOSE'] ? true : false)
CloudDB.hydra.queue(request)
CloudDB.hydra.run
response = request.response
headers = response.headers_hash
if (response.code.to_s == "204")
connection.authtoken = headers["x-auth-token"]
user_id = headers["x-server-management-url"].match(/.*\/(\d+)$/)[1]
headers["x-server-management-url"] = "https://#{connection.region}.databases.api.rackspacecloud.com/v1.0/#{user_id}"
connection.dbmgmthost = URI.parse(headers["x-server-management-url"]).host
connection.dbmgmtpath = URI.parse(headers["x-server-management-url"]).path.chomp
connection.dbmgmtpath.sub!(/\/.*?\//, '/v1.0/')
connection.dbmgmtport = URI.parse(headers["x-server-management-url"]).port
connection.dbmgmtscheme = URI.parse(headers["x-server-management-url"]).scheme
connection.authok = true
else
connection.authtoken = false
raise CloudDB::Exception::Authentication, "Authentication failed with response code #{response.code}"
end
end