cinema/service.js

59 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2022-04-01 23:57:41 +02:00
function makeServiceajax(){
let urlBase = "https://api.themoviedb.org/3/"
let apiKey = "3501a3f71bbe8a2f282d299a14602396"
let service = {
searchMovie, doRequest, discover, detailsMovie, sorting, trading, getGenres
};
function doRequest(search){
return fetch(urlBase+"search/movie?api_key"+apiKey+"&language=fr&query"+search+"&page=1")
.then(response => response.json())
.then(data => data)
}
function searchMovie(search){
return fetch(urlBase+"search/movie?api_key="+apiKey+"&language=fr&query="+search+"&page=1")
.then(response => response.json())
.then(data => data)
}
function discover(){
return fetch(urlBase+"discover/movie?api_key="+apiKey+"&language=fr&app&page=1")
.then(response => response.json())
.then(data => data)
}
function detailsMovie(movie_id){
return fetch(urlBase+"discover/movie"+movie_id+"?api_key="+apiKey+"&language=fr&app&page=1")
.then(response => response.json())
.then(data => data)
}
function genres(){
return fetch(urlBase+"discover/movie?api_key="+apiKey+"&language=fr&app&page=1")
.then(response => response.json())
.then(data => data)
}
function getGenres(){
return fetch(urlBase+"genre/movie/list?api_key="+apiKey+"&language=fr&app&page=1")
.then(response => response.json())
.then(data => data)
}
function sorting(type){
return fetch(urlBase+"discover/movie/?api_key="+apiKey+ type +"&language=fr&app&page=1")
.then(response => response.json())
.then(data => data)
}
function trading(){
return fetch(urlBase + "trending/all/day?api_key=" + apiKey + "&language=fr&page=1")
.then(response => response.json())
.then(data => data)
}
return service
}