Skip to content

Instantly share code, notes, and snippets.

@scottgarner
Created July 23, 2015 13:17
Show Gist options
  • Save scottgarner/fc4ab086987497369c68 to your computer and use it in GitHub Desktop.
Save scottgarner/fc4ab086987497369c68 to your computer and use it in GitHub Desktop.
Parse and Mandril Example
require('cloud/app.js');
// Use Parse.Cloud.define to define as many cloud functions as you want.
// For example:
var Experience = Parse.Object.extend("Experience");
var Mandrill = require('mandrill');
Mandrill.initialize('XXXXXX');
Parse.Cloud.define("email", function(request, response) {
var query = new Parse.Query(Experience);
query.get(request.params.objectId, {
success: function(object) {
if (object.get("sent") == false) {
if (object.get("email") != "" && object.get("email") != null) {
Mandrill.sendTemplate({
template_name: "experience",
template_content: [],
message: {
to: [{
email: object.get("email"),
name: null
}],
"merge": true,
"merge_language": "mailchimp",
"global_merge_vars": [{
"name": "image",
"content": object.get("image").url()
},
{
"name": "url",
"content": "http://atomic.parseapp.com/view/" + object.id
},
{
"name": "id",
"content": object.id
}]
},
async: true
},{
success: function(httpResponse) {
console.log(httpResponse.text);
response.success(httpResponse.text);
},
error: function(httpResponse) {
console.error(httpResponse.text);
response.error(httpResponse.text);
}
});
} else {
response.error("Email invalid.");
}
} else {
response.error("Already sent.");
}
},
error: function(object, error) {
response.error("Can't find object.");
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment