Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configurable api key on require #1

Merged
merged 3 commits into from Jul 12, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -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.
Expand Down
102 changes: 51 additions & 51 deletions 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));

}
}
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));

}
}
};