-
Notifications
You must be signed in to change notification settings - Fork 16
/
script.js
53 lines (45 loc) · 1.51 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const TMDB_BASE_URL = 'https://api.themoviedb.org/3'
const PROFILE_BASE_URL = 'http://image.tmdb.org/t/p/w185'
const BACKDROP_BASE_URL = 'http://image.tmdb.org/t/p/w780'
class App {
static run() {
APIService.fetchMovie(534)
.then(movie => Page.renderMovie(movie))
}
}
class APIService {
static fetchMovie(movieId) {
const url = APIService._constructUrl(`movie/${movieId}`)
return fetch(url)
.then(res => res.json())
.then(json => new Movie(json))
}
static _constructUrl(path) {
return `${TMDB_BASE_URL}/${path}?api_key=${atob('NTQyMDAzOTE4NzY5ZGY1MDA4M2ExM2M0MTViYmM2MDI=')}`
}
}
class Page {
static backdrop = document.getElementById('movie-backdrop')
static title = document.getElementById('movie-title')
static releaseDate = document.getElementById('movie-release-date')
static runtime = document.getElementById('movie-runtime')
static overview = document.getElementById('movie-overview')
static renderMovie(movie) {
Page.backdrop.src = BACKDROP_BASE_URL + movie.backdropPath
Page.title.innerText = movie.title
Page.releaseDate.innerText = movie.releaseDate
Page.runtime.innerText = movie.runtime + " minutes"
Page.overview.innerText = movie.overview
}
}
class Movie {
constructor(json) {
this.id = json.id
this.title = json.title
this.releaseDate = json.release_date
this.runtime = json.runtime
this.overview = json.overview
this.backdropPath = json.backdrop_path
}
}
document.addEventListener("DOMContentLoaded", App.run);