Skip to content

Commit

Permalink
Merge pull request #8 from attech-org/feature/api-typings
Browse files Browse the repository at this point in the history
feat: created api typing
  • Loading branch information
alexandrtovmach committed Nov 22, 2021
2 parents 921ac5f + 0902ad9 commit 13aeca3
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/services/api.ts
@@ -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;
}
};
52 changes: 52 additions & 0 deletions src/services/types.ts
@@ -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;
}

0 comments on commit 13aeca3

Please sign in to comment.