req = require('bagofrequest'),
xml2js = require('xml2js'),
validator = require('./validator');
function Eggtart(username, password, opts) {
this.version = opts.version || 'v1';
this.wait = opts.wait || 1000;
this.url = util.format('https://%s:%s@api.delicious.com/%s/',
Eggtart.prototype._init = function () {
var file = p.join(__dirname, '..', 'conf', this.version + '.json'),
config = JSON.parse(fs.readFileSync(file)),
Object.keys(config).forEach(function (method) {
Object.keys(config[method]).forEach(function (subMethod) {
subMethods[subMethod] = function (args, cb) {
var endpoint = config[method][subMethod].endpoint,
rules = config[method][subMethod].args;
validator.validate(rules, args, function (err) {
self._request(endpoint, args, cb);
Eggtart.prototype[method] = function () {
Eggtart.prototype._request = function (endpoint, params, cb) {
var parser = new xml2js.Parser(),
function _success(result, cb) {
parser.parseString(result.body, cb);
function _error(result, cb) {
parser.parseString(result.body, function (err, result) {
cb(new Error(result.result.$.code));
req.request('get', self.url + endpoint, opts, cb);
module.exports = Eggtart;