function Mandrill(apikey, debug) {
this.apikey = apikey != null ? apikey : null;
this.debug = debug != null ? debug : false;
this.templates = new Templates(this);
this.exports = new Exports(this);
this.users = new Users(this);
this.rejects = new Rejects(this);
this.inbound = new Inbound(this);
this.tags = new Tags(this);
this.messages = new Messages(this);
this.whitelists = new Whitelists(this);
this.ips = new Ips(this);
this.internal = new Internal(this);
this.subaccounts = new Subaccounts(this);
this.urls = new Urls(this);
this.webhooks = new Webhooks(this);
this.senders = new Senders(this);
this.metadata = new Metadata(this);
if (this.apikey === null) {
this.apikey = process.env['MANDRILL_APIKEY'];
}
}n/a
function Mandrill(apikey, debug) {
this.apikey = apikey != null ? apikey : null;
this.debug = debug != null ? debug : false;
this.templates = new Templates(this);
this.exports = new Exports(this);
this.users = new Users(this);
this.rejects = new Rejects(this);
this.inbound = new Inbound(this);
this.tags = new Tags(this);
this.messages = new Messages(this);
this.whitelists = new Whitelists(this);
this.ips = new Ips(this);
this.internal = new Internal(this);
this.subaccounts = new Subaccounts(this);
this.urls = new Urls(this);
this.webhooks = new Webhooks(this);
this.senders = new Senders(this);
this.metadata = new Metadata(this);
if (this.apikey === null) {
this.apikey = process.env['MANDRILL_APIKEY'];
}
}n/a
call = function (uri, params, onresult, onerror) {
var req;
if (params == null) {
params = {};
}
params.key = this.apikey;
params = new Buffer(JSON.stringify(params), 'utf8');
if (this.debug) {
console.log("Mandrill: Opening request to https://" + OPTS.host + OPTS.prefix + uri + ".json");
}
OPTS.path = "" + OPTS.prefix + uri + ".json";
OPTS.headers['Content-Length'] = params.length;
req = https.request(OPTS, (function(_this) {
return function(res) {
var json;
res.setEncoding('utf8');
json = '';
res.on('data', function(d) {
return json += d;
});
return res.on('end', function() {
var e;
try {
json = JSON.parse(json);
} catch (_error) {
e = _error;
json = {
status: 'error',
name: 'GeneralError',
message: e
};
}
if (json == null) {
json = {
status: 'error',
name: 'GeneralError',
message: 'An unexpected error occurred'
};
}
if (res.statusCode !== 200) {
if (onerror) {
return onerror(json);
} else {
return _this.onerror(json);
}
} else {
if (onresult) {
return onresult(json);
}
}
});
};
})(this));
req.write(params);
req.end();
req.on('error', (function(_this) {
return function(e) {
if (onerror) {
return onerror(e);
} else {
return _this.onerror({
status: 'error',
name: 'GeneralError',
message: e
});
}
};
})(this));
return null;
}...
params["from_name"] ?= null
params["subject"] ?= null
params["code"] ?= null
params["text"] ?= null
params["publish"] ?= true
params["labels"] ?= []
@master.call('templates/add', params, onsuccess, onerror)
###
Get the information for an existing template
@param {Object} params the hash of the parameters to pass to the request
@option params {String} name the immutable name of an existing template
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
...onerror = function (err) {
throw {
name: err.name,
message: err.message,
toString: function() {
return "" + err.name + ": " + err.message;
}
};
}...
message: 'An unexpected error occurred'
};
}
if (res.statusCode !== 200) {
if (onerror) {
return onerror(json);
} else {
return _this.onerror(json);
}
} else {
if (onresult) {
return onresult(json);
}
}
});
...