aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/connect
blob: c604fa2a7e37f43d0ad4b16e81f54d6e7d329905 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#! /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);
});