aboutsummaryrefslogtreecommitdiffstats
path: root/lib/caldav/connection.js
diff options
context:
space:
mode:
authorJames Lal <james@lightsofapollo.com>2013-05-02 14:02:07 -0700
committerJames Lal <james@lightsofapollo.com>2013-05-02 14:02:07 -0700
commitc81e925aa6dada192db75dccd4287ab1e9e09ab2 (patch)
tree5e7e4ee8dcc3cb01d48b4b88ab14039bc50cf034 /lib/caldav/connection.js
parent9b6e2c616154f2c20fe6272dca083868c02f98f4 (diff)
parent8857b80ae0dd7be54d0d731000c9f8edb0434336 (diff)
downloadjsCalDAV-c81e925aa6dada192db75dccd4287ab1e9e09ab2.tar.gz
Merge pull request #14 from lightsofapollo/oauth
Bug 867747 - Google OAuth implementation
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;
+ },
};