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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
#! /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 Propfind = CalDav.Request.Propfind;
var CalendarHome = CalDav.Request.CalendarHome;
function getCalendarDetails(caluri) {
var calFind = findProp(caluri);
calFind.prop(['ical', 'calendar-color']);
calFind.prop('owner');
calFind.prop('displayname');
calFind.prop('resourcetype');
calFind.prop(['calserver', 'getctag']);
calFind.depth = 1;
// found calendar home find calendars.
calFind.send(function(err, data) {
var url, name;
for (url in data) {
if (data[url].resourcetype.value.indexOf('calendar') !== -1) {
name = data[url].displayname.value.value;
console.log('CAL RESOURCE:', name, '-', url);
}
}
console.log('DATA:');
console.log(JSON.stringify(data));
});
}
function findProp(uri) {
return new Propfind(con, {
url: uri || config.uri
});
}
function getProp(propName, obj, single) {
var key, url, level, results = {};
for (url in obj) {
level = obj[url];
for (key in level) {
if (key === propName && level[key].status) {
results[url] = level[key].value;
if (single) {
return results[url];
}
}
}
}
return results;
}
var home = new CalendarHome(con, {
url: config.uri
});
home.send(function(err, data) {
console.log('CALENDAR_HOME:', data);
getCalendarDetails(data);
});
|