aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJames Lal <james@lightsofapollo.com>2012-07-06 15:09:49 -0700
committerJames Lal <james@lightsofapollo.com>2012-07-06 15:09:49 -0700
commit69266ff4ac273089cc59bd2a257bbf3fd28db287 (patch)
tree96c0082bfd31c71b02b44c1fdd238dc56d74de2f /scripts
parent684ec0e95608e3212d8dac1b2c7489cf7e5c3078 (diff)
downloadjsCalDAV-69266ff4ac273089cc59bd2a257bbf3fd28db287.tar.gz
Add connection scripts
Diffstat (limited to 'scripts')
-rw-r--r--scripts/.gitignore1
-rwxr-xr-xscripts/connect95
-rw-r--r--scripts/test-configs.json.tpl17
3 files changed, 113 insertions, 0 deletions
diff --git a/scripts/.gitignore b/scripts/.gitignore
new file mode 100644
index 0000000..0d36a86
--- /dev/null
+++ b/scripts/.gitignore
@@ -0,0 +1 @@
+test-configs.json
diff --git a/scripts/connect b/scripts/connect
new file mode 100755
index 0000000..d8570b7
--- /dev/null
+++ b/scripts/connect
@@ -0,0 +1,95 @@
+#! /usr/bin/env node
+
+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;
+
+function findProp(uri) {
+ return new Propfind(con, {
+ url: uri || config.uri
+ });
+}
+
+// Have some url determine where the principal is
+var findCal = findProp();
+findCal.prop('current-user-principal');
+findCal.prop('resourcetype');
+findCal.prop('principal-URL');
+
+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;
+}
+
+findCal.send(function(err, data) {
+
+ // found principal find calendar home
+ var principaluri = getProp('current-user-principal', data, true);
+ console.log('PRINCIPAL:', principaluri);
+ var principalFind = findProp(principaluri);
+
+ principalFind.prop('resourcetype');
+ principalFind.prop(['caldav', 'calendar-home-set']);
+
+ principalFind.send(function(err, data) {
+ var caluri = getProp('calendar-home-set', data, true);
+ var calFind = findProp(caluri);
+ console.log('CALENDAR_HOME:', 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));
+ });
+ });
+
+});
diff --git a/scripts/test-configs.json.tpl b/scripts/test-configs.json.tpl
new file mode 100644
index 0000000..b3c7afd
--- /dev/null
+++ b/scripts/test-configs.json.tpl
@@ -0,0 +1,17 @@
+{
+ "google": {
+ "domain": "https://calendar.google.com",
+ "user": "user",
+ "password": "pass",
+ "uri": "/calendar/dav/"
+ },
+
+ "yahoo": {
+ "domain": "https://caldav.calendar.yahoo.com",
+ "user": "user",
+ "password": "pass",
+ "uri": "/"
+ }
+}
+
+