Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gomfunkel committed Jan 15, 2011
0 parents commit 6b068f6
Show file tree
Hide file tree
Showing 9 changed files with 1,670 additions and 0 deletions.
1 change: 1 addition & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The MIT License===============Copyright (c) 2010 Daniel Leinich <leinich@gmx.net>.Permission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the'Software'), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:The above copyright notice and this permission notice shall beincluded in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANYCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THESOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Expand Down
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
node-mailchimp
==============

A node.js wrapper for the MailChimp API.

All functions of the MailChimp API (Version 1.3) and the MailChimp Export API
(Version 1.0) as described on [http://www.mailchimp.com/api/](http://www.mailchimp.com/api/)
are exposed to your node.js application.

Installation
------------

Installing using npm (node package manager):

npm install mailchimp

If you don't have npm installed or don't want to use it:

cd ~/.node_libraries
git clone git://github.com/gomfunkel/node-mailchimp.git mailchimp

Usage
-----

More or less proper documentation can be found in the source code. Available
API functions and their documentation can be found on
[http://www.mailchimp.com/api/](http://www.mailchimp.com/api/). You can also
find further information on how to obtain an API key and much more on the
MailChimp API pages.

MailChimp API:

var MailChimpAPI = require('mailchimp').MailChimpAPI;

var apiKey = 'Your MailChimp API Key';

try {
var api = new MailChimpAPI(apiKey, { version : '1.3', secure : false });
} catch (error) {
console.log('Error: ' + error);
}

api.campaigns({ start: 0, limit: 25 }, function (data) {
if (data.error)
console.log('Error: '+data.error+' ('+data.code+')');
else
console.log(JSON.stringify(data)); // Do something with your data!
});

api.campaignStats({ cid : '/* CAMPAIGN ID */' }, function (data) {
if (data.error)
console.log('Error: '+data.error+' ('+data.code+')');
else
console.log(JSON.stringify(data)); // Do something with your data!
});

MailChimp Export API:

var MailChimpExportAPI = require('mailchimp').MailChimpExportAPI;

var apiKey = 'Your MailChimp API Key';

try {
var api = new MailChimpExportAPI(apiKey, { version : '1.0', secure: false });
} catch (error) {
console.log('Error: ' + error);
}

exportApi.list({ id : '/* LIST ID */' }, function (data) {
if (data.error)
console.log('Error: '+data.error+' ('+data.code+')');
else
console.log(data); // Do something with your data!
});

ToDo / Ideas
------------

* Implement API versions 1.1 and 1.2
* Implement WebHooks

License
-------

node-mailchimp is licensed under the MIT License. (See LICENSE)
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib/mailchimp');
33 changes: 33 additions & 0 deletions lib/mailchimp/MailChimpAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var MailChimpAPI_v1_3 = require('./MailChimpAPI_v1_3');

/**
* Returns a MailChimp API wrapper object of the specified version. The only
* API version currently supported is 1.3 but as soon as other versions are
* implemented you can specify the one you want in the options parameter.
*
* Available options are:
* - version The API version to use, currently only '1.3' is supported.
* Defaults to '1.3'.
* - secure Whether or not to use secure connections over HTTPS (true/false)
* Defaults to false.
*
* @param apiKey The API key to access the MailChimp API with
* @param options Configuration options as described above
* @returns Instance of the MailChimp API in the specified version
*/
function MailChimpAPI (apiKey, options) {

if (!options)
var options = {};

if (!apiKey)
throw 'You have to provide an API key for this to work.';

if (!options.version || options.version == '1.3')
return new MailChimpAPI_v1_3(apiKey, options);
else
throw 'Version ' + options.version + ' of the MailChimp API is currently not supported.';

}

module.exports = MailChimpAPI;
Loading

0 comments on commit 6b068f6

Please sign in to comment.