1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
import url from 'url';
import * as accounts from './accounts';
import * as calendars from './calendars';
import * as contacts from './contacts';
/**
* @param {dav.Transport} xhr - request sender.
*
* Options:
*
* (String) baseUrl - root url to resolve relative request urls with.
*/
export class Client {
constructor(xhr, options={}) {
this.xhr = xhr;
Object.assign(this, options);
// Expose internal modules for unit testing
this._accounts = accounts;
this._calendars = calendars;
this._contacts = contacts;
}
/**
* @param {dav.Request} req - dav request.
* @param {String} uri - where to send request.
* @return {Promise} a promise that will be resolved with an xhr request
* after its readyState is 4 or the result of applying an optional
* request `transformResponse` function to the xhr object after its
* readyState is 4.
*
* Options:
*
* (Object) sandbox - optional request sandbox.
*/
send(req, uri, options) {
if (this.baseUrl) {
let urlObj = url.parse(uri);
uri = url.resolve(this.baseUrl, urlObj.path);
}
return this.xhr.send(req, uri, options);
}
createAccount(options={}) {
options.xhr = options.xhr || this.xhr;
return accounts.createAccount(options);
}
createCalendarObject(calendar, options={}) {
options.xhr = options.xhr || this.xhr;
return calendars.createCalendarObject(calendar, options);
}
updateCalendarObject(calendarObject, options={}) {
options.xhr = options.xhr || this.xhr;
return calendars.updateCalendarObject(calendarObject, options);
}
deleteCalendarObject(calendarObject, options={}) {
options.xhr = options.xhr || this.xhr;
return calendars.deleteCalendarObject(calendarObject, options);
}
syncCalendar(calendar, options={}) {
options.xhr = options.xhr || this.xhr;
return calendars.syncCalendar(calendar, options);
}
syncCaldavAccount(account, options={}) {
options.xhr = options.xhr || this.xhr;
return calendars.syncCaldavAccount(account, options);
}
createAddressBook(options={}) {
options.xhr = options.xhr || this.xhr;
return contacts.createAddressBook(options);
}
deleteAddressBook(addressBook, options={}) {
options.xhr = options.xhr || this.xhr;
return contacts.deleteAddressBook(addressBook, options);
}
renameAddressBook(addressBook, options={}) {
options.xhr = options.xhr || this.xhr;
return contacts.renameAddressBook(addressBook, options);
}
createCard(addressBook, options={}) {
options.xhr = options.xhr || this.xhr;
return contacts.createCard(addressBook, options);
}
updateCard(card, options={}) {
options.xhr = options.xhr || this.xhr;
return contacts.updateCard(card, options);
}
deleteCard(card, options={}) {
options.xhr = options.xhr || this.xhr;
return contacts.deleteCard(card, options);
}
syncAddressBook(addressBook, options={}) {
options.xhr = options.xhr || this.xhr;
return contacts.syncAddressBook(addressBook, options);
}
syncCarddavAccount(account, options={}) {
options.xhr = options.xhr || this.xhr;
return contacts.syncCarddavAccount(account, options);
}
}
|