Skip to content

Instantly share code, notes, and snippets.

@lonekorean
Created March 5, 2017 18:11
Show Gist options
  • Save lonekorean/a49971434a87d56ad760ca1847316b4f to your computer and use it in GitHub Desktop.
Save lonekorean/a49971434a87d56ad760ca1847316b4f to your computer and use it in GitHub Desktop.
Loading a single Gist via the API
const url = 'https://api.github.com/gists/8a6a3c508b7c71deb4070d3314900b1f';
function handleDone(data) {
// this assumes the gist has a single file
let filename = Object.keys(data.files)[0];
let code = data.files[filename].content;
$('pre').text(code);
$('h1').text(data.description);
}
function handleFail() {
console.log('Something went wrong. :(');
}
$.get(url).done(handleDone).fail(handleFail);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment