Created
January 19, 2013 23:05
-
-
Save theycallmeswift/4575751 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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