aboutsummaryrefslogtreecommitdiffstats
path: root/lib/caldav/request
diff options
context:
space:
mode:
authorJames Lal <james@lightsofapollo.com>2012-07-06 14:52:13 -0700
committerJames Lal <james@lightsofapollo.com>2012-07-06 14:52:13 -0700
commit684ec0e95608e3212d8dac1b2c7489cf7e5c3078 (patch)
tree15ff517b5715f4f32f44a70c2698caeb9426ee28 /lib/caldav/request
parentfa1bc078c2953c4d81d7c5c17e4f3a4c0e3febeb (diff)
downloadjsCalDAV-684ec0e95608e3212d8dac1b2c7489cf7e5c3078.tar.gz
Reworked requests to take connection object and options
Diffstat (limited to 'lib/caldav/request')
-rw-r--r--lib/caldav/request/abstract.js32
-rw-r--r--lib/caldav/request/calendar_query.js4
-rw-r--r--lib/caldav/request/propfind.js10
3 files changed, 22 insertions, 24 deletions
diff --git a/lib/caldav/request/abstract.js b/lib/caldav/request/abstract.js
index 4b72fd5..cc60391 100644
--- a/lib/caldav/request/abstract.js
+++ b/lib/caldav/request/abstract.js
@@ -7,10 +7,10 @@
/**
* Creates an (Web/Cal)Dav request.
*
- * @param {String} url location of resource.
+ * @param {Caldav.Connection} connection connection details.
* @param {Object} options additional options for request.
*/
- function Abstract(url, options) {
+ function Abstract(connection, options) {
if (typeof(options) === 'undefined') {
options = {};
}
@@ -18,22 +18,6 @@
var key;
var xhrOptions = {};
- if (typeof(url) === 'undefined' || !url) {
- throw new Error('request requires a url');
- }
-
- xhrOptions.url = url;
-
- if ('password' in options) {
- xhrOptions.password = options.password;
- delete options.password;
- }
-
- if ('user' in options) {
- xhrOptions.user = options.user;
- delete options.user;
- }
-
this.sax = new SAX();
for (key in options) {
@@ -42,8 +26,16 @@
}
}
- this.xhr = new XHR(xhrOptions);
- this.xhr.headers['Content-Type'] = 'text/xml';
+ if (!connection) {
+ throw new Error('must pass connection object');
+ }
+
+ this.connection = connection;
+
+ this.xhr = this.connection.request({
+ url: this.url,
+ headers: { 'Content-Type': 'text/xml' }
+ });
}
Abstract.prototype = {
diff --git a/lib/caldav/request/calendar_query.js b/lib/caldav/request/calendar_query.js
index 7b64d3f..6fcf74d 100644
--- a/lib/caldav/request/calendar_query.js
+++ b/lib/caldav/request/calendar_query.js
@@ -9,10 +9,10 @@
*
* Defaults to Depth of 1.
*
- * @param {String} url location to make request.
+ * @param {CalDav.Connection} connection connection object.
* @param {Object} options options for calendar query.
*/
- function CalendarQuery(url, options) {
+ function CalendarQuery(options) {
Propfind.apply(this, arguments);
this.xhr.headers['Depth'] = this.depth || 1;
diff --git a/lib/caldav/request/propfind.js b/lib/caldav/request/propfind.js
index 7202ea5..e54b669 100644
--- a/lib/caldav/request/propfind.js
+++ b/lib/caldav/request/propfind.js
@@ -20,14 +20,20 @@
DavResponse
);
- this.xhr.headers['Depth'] = this.depth;
+ this.xhr.headers['Depth'] = 0;
this.xhr.method = 'PROPFIND';
}
Propfind.prototype = {
__proto__: Abstract.prototype,
- depth: 0,
+ get depth() {
+ return this.xhr.headers.Depth;
+ },
+
+ set depth(val) {
+ this.xhr.headers.Depth = val;
+ },
/**
* Adds property to request.