aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Lal <james@lightsofapollo.com>2012-06-26 12:29:36 +0200
committerJames Lal <james@lightsofapollo.com>2012-06-26 12:29:36 +0200
commit95fe95710b81d14dda2a3b77281f1fe65f703ef3 (patch)
tree0ae6cf64a9d93ea7d6034e359433d1412f0f0aff
parent816243091b923cc64d87250f8cbd0854a1348312 (diff)
downloadjsCalDAV-95fe95710b81d14dda2a3b77281f1fe65f703ef3.tar.gz
add user/pass options to abstract request
-rw-r--r--lib/webcals/request/abstract.js22
-rw-r--r--lib/webcals/xhr.js1
-rw-r--r--test/webcals/request/abstract_test.js21
3 files changed, 33 insertions, 11 deletions
diff --git a/lib/webcals/request/abstract.js b/lib/webcals/request/abstract.js
index ac0ceb5..4d549c2 100644
--- a/lib/webcals/request/abstract.js
+++ b/lib/webcals/request/abstract.js
@@ -11,13 +11,29 @@
* @param {Object} options additional options for request.
*/
function Abstract(url, options) {
+ if (typeof(options) === 'undefined') {
+ options = {};
+ }
+
var key;
+ var xhrOptions = {};
if (typeof(url) === 'undefined' || !url) {
throw new Error('request requires a url');
}
- this.url = 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) {
@@ -26,9 +42,7 @@
}
}
- this.xhr = new XHR({
- url: this.url
- });
+ this.xhr = new XHR(xhrOptions);
}
Abstract.prototype = {
diff --git a/lib/webcals/xhr.js b/lib/webcals/xhr.js
index f20415f..a8d8d58 100644
--- a/lib/webcals/xhr.js
+++ b/lib/webcals/xhr.js
@@ -49,6 +49,7 @@
waiting: false,
user: null,
password: null,
+ url: null,
headers: {},
data: {},
diff --git a/test/webcals/request/abstract_test.js b/test/webcals/request/abstract_test.js
index 0acb42b..37cd0f6 100644
--- a/test/webcals/request/abstract_test.js
+++ b/test/webcals/request/abstract_test.js
@@ -31,22 +31,29 @@ suite('webcals/request/abstract.js', function() {
FakeXhr.instances.length = 0;
});
- test('.xhr', function() {
- var xhr = subject.xhr;
- assert.instanceOf(xhr, Xhr);
- assert.equal(xhr.url, url);
- });
-
test('#_createPayload', function() {
assert.equal(subject._createPayload(), '');
});
test('#initializer', function() {
- assert.equal(subject.url, url);
+ assert.instanceOf(subject.xhr, Xhr);
+ assert.equal(subject.xhr.url, url);
assert.equal(subject.configOpt, options.configOpt);
assert.instanceOf(subject.sax, SAX);
});
+ test('xhr password options', function() {
+ var subject = new Abstract(url, {
+ password: 'password',
+ user: 'user'
+ });
+
+ var xhr = subject.xhr;
+
+ assert.equal(xhr.password, 'password');
+ assert.equal(xhr.user, 'user');
+ });
+
suite('#send', function(done) {
var xhr;