From e209ae38bb4685c1b800e37aa160db62095ef3ed Mon Sep 17 00:00:00 2001 From: User Date: Thu, 30 Dec 2021 22:09:33 +0500 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BE=D1=80=D0=BE=D0=B1=D1=8C=D0=B5?= =?UTF-8?q?=D0=B2=D0=B0=20=D0=9A=D1=80=D0=B8=D1=81=D1=82=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task-1/index.ts | 12 ++++++++++-- task-2/index.ts | 9 ++++++++- task-3/index.ts | 11 +++++++++-- task-4/index.ts | 21 ++++++++++++++++++--- 4 files changed, 45 insertions(+), 8 deletions(-) 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