diff --git a/task-1/index.ts b/task-1/index.ts index 55e9401..c070825 100644 --- a/task-1/index.ts +++ b/task-1/index.ts @@ -10,6 +10,14 @@ import fetch from "node-fetch"; * Проверяет существование пользователя на GH * @param username - юзернейм */ -export function isUserExist(username: string): Promise{ +export async function isUserExist(username: string): Promise { + const url = `https://api.github.com/users/${username}`; + const answer = await fetch(url , { + method: 'GET', + headers: { + 'Content-Type': 'application/json;charset=utf-8' + } + }); + return answer.ok; -} +} \ No newline at end of file diff --git a/task-2/index.ts b/task-2/index.ts index 72204c4..874f185 100644 --- a/task-2/index.ts +++ b/task-2/index.ts @@ -12,10 +12,17 @@ */ export interface CatFactResponseModel{ + fact: string; + length: number; } export interface TranslateRequestModel{ + q: string; + source: string; + target: string; + format: "text"|"html"; } export interface TranslateResponseModel{ -} + translatedText: string; +} \ No newline at end of file diff --git a/task-3/index.ts b/task-3/index.ts index 4497e60..5763971 100644 --- a/task-3/index.ts +++ b/task-3/index.ts @@ -4,6 +4,13 @@ * С помощью предыдущих моделей запроси рандомный факт о котиках */ -export function getCatFact(): Promise{ +import fetch from "node-fetch"; +import {CatFactResponseModel} from "../task-2"; -} +export async function getCatFact(): Promise { + const answer = await fetch("https://catfact.ninja/fact"); + if (answer.ok){ + return await answer.json() as CatFactResponseModel + } + throw new Error(); +} \ No newline at end of file diff --git a/task-4/index.ts b/task-4/index.ts index ea39628..b2597dc 100644 --- a/task-4/index.ts +++ b/task-4/index.ts @@ -4,7 +4,22 @@ * Так как мы получаем факты о котиках на непонятном языке, * давай переведем их на русский)) */ +import {CatFactResponseModel, TranslateResponseModel} from "../task-2"; +import fetch from "node-fetch"; -export function translateCatFact(fact: CatFactResponseModel): Promise{ - -} +export async function translateCatFact(fact: CatFactResponseModel): Promise{ + const answer = await fetch("https://trans.zillyhuhn.com/translate", { + method: "POST", + body: JSON.stringify({ + q: fact.fact, + source: "en", + target: "ru", + format: "text" + }), + headers: { "Content-Type": "application/json" } + }); + if(answer.ok) { + return await answer.json() as TranslateResponseModel; + } + throw new Error(); +} \ No newline at end of file