Permalink
Browse files

Made the plugin more flexible for the expansion of the API and more f…

…lexible with the parameters you need to include
  • Loading branch information...
Jon Lim
Jon Lim committed Aug 15, 2011
1 parent e9721dd commit caa1aa3ff1b4719b81752b16208b84c063947ff9
Showing with 33 additions and 19 deletions.
  1. +32 −18 lib/postageapp.js
  2. +1 −1 package.json
View
@@ -1,10 +1,11 @@
var http = require('http');
+var fs = require('fs');
var postageVersion = '1.0.0';
module.exports = function(apiKey) {
return {
- apiCall: function (emailRecipients, emailContent, emailSubject, emailFrom, emailVariables) {
+ sendMessage: function (options) {
var api = http.createClient(80, 'api.postageapp.com');
var request = api.request('POST', '/v.1.0/send_message.json',
@@ -14,41 +15,54 @@ module.exports = function(apiKey) {
'user-agent': 'PostageApp Node.JS ' + postageVersion + ' (Node.JS ' + process.version + ')'
});
- var templateName = new String();
+ var recipients = options.recipients;
+
+ var subject = options.subject;
+ var from = options.from;
+
+ var content = options.content;
+
+ var template = options.template;
+ var variables = options.variables;
- if (isNaN(emailContent)) {
- templateName = emailContent;
- emailSubject = null;
- emailContent = null;
- emailFrom = null;
- } else if (isArray(emailContent)) {
-
- }
-
+ /*
+ Creates a string of numbers to be used for the UID, which has to be a unique identifier in order
+ to prevent duplicate sending through PostageApp.
+ */
var date = new Date;
var epochDate = date.getTime();
+ /*
+ Payload is the aggregated data that will be passed to the API server including all of the parameters
+ required to send an email through PostageApp.
+ */
var payload = {
api_key: apiKey,
uid: epochDate,
arguments: {
- recipients: emailRecipients,
+ recipients: recipients,
headers: {
- subject: emailSubject,
- from: emailFrom
+ subject: subject,
+ from: from
},
- content: emailContent,
+ content: content,
- template: templateName,
+ template: template,
- variables: emailVariables
+ variables: variables,
}
}
- request.on('response', function (response) {});
+ request.on('response', function (response) {
+ console.log('STATUS: ' + response.statusCode);
+ response.setEncoding('utf8');
+ response.on('data', function (chunk) {
+ console.log('BODY: ' + chunk);
+ });
+ });
request.end(JSON.stringify(payload));
},
View
@@ -1,6 +1,6 @@
{
"name": "postageapp",
- "version": "0.0.3",
+ "version": "0.0.5",
"node": ">= 0.4.0",
"homepage": "https://github.com/postageapp/postageapp-nodejs",
"repository": {

0 comments on commit caa1aa3

Please sign in to comment.