Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions task-1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import fetch from "node-fetch";
* Проверяет существование пользователя на GH
* @param username - юзернейм
*/
export function isUserExist(username: string): Promise<boolean>{
export async function isUserExist(username: string): Promise<boolean> {
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;

}
}
9 changes: 8 additions & 1 deletion task-2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
11 changes: 9 additions & 2 deletions task-3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
* С помощью предыдущих моделей запроси рандомный факт о котиках
*/

export function getCatFact(): Promise<CatFactResponseModel>{
import fetch from "node-fetch";
import {CatFactResponseModel} from "../task-2";

}
export async function getCatFact(): Promise<CatFactResponseModel> {
const answer = await fetch("https://catfact.ninja/fact");
if (answer.ok){
return await answer.json() as CatFactResponseModel
}
throw new Error();
}
21 changes: 18 additions & 3 deletions task-4/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@
* Так как мы получаем факты о котиках на непонятном языке,
* давай переведем их на русский))
*/
import {CatFactResponseModel, TranslateResponseModel} from "../task-2";
import fetch from "node-fetch";

export function translateCatFact(fact: CatFactResponseModel): Promise<TranslateResponseModel>{

}
export async function translateCatFact(fact: CatFactResponseModel): Promise<TranslateResponseModel>{
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();
}