DEV/DEV4.1/test/test/test.js
2024-03-25 17:33:16 +01:00

139 lines
5.0 KiB
JavaScript

function apiManager() {
key = "92f0f56afffd55f39d43937ed6899e00";
let URL = "https://api.themoviedb.org/3/";
let request = { search, searchMovie, searchTV, searchPerson, popMovie, trendMovie, topMovie, upcomingMovie,
getMovieCredits, popTV, todayTV, weekTV, topTV, findPeopleID, findPeopleID, findPeopleName,
getPeopleCreditsTV, getPeopleCreditsMovie
};
function search(input,page_index) { //multisearch
return fetch(URL + "search/multi?query="+ input +"&api_key=" + key + "&page=" + page_index + "&language=fr")
.then(response => response.json())
.then(data => data);
console.log(response.json)
}
function searchMovie(input,page_index) {
return fetch(URL + "search/movie?query="+ input +"&api_key=" + key + "&page=" + page_index + "&language=fr")
.then(response => response.json())
.then(data => data);
console.log(response.json)
}
function searchTV(input,page_index) {
return fetch(URL + "search/tv?query="+ input +"&api_key=" + key + "&page=" + page_index + "&language=fr")
.then(response => response.json())
.then(data => data);
console.log(response.json)
}
function searchPerson(input,page_index) {
return fetch(URL + "search/person?query="+ input +"&api_key=" + key + "&page=" + page_index + "&language=fr")
.then(response => response.json())
.then(data => data);
console.log(response.json)
}
//Movie
function popMovie(page_index) {
return fetch(URL + "movie/popular?&api_key=" + key + "&page=" + page_index + "&language=fr")
.then(response => response.json())
.then(data => data);
console.log(response.json)
}
function trendMovie(page_index) {
return fetch(URL + "trending/movie/day?&api_key=" + key + "&page=" + page_index + "&language=fr")
.then(response => response.json())
.then(data => data);
console.log(response.json)
}
function topMovie(page_index) {
return fetch(URL + "movie/top_rated?&api_key=" + key + "&page=" + page_index + "&language=fr")
.then(response => response.json())
.then(data => data);
console.log(response.json)
}
function upcomingMovie(page_index) {
return fetch(URL + "movie/upcoming?&api_key=" + key + "&page=" + page_index + "&language=fr")
.then(response => response.json())
.then(data => data);
console.log(response.json)
}
function getMovieCredits(id) {
return fetch(URL + "movie/" + id + "/credits?&api_key=" + key + "&language=fr")
.then(response => response.json())
.then(data => data);
console.log(response.json)
}
//TV
function popTV(page_index) {
return fetch(URL + "tv/popular?&api_key=" + key + "&page=" + page_index + "&language=fr")
.then(response => response.json())
.then(data => data);
console.log(response.json)
}
function todayTV(page_index) {
return fetch(URL + "tv/airing_today?&api_key=" + key + "&page=" + page_index + "&language=fr")
.then(response => response.json())
.then(data => data);
console.log(response.json)
}
function weekTV(page_index) {
return fetch(URL + "tv/on_the_air?&api_key=" + key + "&page=" + page_index + "&language=fr")
.then(response => response.json())
.then(data => data);
console.log(response.json)
}
function topTV(page_index) {
return fetch(URL + "tv/top_rated?&api_key=" + key + "&page=" + page_index + "&language=fr")
.then(response => response.json())
.then(data => data);
console.log(response.json)
}
//People
function findPeopleID(id) {
return fetch(URL + "person/"+ id +"?&api_key=" + key + "&language=fr")
.then(response => response.json())
.then(data => data);
console.log(response.json)
}
function findPeopleName(name,page_index) {
return fetch(URL + "search/person?query="+ name +"?&api_key=" + key + "&page=" + page_index + "&language=fr")
.then(response => response.json())
.then(data => data);
console.log(response.json)
}
function getPeopleCreditsTV(id) {
return fetch(URL + "person/"+ id + "/tv_credits?&api_key=" + key + "&language=fr")
.then(response => response.json())
.then(data => data);
console.log(response.json)
}
function getPeopleCreditsMovie(id) {
return fetch(URL + "person/"+ id + "/movie_credits?&api_key=" + key + "&language=fr")
.then(response => response.json())
.then(data => data);
console.log(response.json)
}
// TAGGED IMAGES ??
return request;
}