aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/caldav/request/resources.js14
-rwxr-xr-xscripts/connect39
-rw-r--r--test/caldav/request/resources_test.js2
3 files changed, 24 insertions, 31 deletions
diff --git a/lib/caldav/request/resources.js b/lib/caldav/request/resources.js
index 1df7cf1..f66a455 100644
--- a/lib/caldav/request/resources.js
+++ b/lib/caldav/request/resources.js
@@ -2,14 +2,14 @@
var Propfind = ns.require('request/propfind');
- function ResourceFinder(connection, options) {
+ function Resources(connection, options) {
Propfind.apply(this, arguments);
this._resources = {};
this.depth = 1;
}
- ResourceFinder.prototype = {
+ Resources.prototype = {
__proto__: Propfind.prototype,
addResource: function(name, handler) {
@@ -22,6 +22,7 @@
var root;
var collection;
var self = this;
+ var resources;
if ('multistatus' in this.sax.root) {
root = this.sax.root.multistatus;
@@ -29,8 +30,11 @@
for (url in root) {
collection = root[url];
- if ('resourcetype' in collection) {
- collection.resourcetype.forEach(function(type) {
+ resources = collection.resourcetype;
+
+ if (resources.value.forEach) {
+
+ resources.value.forEach(function(type) {
if (type in self._resources) {
if (!(type in results)) {
@@ -59,7 +63,7 @@
};
- module.exports = ResourceFinder;
+ module.exports = Resources;
}.apply(
this,
diff --git a/scripts/connect b/scripts/connect
index b5d12cb..bab6271 100755
--- a/scripts/connect
+++ b/scripts/connect
@@ -36,37 +36,26 @@ var con = new CalDav.Connection({
var Propfind = CalDav.Request.Propfind;
var CalendarHome = CalDav.Request.CalendarHome;
var Calendar = CalDav.Resources.Calendar;
+var Resources = CalDav.Request.Resources;
function getCalendarDetails(caluri) {
- var calFind = findProp(caluri);
- calFind.prop(['ical', 'calendar-color']);
- calFind.prop('owner');
- calFind.prop('current-user-privilege-set');
- calFind.prop(['caldav', 'calendar-description']);
- calFind.prop(['caldav', 'calendar-timezone']);
- calFind.prop('displayname');
- calFind.prop('resourcetype');
- calFind.prop(['calserver', 'getctag']);
- calFind.depth = 1;
-
+ var resources = new Resources(con, {
+ url: caluri
+ });
- // found calendar home find calendars.
- calFind.send(function(err, data) {
- var url, name, calendars = {};
+ resources.addResource('calendar', Calendar);
- for (url in data) {
- if (data[url].resourcetype.value.indexOf('calendar') !== -1) {
- calendars[url] = new Calendar(con, { url: url });
- calendars[url].updateFromServer(data[url]);
+ resources.prop(['ical', 'calendar-color']);
+ resources.prop(['caldav', 'calendar-description']);
+ resources.prop(['caldav', 'calendar-timezone']);
+ resources.prop('displayname');
+ resources.prop('resourcetype');
+ resources.prop(['calserver', 'getctag']);
- console.log('CAL RESOURCE:', calendars[url]);
- }
- }
- //console.log('DATA:');
- //console.log(JSON.stringify(data));
- //console.log('RAW:');
- //console.log(calFind.xhr.xhr.responseText);
+ // found calendar home find calendars.
+ resources.send(function(err, data) {
+ console.log(data);
});
}
diff --git a/test/caldav/request/resources_test.js b/test/caldav/request/resources_test.js
index c8a8675..ecea34a 100644
--- a/test/caldav/request/resources_test.js
+++ b/test/caldav/request/resources_test.js
@@ -71,7 +71,7 @@ suite('caldav/resource_finder', function() {
function resource(name, type) {
return {
name: status(name),
- resourcetype: [type]
+ resourcetype: status([type])
};
}