Skip to content

Instantly share code, notes, and snippets.

@kohlikohl
Created March 27, 2013 17:52
Show Gist options
  • Save kohlikohl/5256525 to your computer and use it in GitHub Desktop.
Save kohlikohl/5256525 to your computer and use it in GitHub Desktop.
Multiple methodes
SendGridClient.prototype.send = function (message, parameters) {
var deferred = when.defer();
when(parameters,
this._sendEmail.bind(this, deferred, message),
function (error) {
deferred.reject(error);
}
);
return deferred.promise;
};
SendGrid.prototype._sendEmail = function(parameters, deferred, message) {
var email = new SendGridEmail(parameters),
categories = message.get("categories"),
guid = guidGen();
if (categories) {
this._addCategories(email, categories);
}
this._sendGrid.send(email, function (success, errMessage) {
if (!success) {
deferred.reject({"error": errMessage, "action": "postpone"});
} else {
deferred.resolve(guid);
}
});
};
SendGridClient.prototype._addCategories = function(email, categories){
var i;
for (i in categories) {
email.addCategory(categories[i]);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment