aboutsummaryrefslogblamecommitdiffstats
path: root/scripts/connect
blob: c604fa2a7e37f43d0ad4b16e81f54d6e7d329905 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12

                    









                                                   






















                                                             
                                               
                                         
                                         


                                     


                                      
 
                                              
 




                                                     

                                              
                                           
 

                                        








                                                   


     
 


                                  
 

                                      
                               
   
#! /usr/bin/env node


/**
 * The intent of this script is to test some
 * basic operations on a given server to see how
 * well we can interact with them out of the box.
 *
 * As our detection capabilities evolve this script
 * should be smaller and simpler.
 */

var CalDav = require('../lib/caldav');
var configurations = JSON.parse(require('fs').readFileSync(
  __dirname + '/test-configs.json', 'utf8'
));

var connectionType = process.argv[2];

if (!connectionType || !(connectionType in configurations)) {
  console.error(
    'You must choose an available configuration:',
    Object.keys(configurations)
  );
  process.exit(1);
}

var config = configurations[connectionType];

var con = new CalDav.Connection({
  domain: config.domain,
  user: config.user,
  password: config.password
});

var CalendarHome = CalDav.Request.CalendarHome;
var Calendar = CalDav.Resources.Calendar;
var Resources = CalDav.Request.Resources;

function getCalendarDetails(caluri) {

  var resources = new Resources(con, {
    url: caluri
  });

  resources.addResource('calendar', Calendar);

  resources.prop(['ical', 'calendar-color']);
  resources.prop(['caldav', 'calendar-description']);
  resources.prop(['caldav', 'calendar-timezone']);
  resources.prop('displayname');
  resources.prop('resourcetype');
  resources.prop('getlastmodified');
  resources.prop('current-user-privilege-set')
  resources.prop(['calserver', 'getctag']);

  // found calendar home find calendars.
  resources.send(function(err, data) {
    var calendars = data.calendar;
    var cal = calendars[Object.keys(calendars)[0]];
    console.log(cal);
    var query = cal.createQuery();

    query.send(function(err, data, xhr) {
      console.log(query.xhr.data);
      console.log(err, data);
    });
  });

}

var home = new CalendarHome(con, {
  url: config.uri
});

home.send(function(err, data) {
  console.log('CALENDAR_HOME:', data);
  getCalendarDetails(data.url);
});