Skip to content

Instantly share code, notes, and snippets.

@shrutis22
Last active May 9, 2018 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shrutis22/e1fc9d0830a88b1ad54c54197f0da677 to your computer and use it in GitHub Desktop.
Save shrutis22/e1fc9d0830a88b1ad54c54197f0da677 to your computer and use it in GitHub Desktop.
({
getGiphyImage : function( emotion, callback ) {
var xhr = new XMLHttpRequest();
xhr.open( "GET", "https://api.giphy.com/v1/gifs/search?api_key=B9pfrx9wtMXmdLnVaJ6vllAW7uTqaHvO&q=" + emotion + "&limit=1", false )
xhr.onreadystatechange = function() {
if( this.readyState === 4 ) {
var jsonResp = JSON.parse( this.response );
var gifUrl = jsonResp.data[0].images.downsized.url;
callback( gifUrl );
}
};
xhr.send();
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment