From 733362fcdb703a17b5dd8ec9e1c411b21483a963 Mon Sep 17 00:00:00 2001 From: Visnu Pitiyanuvath Date: Tue, 12 Jul 2011 01:29:40 -0700 Subject: [PATCH 1/3] allow configuration of api key --- lib/postageapp.js | 102 +++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/lib/postageapp.js b/lib/postageapp.js index f5305eb..33dcbbd 100644 --- a/lib/postageapp.js +++ b/lib/postageapp.js @@ -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)); - - } -} \ No newline at end of file + 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)); + + } + } +}; From 3b518b3f4c80933d90712a1aa16c403283e1311e Mon Sep 17 00:00:00 2001 From: Visnu Pitiyanuvath Date: Tue, 12 Jul 2011 01:41:24 -0700 Subject: [PATCH 2/3] missing postageVersion --- lib/postageapp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/postageapp.js b/lib/postageapp.js index 33dcbbd..f9988b6 100644 --- a/lib/postageapp.js +++ b/lib/postageapp.js @@ -9,7 +9,7 @@ module.exports = function(apiKey) { { 'host': 'api.postageapp.com', 'content-type': 'application/json', - 'user-agent': 'PostageApp Node.JS ' + postageVersion + ' (Node.JS ' + process.version + ')' + 'user-agent': 'PostageApp Node.JS 0.0.1 (Node.JS ' + process.version + ')' }); var templateName = new String(); From 93c34229e8eedd6f7205bc4b7568ea35906d16de Mon Sep 17 00:00:00 2001 From: visnu pitiyanuvath Date: Tue, 12 Jul 2011 03:10:10 -0700 Subject: [PATCH 3/3] updated readme on how to specify api key --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b49b6ff..89e4536 100644 --- a/README.md +++ b/README.md @@ -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.