diff --git a/src/TenorJSv2.js b/src/TenorJSv2.js new file mode 100644 index 0000000..6827984 --- /dev/null +++ b/src/TenorJSv2.js @@ -0,0 +1,24 @@ +module.exports = { + Tenor: class Tenor { + constructor(tenorApiKey) { + this.token = tenorApiKey; + } + + configure() { + + } + }, + Request: class Request { + constructor() { + + } + + get() { + + } + + post() { + + } + } +} \ No newline at end of file diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..052a641 --- /dev/null +++ b/src/main.js @@ -0,0 +1,69 @@ +// url Async requesting function +function httpGetAsync(theUrl, callback) +{ + // create the request object + var xmlHttp = new XMLHttpRequest(); + + // set the state change callback to capture when the response comes in + xmlHttp.onreadystatechange = function() + { + if (xmlHttp.readyState == 4 && xmlHttp.status == 200) + { + callback(xmlHttp.responseText); + } + } + + // open as a GET call, pass in the url and set async = True + xmlHttp.open("GET", theUrl, true); + + // call send with no params as they were passed in on the url string + xmlHttp.send(null); + + return; +} + +// callback for the top 8 GIFs of search +function tenorCallback_search(responsetext) +{ + // parse the json response + var response_objects = JSON.parse(responsetext); + + top_10_gifs = response_objects["results"]; + + // load the GIFs -- for our example we will load the first GIFs preview size (nanogif) and share size (tinygif) + + document.getElementById("preview_gif").src = top_10_gifs[0]["media"][0]["nanogif"]["url"]; + + document.getElementById("share_gif").src = top_10_gifs[0]["media"][0]["tinygif"]["url"]; + + return; + +} + + +// function to call the trending and category endpoints +function grab_data() +{ + // set the apikey and limit + var apikey = "LIVDSRZULELA"; + var lmt = 8; + + // test search term + var search_term = "excited"; + + // using default locale of en_US + var search_url = "https://g.tenor.com/v1/search?q=" + search_term + "&key=" + + apikey + "&limit=" + lmt; + + httpGetAsync(search_url,tenorCallback_search); + + // data will be loaded by each call's callback + return; +} + + +// SUPPORT FUNCTIONS ABOVE +// MAIN BELOW + +// start the flow +grab_data(); \ No newline at end of file