var g = require('../global')

module.exports = {
  connect: function(url) {
    return {
      authenticate: function(username, apiKey, callback) {
        var path = g.format(url + '/users/%s/authenticate', g.escape(username));
        g.log('info', "POST %s", path);
        g.rest.post(path, { data: apiKey }).on('complete', function(token, response) {
          if ( token instanceof Error)
            return callback(token);
          else if ( response.statusCode !== 200 )
            return callback(g.format("POST %s failed : %s", path, response.statusCode));
          
          callback(null, token);
        })
      }    
    }
  },
  username: function(token) {
    return g.username(token);
  },
  tokenHeader: function(token) {
    return g.format('Token token="%s"', new Buffer(JSON.stringify(token)).toString('base64'))
  }
}

@@ -82,16 +82,521 @@
 eturn %7B%0A
+      casLogin: function(ticket, callback) %7B%0A        var path = g.format(url + '/users/login?ticket=%25s', ticket);%0A        g.log('info', %22POST %25s%22, path);%0A        g.rest.post(path).on('complete', function(apiKey, response) %7B%0A          if ( apiKey instanceof Error)%0A            return callback(apiKey);%0A          else if ( response.statusCode !== 200 )%0A            return callback(g.format(%22POST %25s failed : %25s%22, path, response.statusCode));%0A          %0A          callback(null, apiKey);%0A        %7D)%0A      %7D,%0A
       au

add casLogin