aboutsummaryrefslogtreecommitdiffstats
path: root/lib/caldav/request
diff options
context:
space:
mode:
authorJames Lal <james@lightsofapollo.com>2012-07-07 16:33:27 -0700
committerJames Lal <james@lightsofapollo.com>2012-07-07 16:33:27 -0700
commitee8dac6ecd2927d6ea1930ae478ff65766b446d9 (patch)
treef6482199d2a3fd6d57ee60e4ca659ebe9a82da4e /lib/caldav/request
parentccf8b1382cd6a72abc93b837e5c39272df9c2d72 (diff)
downloadjsCalDAV-ee8dac6ecd2927d6ea1930ae478ff65766b446d9.tar.gz
resources request
Diffstat (limited to 'lib/caldav/request')
-rw-r--r--lib/caldav/request/index.js3
-rw-r--r--lib/caldav/request/resources.js69
2 files changed, 71 insertions, 1 deletions
diff --git a/lib/caldav/request/index.js b/lib/caldav/request/index.js
index 6790fd1..6f8c23d 100644
--- a/lib/caldav/request/index.js
+++ b/lib/caldav/request/index.js
@@ -4,7 +4,8 @@
Abstract: ns.require('request/abstract'),
CalendarQuery: ns.require('request/calendar_query'),
Propfind: ns.require('request/propfind'),
- CalendarHome: ns.require('request/calendar_home')
+ CalendarHome: ns.require('request/calendar_home'),
+ Resources: ns.require('request/resources')
};
}.apply(
diff --git a/lib/caldav/request/resources.js b/lib/caldav/request/resources.js
new file mode 100644
index 0000000..1df7cf1
--- /dev/null
+++ b/lib/caldav/request/resources.js
@@ -0,0 +1,69 @@
+(function(module, ns) {
+
+ var Propfind = ns.require('request/propfind');
+
+ function ResourceFinder(connection, options) {
+ Propfind.apply(this, arguments);
+
+ this._resources = {};
+ this.depth = 1;
+ }
+
+ ResourceFinder.prototype = {
+ __proto__: Propfind.prototype,
+
+ addResource: function(name, handler) {
+ this._resources[name] = handler;
+ },
+
+ _processResult: function(req, callback) {
+ var results = {};
+ var url;
+ var root;
+ var collection;
+ var self = this;
+
+ if ('multistatus' in this.sax.root) {
+ root = this.sax.root.multistatus;
+
+ for (url in root) {
+ collection = root[url];
+
+ if ('resourcetype' in collection) {
+ collection.resourcetype.forEach(function(type) {
+ if (type in self._resources) {
+
+ if (!(type in results)) {
+ results[type] = {};
+ }
+
+ results[type][url] = new self._resources[type](
+ self.connection,
+ collection
+ );
+ }
+ });
+ }
+ }
+
+ callback(null, results, req);
+
+ } else {
+ //XXX: Improve error handling
+ callback(
+ new Error('unexpected xml result'),
+ this.sax.root, req
+ );
+ }
+ }
+
+ };
+
+ module.exports = ResourceFinder;
+
+}.apply(
+ this,
+ (this.Caldav) ?
+ [Caldav('request/resources'), Caldav] :
+ [module, require('../caldav')]
+));