Permalink
Browse files

allow configuration of api key

  • Loading branch information...
1 parent 88bb763 commit 733362fcdb703a17b5dd8ec9e1c411b21483a963 Visnu Pitiyanuvath committed Jul 12, 2011
Showing with 51 additions and 51 deletions.
  1. +51 −51 lib/postageapp.js
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 ' + 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));
+
+ }
+ }
+};

0 comments on commit 733362f

Please sign in to comment.