Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from attech-org/feature/api-typings
feat: created api typing
- Loading branch information
Showing
2 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,35 @@ | ||
import axios from 'axios'; | ||
|
||
import { ComingSoon, Top250Movies } from './types'; | ||
|
||
const moviesApi = axios.create({ | ||
baseURL: 'https://imdb-api.com/en/API/', | ||
}); | ||
|
||
export const top250Movies = async () => { | ||
try { | ||
const res = await moviesApi.get('/'); | ||
console.warn(res); | ||
const res = await moviesApi.get<Top250Movies>(`Top250Movies/${process.env.REACT_APP_API_KEY}`); | ||
if (res.data.errorMessage) { | ||
throw new Error(res.data.errorMessage); | ||
} else { | ||
return res.data.items; | ||
} | ||
} catch (e) { | ||
console.warn(e); | ||
return false; | ||
} | ||
}; | ||
|
||
export const comingSoon = async () => { | ||
try { | ||
const res = await moviesApi.get('/'); | ||
console.warn(res); | ||
const res = await moviesApi.get<ComingSoon>(`ComingSoon/${process.env.REACT_APP_API_KEY}`); | ||
if (res.data.errorMessage) { | ||
throw new Error(res.data.errorMessage); | ||
} else { | ||
return res.data.items; | ||
} | ||
} catch (e) { | ||
console.warn(e); | ||
return false; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
export interface Top250Movies { | ||
errorMessage: string; | ||
items: Movie[]; | ||
} | ||
interface Movie { | ||
// max.haveSexWith(typeScript) | ||
crew: string; | ||
fullTitle: string; | ||
id: string; | ||
imDbRating: string; | ||
imDbRatingCount: string; | ||
image: string; | ||
rank: string; | ||
title: string; | ||
year: string; | ||
} | ||
|
||
export interface ComingSoon { | ||
errorMessage: string; | ||
items: ComingSoonItem[]; | ||
} | ||
interface ComingSoonItem { | ||
contentRating: string; | ||
directorList: ComingSoonDirectorList[]; | ||
directors: string; | ||
fullTitle: string; | ||
genreList: ComingSoonOtherList[]; | ||
genres: string; | ||
id: string; | ||
imDbRating: string; | ||
imDbRatingCount: string; | ||
image: string; | ||
metacriticRating: string; | ||
plot: string; | ||
releaseState: string; | ||
runtimeMins: string; | ||
runtimeStr: string; | ||
starList: ComingSoonOtherList[]; | ||
stars: string; | ||
title: string; | ||
year: string; | ||
} | ||
|
||
interface ComingSoonDirectorList { | ||
id: string; | ||
name: string; | ||
} | ||
|
||
interface ComingSoonOtherList { | ||
key: string; | ||
value: string; | ||
} |