This commit is contained in:
Skylar Grant 2024-09-21 21:55:04 -04:00
parent f632605a55
commit efdc51ab85
2 changed files with 93 additions and 0 deletions

24
src/TenorJSv2.js Normal file
View File

@ -0,0 +1,24 @@
module.exports = {
Tenor: class Tenor {
constructor(tenorApiKey) {
this.token = tenorApiKey;
}
configure() {
}
},
Request: class Request {
constructor() {
}
get() {
}
post() {
}
}
}

69
src/main.js Normal file
View File

@ -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();