Skip to content

Instantly share code, notes, and snippets.

@theycallmeswift
Created January 19, 2013 23:05
Show Gist options
  • Save theycallmeswift/4575751 to your computer and use it in GitHub Desktop.
Save theycallmeswift/4575751 to your computer and use it in GitHub Desktop.
var arduino = require("johnny-five")
, board = new arduino.Board()
, photo = require('./photo')
, SendGrid = require('sendgrid').SendGrid
, sg = new SendGrid(process.env.SENDGRID_USER, process.env.SENDGRID_PASS);
board.on("ready", function() {
var button = new arduino.Button(3);
button.on("up", function() {
photo(function(err, html) {
sg.send({
to: "[email protected]",
from: "[email protected]",
subject: "Stop tweeting!",
html: html
}, function() {
console.log(arguments);
});
});
});
});
{
"name": "swift_sendgrid_demo_3",
"version": "0.0.1",
"description": "Arduino powered SendGridness.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": "",
"keywords": [
"SendGrid",
"Arduino"
],
"author": "Swift <[email protected]>",
"license": "Beerware",
"dependencies": {
"sendgrid": "~0.2.4",
"johnny-five": "~0.5.14",
"request": "~2.12.0"
}
}
module.exports = function getImage(cb) {
var request = require('request')
, callback = cb || function() {}
, tumblr_key = process.env.TUMBLR_KEY
, post = Math.floor((Math.random()*96))
, url = "http://api.tumblr.com/v2/blog/programmerryangosling.tumblr.com/posts?api_key=" + tumblr_key + "&type=photo&limit=1&offset=" + post;
request(url, function(err, res, body) {
try {
var image = JSON.parse(body).response.posts[0].photos[0].original_size.url;
callback(err, "<img src='" + image + "' width='50%' />");
} catch(e) {
callback(e);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment