dav icon indicating copy to clipboard operation
dav copied to clipboard

Simplify lower-level WebDAV api

Open lambdabaa opened this issue 10 years ago • 1 comments

Right now using the WebDAV bits looks like

var dav = require('dav');

var client = new dav.Client(
  new dav.transport.Basic(
    new dav.Credentials({
      username: 'xxx',
      password: 'xxx'
    })
  ),
  {
    baseUrl: 'https://mail.mozilla.com'
  }
);

var req = dav.request.basic({
  method: 'PUT',
  data: 'BEGIN:VCALENDAR\nEND:VCALENDAR',
  etag: '12345'
});

// req instanceof dav.Request

client.send(req, { url: '/calendars/123.ics' })
.then(function(response) {
  // response instanceof XMLHttpRequest
});

This is quite verbose and I think there's room for some cleanup.

lambdabaa avatar Jun 29 '14 01:06 lambdabaa

if you remove the unnecessary constructors it gets a little bit simpler:

var dav = require('dav');

// use `dav.transport.Basic` by default if single argument & no `send()` method
var client = new dav.Client({
  baseUrl: 'https://mail.mozilla.com',
  credentials: {
    username: 'xxx',
    password: 'xxx'
  }
});

var req = {
  method: 'PUT',
  data: 'BEGIN:VCALENDAR\nEND:VCALENDAR',
  etag: '12345'
};
client.send(req, '/calendars/123.ics').then(response => {
  // response instanceof XMLHttpRequest
});

see: #70, #71

millermedeiros avatar Apr 07 '15 20:04 millermedeiros