Last active
October 11, 2016 21:43
-
-
Save pkpp1233/6407380bd75e0470950e to your computer and use it in GitHub Desktop.
fullsies.js
This file contains hidden or 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 blockspring = require("blockspring"); | |
var requests = require("request"); | |
var fs = require("fs"); | |
blockspring.define(function(request, response) { | |
name = "Hi! My name is " + request.params.first_name; | |
age = " and my age is " + request.params.age.toString(); | |
response.addOutput('intro', name + age); | |
// run this function remotely https://api.blockspring/pkpp1233/806a62b680e1148d57cc65bdfc048805. Pass in a callback for blockspring.run. | |
blockspring.run("pkpp1233/806a62b680e1148d57cc65bdfc048805", {"age": request.params.age}, function(famous){ | |
// add the result of this function to our response | |
response.addOutput("famous", "A famous person my age is " + famous.famous); | |
// run an image search https://api.blockspring/pkpp1233/57d4be79541775e807fffe5f1dffca59. Pass in a callback for blockspring.run. | |
blockspring.run("pkpp1233/57d4be79541775e807fffe5f1dffca59", {"text_search": famous.famous}, function(famous_image){ | |
try { | |
var file = fs.createWriteStream("image.png"); | |
requests(famous_image.image).pipe(file); | |
file.on('finish', function() { | |
// add a file to the output. Pass in a callback | |
response.addFileOutput("image", "image.png", function(){ | |
response.end(); | |
}); | |
}); | |
} catch (err){ | |
response.addErrorOutput("Image error", "couldn't find an image of your famous peer."); | |
response.end(); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment