Permalink
Browse files

Merge pull request #1 from visnup/patch-1

configurable api key on require
  • Loading branch information...
2 parents 88bb763 + 93c3422 commit f8a094a86335597abb86b9af0072537fa0f81c04 @JonLim JonLim committed Jul 12, 2011
Showing with 55 additions and 55 deletions.
  1. +4 −4 README.md
  2. +51 −51 lib/postageapp.js
View
@@ -36,13 +36,13 @@ In your `node_modules` directory type
Usage
-----
-Add your PostageApp Project API key to `lib/postageapp.js':
+When you require the library, make sure to specify your API key:
- var apiKey = 'API KEY HERE';
+ var postageapp = require('postageapp')('YOUR API KEY HERE');
-After that, you should be good to go. Load the module in your app and call the `apiCall` function. Here is a sample of how to use it:ter
+After that, you should be good to go. Load the module in your app and call the `apiCall` function. Here is a sample of how to use it:
- var postageapp = require('postageapp');
+ var postageapp = require('postageapp')('YOUR API KEY HERE');
postageapp.apiCall(recipients, content, subject, from, variables);
Recipients can be passed along as a single string or as an array.
View
@@ -1,54 +1,54 @@
var http = require('http');
-var apiKey = 'API KEY HERE';
+module.exports = function(apiKey) {
+ return {
+ apiCall: function (emailRecipients, emailContent, emailSubject, emailFrom, emailVariables) {
+ var api = http.createClient(80, 'api.postageapp.com');
-var postageapp = module.exports = {
- apiCall: function (emailRecipients, emailContent, emailSubject, emailFrom, emailVariables) {
- var api = http.createClient(80, 'api.postageapp.com');
-
- var request = api.request('POST', '/v.1.0/send_message.json',
- {
- 'host': 'api.postageapp.com',
- 'content-type': 'application/json',
- 'user-agent': 'PostageApp Node.JS ' + postageVersion + ' (Node.JS ' + process.version + ')'
- });
-
- var templateName = new String();
-
- if (isNaN(emailContent)) {
- templateName = emailContent;
- emailSubject = null;
- emailContent = null;
- emailFrom = null;
- } else if (isArray(emailContent)) {
-
- }
-
- var date = new Date;
- var epochDate = date.getTime();
-
- var payload = {
- api_key: apiKey,
- uid: epochDate,
- arguments: {
- recipients: emailRecipients,
-
- headers: {
- subject: emailSubject,
- from: emailFrom
- },
-
- content: emailContent,
-
- template: templateName,
-
- variables: emailVariables
-
- }
- }
-
- request.on('response', function (response) {});
- request.end(JSON.stringify(payload));
-
- }
-}
+ var request = api.request('POST', '/v.1.0/send_message.json',
+ {
+ 'host': 'api.postageapp.com',
+ 'content-type': 'application/json',
+ 'user-agent': 'PostageApp Node.JS 0.0.1 (Node.JS ' + process.version + ')'
+ });
+
+ var templateName = new String();
+
+ if (isNaN(emailContent)) {
+ templateName = emailContent;
+ emailSubject = null;
+ emailContent = null;
+ emailFrom = null;
+ } else if (isArray(emailContent)) {
+
+ }
+
+ var date = new Date;
+ var epochDate = date.getTime();
+
+ var payload = {
+ api_key: apiKey,
+ uid: epochDate,
+ arguments: {
+ recipients: emailRecipients,
+
+ headers: {
+ subject: emailSubject,
+ from: emailFrom
+ },
+
+ content: emailContent,
+
+ template: templateName,
+
+ variables: emailVariables
+
+ }
+ }
+
+ request.on('response', function (response) {});
+ request.end(JSON.stringify(payload));
+
+ }
+ }
+};

0 comments on commit f8a094a

Please sign in to comment.