Skip to content

Instantly share code, notes, and snippets.

@bignimbus
Last active October 16, 2015 20:03
Show Gist options
  • Save bignimbus/4e61d7bade1ca0e62cfd to your computer and use it in GitHub Desktop.
Save bignimbus/4e61d7bade1ca0e62cfd to your computer and use it in GitHub Desktop.
Math.PIE() - a proposed ECMAScript 7 feature
// in order for this to work, you need a yummly dev account.
function makePie (response) {
var match = JSON.parse(response).matches[0],
yourPie = ["you could bake a delicious ",
match.recipeName,
" using "];
match.ingredients.forEach(function (ingredient) {
yourPie.push("[" + ingredient + "]");
});
return yourPie.join('');
}
Math.PIE = function (ingredients) {
ingredients = (ingredients instanceof Array ? ingredients.join('+') : ingredients) || "";
var req = new XMLHttpRequest();
req.onreadystatechange = function () {
if (req.readyState == 4 && req.status == 200) {
console.log(makePie(req.responseText));
}
};
req.open("GET",
"https://api.yummly.com/v1/api/recipes?_app_id=##YUMMLY_API_ID##&_app_key=##YUMMLY_API_KEY##&q=pie+"
+ ingredients,
false);
req.send();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment