Skip to content

Commit

Permalink
Modularized utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ytanay committed Feb 25, 2014
1 parent 8ba5300 commit 11970da
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 36 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: node_js
node_js:
- '0.10'
- '0.8'
before_script:
- npm install -g grunt-cli
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Stupidly easy mailing with Amazon AWS SES (Simple Email Service)
Install the module with: `npm install ultrases`

```javascript
var ultrases = require('ultrases');
ultrases.awesome(); // "awesome"
var UltraSES = require('ultrases');
var mailer = new UltraSES({...}); // "awesome"
```

## Documentation
Expand Down
31 changes: 3 additions & 28 deletions lib/ultrases.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,11 @@

'use strict';

function checkRequiredParams(config) {
if(!config.aws){
throw new TypeError('you must pass an AWS config object to the constructor in the form of {accessKeyId, secretAccessKey, region}');
}
var required = {'accessKeyId': 'string', 'secretAccessKey': 'string'};
for(var prop in required){
if(typeof config.aws[prop] !== required[prop]){
throw new TypeError('\'' + prop + '\' must be of type ' + required[prop] + ' (currently ' + typeof config[prop] + ')');
}
}
}

function checkRequiredParamsSend(params) {
var props = {from: 'string', to: 'array', cc: 'array', bcc: 'array', subject: 'string', text: 'string', html: 'string', replyTo: 'array', returnPath: 'string'};
for(var prop in props){
if(props[prop] === 'array'){
if(!Array.isArray(params[prop])){
throw new TypeError('\'' + prop + '\' must be of array');
}
} else {
if(typeof params[prop] !== props[prop]){
throw new TypeError('\'' + prop + '\' must be of ' + props[prop]);
}
}
}
}
var util = require('./util');

function UltraSES(config){

checkRequiredParams(config);
util.checkRequiredParams(config);

var AWS = require('aws-sdk');
AWS.config.update(config.aws);
Expand All @@ -48,7 +23,7 @@ function UltraSES(config){

UltraSES.prototype.send = function(data, done) {
data = this._typer(this._merge(data));
checkRequiredParamsSend(data);
util.checkRequiredParamsSend(data);
this.ses.sendEmail({
Source: data.from,
Destination: {
Expand Down
36 changes: 36 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* ultrases
* http://dev.paticon.com/module/ultrases
*
* Copyright (c) 2014 Yotam Tanay
* Licensed under the MIT license.
*/

'use strict';

exports.checkRequiredParams = function checkRequiredParams(config) {
if(!config.aws){
throw new TypeError('you must pass an AWS config object to the constructor in the form of {accessKeyId, secretAccessKey, region}');
}
var required = {'accessKeyId': 'string', 'secretAccessKey': 'string'};
for(var prop in required){
if(typeof config.aws[prop] !== required[prop]){
throw new TypeError('\'' + prop + '\' must be of type ' + required[prop] + ' (currently ' + typeof config[prop] + ')');
}
}
};

exports.checkRequiredParamsSend = function checkRequiredParamsSend(params) {
var props = {from: 'string', to: 'array', cc: 'array', bcc: 'array', subject: 'string', text: 'string', html: 'string', replyTo: 'array', returnPath: 'string'};
for(var prop in props){
if(props[prop] === 'array'){
if(!Array.isArray(params[prop])){
throw new TypeError('\'' + prop + '\' must be of array');
}
} else {
if(typeof params[prop] !== props[prop]){
throw new TypeError('\'' + prop + '\' must be of ' + props[prop]);
}
}
}
};
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "ultrases",
"version": "0.0.0",
"version": "0.0.1",
"main": "lib/ultrases.js",
"description": "Stupidly easy mailing with Amazon AWS SES (Simple Email Service)",
"description": "Dead simple email dispatch with AWS SES (Amazon Simple Email Service)",
"homepage": "http://dev.paticon.com/module/ultrases",
"bugs": "https://github.com//ultrases/issues",
"author": {
Expand All @@ -19,9 +19,7 @@
"type": "MIT"
}
],
"files": [ ],
"keywords":[
],
"keywords": ["ses", "aws", "email"],
"devDependencies": {
"grunt-contrib-jshint": "~0.7.0",
"grunt-contrib-nodeunit": "~0.2.0",
Expand Down

0 comments on commit 11970da

Please sign in to comment.