forked from lucas.delanier/MovieFinder
parent
8a5b796406
commit
ebc12c478e
@ -1,15 +1,75 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import {Cast, People} from "../components/Movie";
|
||||||
|
import Movie from "../components/Movie";
|
||||||
|
import Config from "../constants/config";
|
||||||
|
|
||||||
|
interface idMovie {
|
||||||
|
id: string
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class apiTMBD {
|
class apiTMBD {
|
||||||
api_key: string = "a133422b5b1f22428e8074470d32186";
|
|
||||||
base_url: string = "https://api.themoviedb.org/3/";
|
|
||||||
|
|
||||||
apiTMDB() {
|
|
||||||
};
|
|
||||||
|
|
||||||
getPopularMovie() {
|
async getTrendingMovie() {
|
||||||
|
const movielist: string[] = [];
|
||||||
|
try {
|
||||||
|
axios.get(Config.base_url + "trending/all/day?api_key=" + Config.api_key).then(async (response) => {
|
||||||
|
await response.data.results.forEach(async function (id: idMovie) {
|
||||||
|
movielist.push(id.id);
|
||||||
|
console.log(id.id);
|
||||||
|
return movielist;
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
return movielist;
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getInfoMovie(id: string) {
|
||||||
|
try {
|
||||||
|
axios.get<Movie>(Config.base_url + "movie/" + id + "?api_key=" + Config.api_key).then(async (response) => {
|
||||||
|
let director = await this.getDirector(response.data.id);
|
||||||
|
console.log("----------");
|
||||||
|
console.log(director);
|
||||||
|
console.log("----------");
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
/*let newmovie = new Movie(movie.id, movie.original_title, movie.poster_path, movie.runtime, movie.vote_average, director)
|
||||||
|
console.log(newmovie);*/
|
||||||
|
return null;
|
||||||
|
} catch (err) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async getDirector(id: string): Promise<string | undefined> {
|
||||||
|
try {
|
||||||
|
const {data: cast} = await axios.get(Config.base_url + "movie/" + id + "/credits?api_key=" + Config.api_key);
|
||||||
|
cast.crew.forEach((people: People) => {
|
||||||
|
if (people.job == "Director") {
|
||||||
|
console.log(people.name);
|
||||||
|
|
||||||
|
return people.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default apiTMBD;
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
import apiTMBD from "../api/tmdb";
|
||||||
|
|
||||||
|
class Movie {
|
||||||
|
id: string
|
||||||
|
original_title: string
|
||||||
|
poster_path: string
|
||||||
|
runtime: number
|
||||||
|
vote_average: number
|
||||||
|
|
||||||
|
director: string | undefined
|
||||||
|
|
||||||
|
constructor(id: string, original_title: string, poster_path: string, runtime: number, vote_average: number, director: string | undefined) {
|
||||||
|
this.id = id;
|
||||||
|
this.original_title = original_title;
|
||||||
|
this.poster_path = poster_path;
|
||||||
|
this.runtime = runtime;
|
||||||
|
this.vote_average = vote_average;
|
||||||
|
this.director = director;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Cast {
|
||||||
|
cast: string
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface People {
|
||||||
|
name: string
|
||||||
|
job: string
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Movie;
|
@ -0,0 +1,4 @@
|
|||||||
|
export default {
|
||||||
|
api_key: "a133422b5b1f22428e8074470d321865",
|
||||||
|
base_url: "https://api.themoviedb.org/3/"
|
||||||
|
}
|
Loading…
Reference in new issue