gistfile1.js

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(); } }); }); });
fullsies.js

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.