aboutsummaryrefslogtreecommitdiffstats
path: root/lib/caldav/connection.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/caldav/connection.js')
-rw-r--r--lib/caldav/connection.js63
1 files changed, 40 insertions, 23 deletions
diff --git a/lib/caldav/connection.js b/lib/caldav/connection.js
index 6884217..7262d06 100644
--- a/lib/caldav/connection.js
+++ b/lib/caldav/connection.js
@@ -30,6 +30,10 @@
}
}
+ var httpHandler = this.httpHandler || 'basic_auth';
+ if (typeof(httpHandler) !== 'object') {
+ this.httpHandler = Caldav.require('http/' + httpHandler);
+ }
}
Connection.prototype = {
@@ -55,36 +59,49 @@
* @return {Caldav.Xhr} http request set with default options.
*/
request: function(options) {
- if (typeof(options) === 'undefined') {
- options = {};
- }
-
- var copy = {};
- var key;
- // copy options
-
- for (key in options) {
- copy[key] = options[key];
+ if (options) {
+ if (options.url && options.url.indexOf('http') !== 0) {
+ var url = options.url;
+ if (url.substr(0, 1) !== '/') {
+ url = '/' + url;
+ }
+ options.url = this.domain + url;
+ }
}
- if (!copy.user) {
- copy.user = this.user;
- }
+ return new this.httpHandler(this, options);
+ },
- if (!copy.password) {
- copy.password = this.password;
+ /**
+ * Update properties on this connection and trigger a "update" event.
+ *
+ *
+ * connection.onupdate = function() {
+ * // do stuff
+ * };
+ *
+ * connection.update({
+ * user: 'foobar'
+ * });
+ *
+ *
+ * @param {Object} newProperties to shallow copy onto connection.
+ */
+ update: function(newProperties) {
+ if (newProperties) {
+ for (var key in newProperties) {
+ if (Object.prototype.hasOwnProperty.call(newProperties, key)) {
+ this[key] = newProperties[key];
+ }
+ }
}
- if (copy.url && copy.url.indexOf('http') !== 0) {
- var url = copy.url;
- if (url.substr(0, 1) !== '/') {
- url = '/' + url;
- }
- copy.url = this.domain + url;
+ if (this.onupdate) {
+ this.onupdate();
}
- return new XHR(copy);
- }
+ return this;
+ },
};