Comparing version 0.4.3 to 0.4.4
121
index.js
@@ -28,6 +28,10 @@ /*! | ||
this.method = method; | ||
this.status = 0|err.status; | ||
try { | ||
if ('code' in err.response.body) | ||
err = err.response.body; | ||
} catch (e) {} | ||
this.code = 0|err.code; | ||
this.status = 0|err.status; | ||
this.message = err.message; | ||
this.additional = err.additional||[]; | ||
this.additional = err.additional || []; | ||
}; | ||
@@ -76,3 +80,3 @@ TDoc.Error.prototype = Object.create(Error.prototype); | ||
).fail(function (err) { | ||
throw new TDoc.Error(method, err.response.body); | ||
throw new TDoc.Error(method, err); | ||
}).then(function (resp) { | ||
@@ -93,3 +97,3 @@ const data = resp.body; | ||
).fail(function (err) { | ||
throw new TDoc.Error(method, err.response.body); | ||
throw new TDoc.Error(method, err); | ||
}).then(function (resp) { | ||
@@ -112,3 +116,3 @@ if ('etag' in resp.header) { | ||
).fail(function (err) { | ||
throw new TDoc.Error(method, err.response.body); | ||
throw new TDoc.Error(method, err); | ||
}).then(function (resp) { | ||
@@ -131,3 +135,3 @@ const data = resp.body; | ||
).fail(function (err) { | ||
throw new TDoc.Error(method, err.response.body); | ||
throw new TDoc.Error(method, err); | ||
}).then(function (resp) { | ||
@@ -298,2 +302,9 @@ const data = resp.body; | ||
function parcelXML(me, p) { | ||
const data = {}; | ||
if (p.user) data.user = p.user; | ||
if (p.company) data.company = p.company; | ||
return GETbuffer(me, 'docs/parcel/' + p.id + '.xml', data); | ||
} | ||
function companyList(me, p) { | ||
@@ -321,76 +332,28 @@ const data = {}; | ||
TDoc.prototype.upload = function (p) { | ||
if (arguments.length > 1 || typeof p !== 'object') // backward compatibility | ||
p = { ready: 1, file: arguments[0], doctype: arguments[1], period: arguments[2], meta: arguments[3], callback: arguments[4] }; | ||
return upload(this, p).nodeify(p.callback); | ||
}; | ||
// register nodeified versions in the prototype | ||
[ | ||
companyList, | ||
doctypeInfo, | ||
doctypeList, | ||
document, | ||
documentDelete, | ||
documentLink, | ||
documentMeta, | ||
parcelClose, | ||
parcelCreate, | ||
parcelDelete, | ||
parcelXML, | ||
search, | ||
searchOne, | ||
update, | ||
updateMeta, | ||
upload, | ||
].forEach(function (f) { | ||
TDoc.prototype[f.name] = function (p) { | ||
if (typeof p != 'object') | ||
throw new Error('The parameter must be an object.'); | ||
return f(this, p).nodeify(p.callback); | ||
}; | ||
}); | ||
TDoc.prototype.update = function (p) { | ||
return update(this, p).nodeify(p.callback); | ||
}; | ||
TDoc.prototype.updateMeta = function (p) { | ||
return updateMeta(this, p).nodeify(p.callback); | ||
}; | ||
TDoc.prototype.search = function (p) { | ||
if (arguments.length > 1 || typeof p !== 'object') // backward compatibility | ||
p = { doctype: arguments[0], period: arguments[1], meta: arguments[2], callback: arguments[3] }; | ||
return search(this, p).nodeify(p.callback); | ||
}; | ||
TDoc.prototype.document = function (p) { | ||
return document(this, p).nodeify(p.callback); | ||
}; | ||
TDoc.prototype.documentMeta = function (p) { | ||
if (arguments.length > 1 || typeof p !== 'object') // backward compatibility | ||
p = { id: arguments[0], callback: arguments[1] }; | ||
return documentMeta(this, p).nodeify(p.callback); | ||
}; | ||
TDoc.prototype.documentLink = function (p) { | ||
return documentLink(this, p).nodeify(p.callback); | ||
}; | ||
TDoc.prototype.documentDelete = function (p) { | ||
return documentDelete(this, p).nodeify(p.callback); | ||
}; | ||
TDoc.prototype.searchOne = function (p) { | ||
if (arguments.length > 1 || typeof p !== 'object') // backward compatibility | ||
p = { doctype: arguments[0], period: arguments[1], meta: arguments[2], callback: arguments[3] }; | ||
return searchOne(this, p).nodeify(p.callback); | ||
}; | ||
TDoc.prototype.parcelCreate = function (p) { | ||
if (arguments.length > 1 || typeof p !== 'object') // backward compatibility | ||
p = { company: arguments[0], doctype: arguments[1], filename: arguments[2], callback: arguments[3] }; | ||
return parcelCreate(this, p).nodeify(p.callback); | ||
}; | ||
TDoc.prototype.parcelClose = function (p) { | ||
if (arguments.length > 1 || typeof p !== 'object') // backward compatibility | ||
p = { id: arguments[0], callback: arguments[1] }; | ||
return parcelClose(this, p).nodeify(p.callback); | ||
}; | ||
TDoc.prototype.parcelDelete = function (p) { | ||
if (arguments.length > 1 || typeof p !== 'object') // backward compatibility | ||
p = { id: arguments[0], callback: arguments[1] }; | ||
return parcelDelete(this, p).nodeify(p.callback); | ||
}; | ||
TDoc.prototype.companyList = function (p) { | ||
return companyList(this, p).nodeify(p.callback); | ||
}; | ||
TDoc.prototype.doctypeList = function (p) { | ||
return doctypeList(this, p).nodeify(p.callback); | ||
}; | ||
TDoc.prototype.doctypeInfo = function (p) { | ||
return doctypeInfo(this, p).nodeify(p.callback); | ||
}; | ||
module.exports = TDoc; |
@@ -5,3 +5,3 @@ /*jshint node: true, strict: true, globalstrict: true, indent: 4, immed: true, undef: true, sub: true */ | ||
// local instance, as we enable debug features | ||
var Promise = require('bluebird/js/release/promise')(); | ||
var Promise = require('bluebird').getNewLibraryCopy(); | ||
Promise.prototype.fail = Promise.prototype['catch']; | ||
@@ -8,0 +8,0 @@ Promise.config({ |
{ | ||
"name": "tdoc-api", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"description": "Wrapper around tDoc REST-ful APIs", | ||
@@ -15,6 +15,7 @@ "main": "index.js", | ||
"dependencies": { | ||
"bluebird": "^3.3.3", | ||
"bluebird": "^3.4.1", | ||
"superagent": "^2.3.0" | ||
}, | ||
"devDependencies": { | ||
"tap-spec": "^4.1.1", | ||
"tape": "^4.6.2", | ||
@@ -25,7 +26,6 @@ "tape-nock": "^1.2.2" | ||
"index.js", | ||
"lib/promise.js", | ||
"lib/restler-q.js" | ||
"lib/promise.js" | ||
], | ||
"scripts": { | ||
"test": "node test/test.js local" | ||
"test": "node test/test.js local | tap-spec" | ||
}, | ||
@@ -32,0 +32,0 @@ "bugs": "https://github.com/andxor/tdoc-api/issues", |
@@ -9,3 +9,3 @@ tdoc-api | ||
All the methods have a single object parameter, used as a way to have named optional parameters. | ||
All the methods have a single object parameter, used as a way to improve readability and have optional parameters. | ||
@@ -12,0 +12,0 @@ All methods return a [Promise/A+](https://promisesaplus.com/) but accept an optional Node-style `callback(err, data)` parameter. |
16921
3
331
Updatedbluebird@^3.4.1