var oauthModule = require('./oauth')
  , Parser = require('xml2js').Parser;

var twitter = module.exports =
oauthModule.submodule('tumblr')
  .apiHost('http://www.tumblr.com/api')
  .oauthHost('http://www.tumblr.com')
  .entryPath('/auth/tumblr')
  .callbackPath('/auth/tumblr/callback')
  .sendCallbackWithAuthorize(false)
  .fetchOAuthUser( function (accessToken, accessTokenSecret, params) {
    var promise = this.Promise();
    this.oauth.get(this.apiHost() + '/authenticate', accessToken, accessTokenSecret, function (err, data) {
      if (err) return promise.fail(err);
      var parser = new Parser();
      parser.on('end', function (result) {
        var oauthUser;
        if(result.tumblelog instanceof Array){
          oauthUser = result.tumblelog[0]['@'];
        } else {
          oauthUser = result.tumblelog['@'];
        }
        promise.fulfill(oauthUser);
      });
      parser.parseString(data);
    });
    return promise;
  })
  .convertErr( function (data) {
    return data.data;
  });
@@ -30,18 +30,16 @@
 oauth')%0A
-  
 , Parser
@@ -69,16 +69,39 @@
 rser
+%0A, url = require('url')
 ;%0A%0Avar t
 witt
@@ -100,13 +100,12 @@
 ar t
-witte
+umbl
 r = 
@@ -556,16 +556,18 @@
 %7B%0A      
+  
 if (err)
@@ -977,49 +977,581 @@
 %0A  .
-convertErr( function (data) %7B%0A    return 
+authCallbackDidErr( function (req) %7B%0A    var parsedUrl = url.parse(req.url, true);%0A    return !parsedUrl.query %7C%7C !parsedUrl.query.oauth_token;%0A  %7D)%0A  .handleAuthCallbackError( function (req, res) %7B%0A    if (res.render) %7B%0A      res.render(__dirname + '/../views/auth-fail.jade', %7B%0A        errorDescription: 'The user denied your request'%0A      %7D);%0A    %7D else %7B%0A      // TODO Replace this with a nice fallback%0A      throw new Error(%22You must configure handleAuthCallbackError if you are not using express%22);%0A    %7D%0A  %7D)%0A  .convertErr( function (data) %7B%0A      return new Error(
 data
@@ -1555,15 +1555,16 @@
 ata.data
+)
 ;%0A  %7D);

fix uncatched error when declining tumblr auth