Comparing version
@@ -1,1 +0,5 @@ | ||
module.exports = require('./lib'); | ||
exports.SendGrid = require('./lib/sendgrid'); | ||
exports.connect = function(options) { | ||
return new exports.SendGrid(options); | ||
}; |
@@ -1,132 +0,22 @@ | ||
var Request = require('./request') | ||
, Email = require('./email') | ||
, utils = require('./utils'); | ||
var SendGrid = module.exports = function(config) { | ||
this.config = config; | ||
} | ||
var path = require('path') | ||
, request = require('superagent'); | ||
SendGrid.prototype = { | ||
var SendGrid = module.exports = function(options) { | ||
this.options = options || {}; | ||
this.options.base = this.options.base || 'https://sendgrid.com/api/'; | ||
this.options.format = this.options.format || 'json'; | ||
}; | ||
/* | ||
*/ | ||
compose: function(options) { | ||
return new Email(this.config).settings(options); | ||
}, | ||
email: function(options, callback) { | ||
var email = this.compose(options); | ||
if (typeof callback == 'function') { | ||
email.send(callback); | ||
} else { | ||
return email; | ||
} | ||
}, | ||
SendGrid.prototype.request = function(p) { | ||
var r = request.post(this.options.base + p + '.' + this.options.format); | ||
r.type('form'); | ||
r.send({ | ||
api_user: this.options.api_user | ||
, api_key: this.options.api_key | ||
}); | ||
return r; | ||
}; | ||
/* | ||
Profile | ||
*/ | ||
getProfile: function(callback) { | ||
var req = new Request(this.config); | ||
req._send('profile', 'get', callback); | ||
}, | ||
setProfile: function(options, callback) { | ||
var req = new Request(this.config).settings(options); | ||
req._send('profile', 'set', callback); | ||
}, | ||
setUsername: function(username, callback) { | ||
var req = new Request(this.config).settings({ username: username }); | ||
req._send('profile', 'setUsername', callback); | ||
}, | ||
setPassword: function(password, callback) { | ||
var req = new Request(this.config).settings({ password: password, confirm_password: password }); | ||
req._send('password', 'set', callback); | ||
}, | ||
setEmail: function(email, callback) { | ||
var req = new Request(this.config).settings({ email: email }); | ||
req._send('profile', 'setEmail', callback); | ||
}, | ||
/* | ||
Bounces | ||
*/ | ||
getBounces: function(date, callback) { | ||
this._retrieve('bounces', date, callback); | ||
}, | ||
deleteBounces: function(email, callback) { | ||
this._delete('bounces', email, callback); | ||
}, | ||
/* | ||
Subscription management | ||
*/ | ||
unsubscribe: function(email, callback) { | ||
var req = new Request(this.config).settings({ email: email }); | ||
req._send('unsubscribes', 'add', callback); | ||
}, | ||
getUnsubscribes: function(date, callback) { | ||
this._retrieve('unsubscribes', date, callback); | ||
}, | ||
deleteUnsubscribes: function(email, callback) { | ||
this._delete('unsubscribes', email, callback); | ||
}, | ||
/* | ||
Newsletter management | ||
*/ | ||
addRecipientToList: function(list, name, email, callback) { | ||
var req = new Request(this.config); | ||
req.settings({ | ||
list: list | ||
, data: JSON.stringify({ name: name, email: email }) | ||
}); | ||
req._send('newsletter/lists/email/add', '', callback) | ||
}, | ||
removeRecipientFromList: function(list, email, callback) { | ||
var req = new Request(this.config); | ||
req.settings({ | ||
list: list | ||
, email: email | ||
}); | ||
req._send('newsletter/lists/email', 'delete', callback) | ||
}, | ||
/* | ||
Spam reports | ||
*/ | ||
getSpamReports: function(date, callback) { | ||
this._retrieve('spamreports', date, callback); | ||
}, | ||
deleteSpamReports: function(email, callback) { | ||
this._delete('spamreports', email, callback); | ||
}, | ||
/* | ||
Invalid emails | ||
*/ | ||
getInvalidEmails: function(date, callback) { | ||
this._retrieve('invalidemails', date, callback); | ||
}, | ||
deleteInvalidEmails: function(email, callback) { | ||
this._delete('invalidemails', email, callback); | ||
}, | ||
_retrieve: function(module, date, callback) { | ||
var req = new Request(this.config); | ||
if (typeof callback == 'undefined') { | ||
callback = date; | ||
req.settings({ date: 1 }); | ||
} else if (date === true) { | ||
req.settings({ date: 1 }); | ||
} | ||
req._send(module, 'get', callback); | ||
}, | ||
_delete: function(module, email, callback) { | ||
var req = new Request(this.config).settings({ email: email }); | ||
req._send(module, 'delete', callback); | ||
} | ||
SendGrid.prototype.email = function(options, fn) { | ||
this.request('mail.send').send(options).end(fn); | ||
}; |
{ "name": "sgrid" | ||
, "description": "Nodejs Sendgrid client for the rest api" | ||
, "description": "NodeJS client for the Sendgrid Web API" | ||
, "author": "Storify <dev@storify.com> (http://storify.com)" | ||
@@ -8,8 +8,13 @@ , "contributors": [ | ||
] | ||
, "version": "0.0.2" | ||
, "version": "0.0.3" | ||
, "keywords": ["mail", "email"] | ||
, "repository": "git://github.com/storify/node-sendgrid" | ||
, "repository": "git://github.com/storify/sgrid" | ||
, "main": "./index.js" | ||
, "engines": { "node": ">= 0.4.4" } | ||
, "bin": { "mail": "./bin/mail" } | ||
, "dependencies": { | ||
"superagent": "0.3.x" | ||
} | ||
, "devDependencies": { | ||
"should": "0.5.x" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
2
-50%12128
-56.37%1
Infinity%1
Infinity%10
-50%220
-69.01%+ Added
+ Added
+ Added