mailchimp
Version:
A node.js wrapper for the MailChimp API.
43 lines (36 loc) • 1.55 kB
JavaScript
var MandrillAPI_v1_0 = require('./MandrillAPI_v1_0'),
fs = require('fs');
/**
* Returns a Mandrill API wrapper object in the specified version. The only API
* version currently supported (even the only version available at the time of
* writing) is 1.0 but as soon as other versions are available and
* implemented you can specify the one you want in the options parameter.
*
* Available options are:
* - version The API version to use, currently only '1.0' is supported.
* Defaults to '1.0'.
* - secure Whether or not to use secure connections over HTTPS
* (true/false). Defaults to false.
* - userAgent Custom User-Agent description to use in the request header.
*
* @param apiKey The API key to access the Mandrill API with
* @param options Configuration options as described above
* @return Instance of the Mandrill API in the specified version
*/
function MandrillAPI (apiKey, options) {
if (!options)
var options = {};
if (!apiKey)
throw new Error('You have to provide an API key for this to work.');
try {
var packageInfo = fs.readFileSync(__dirname+"/../../package.json");
} catch (error) {
throw new Error('Required package file package.json not found for this module.');
}
options.packageInfo = JSON.parse(packageInfo.toString());
if (!options.version || options.version == '1.0')
return new MandrillAPI_v1_0(apiKey, options);
else
throw new Error('Version ' + options.version + ' of the Mandrill API is currently not supported.');
}
module.exports = MandrillAPI;