Permalink
Browse files

Added OAuth2 and made some minor text changes

  • Loading branch information...
1 parent 2f20cfc commit 6e8135239eb71ad197aad5f8f4435cdd4a0651d6 @gomfunkel committed Aug 30, 2011
Showing with 57 additions and 3 deletions.
  1. +57 −3 README.md
View
@@ -8,8 +8,9 @@ _node-mailchimp_ exposes the following features of the MailChimp API to your nod
* MailChimp Export API (Version 1.0)
* MailChimp Webhooks
* MailChimp STS API (Version 1.0)
+ * MailChimp OAuth2 authorization
-Further information on the MailChimp API and its features is available at [http://www.mailchimp.com/api/](http://www.mailchimp.com/api/)
+Further information on the MailChimp API and its features is available at [http://apidocs.mailchimp.com](http://apidocs.mailchimp.com)
## Installation
@@ -22,11 +23,11 @@ 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
-Please note that parts of _node-mailchimp_ depend on [request](http://github.com/mikeal/request) by [Mikeal Rogers](http://github.com/mikeal). This library needs to be installed for the API and Export API to work.
+Please note that parts of _node-mailchimp_ depend on [request](http://github.com/mikeal/request) by [Mikeal Rogers](http://github.com/mikeal). This library needs to be installed for the API and Export API to work. If you are using npm this dependency should be automagically resolved for you.
## Usage
-Information on how to use the MailChimp APIs can be found below. Further information on the API methods available can be found at [http://apidocs.mailchimp.com/](http://apidocs.mailchimp.com/). You can also find further information on how to obtain an API key, how to set up Webhooks in your MailChimp account and much more on the MailChimp API pages.
+Information on how to use the MailChimp APIs can be found below. Further information on the API methods available can be found at [http://apidocs.mailchimp.com](http://apidocs.mailchimp.com). You can also find further information on how to obtain an API key, how to set up Webhooks and/or OAuth2 in your MailChimp account and much more on the MailChimp API pages.
### MailChimp API
@@ -153,6 +154,59 @@ Example:
console.log(data); // Do something with your data!
});
+### MailChimp OAuth2
+
+_MailChimpOAuth_ takes one argument, an options object which can contain the following options:
+
+ * `clientId` The clientId can be obtained from MailChimp, please refer to the API docs on how to do this. The clientId is a required parameter.
+ * `clientSecret` The clientSecret can be obtained from MailChimp, please refer to the API docs on how to do this. The clientSecret is a required parameter.
+ * `serverUri` The URI to reach this server from the internet. This URI is required as MailChimp sends a request upon successful authorization of a user.
+ * `redirectUri` After a successful authorization on the MailChimp website the user is redirected to this URI, if any.
+ * `port` The port the server is going to listen on. Defaults to 8100.
+ * `secure` Credentials as generated by the crypto module. If present HTTPS support is enabled for the server. Defaults to false.
+
+You can register the following events:
+
+ * `error` This event is emitted when an error occured and receives one argument that contains the error message.
+ * `authed` Emitted when the OAuth was completed successfully. Receives one argument which represents the API key that can be passed on to other API functionality.
+
+Example:
+
+ var MailChimpOAuth = require('mailchimp').MailChimpOAuth;
+ var MailChimpAPI = require('mailchimp').MailChimpAPI;
+
+ var options = {
+ clientId: 'Your MailChimp client id',
+ clientSecret: 'Your MailChimp client secret',
+ serverUri: 'http://www.example.com',
+ redirectUri: 'http://www.example.com/successfulLogin.html'
+ };
+
+ var oauth = new MailChimpOAuth(options);
+
+ console.log(oauth.getAuthorizeUri()); // The MailChimp login URI the user needs to be sent to
+
+ oauth.on('error', function (message) {
+ console.log('Error: '+message);
+ });
+
+ oauth.on('authed', function (apiKey) {
+
+ 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!
+ });
+
+ });
+
## License
_node-mailchimp_ is licensed under the MIT License. (See LICENSE)

0 comments on commit 6e81352

Please sign in to comment.