From 64c6aa337f9e2623d409e082ec5a9569c34b8d84 Mon Sep 17 00:00:00 2001 From: renantatsuo Date: Mon, 28 Sep 2020 22:23:33 -0300 Subject: [PATCH] Create User lib --- lib/static/index.ts | 21 +++++++++++++++++++++ lib/user/GithubUser.ts | 21 +++++++++++++++++++++ lib/user/SocialNetwork.ts | 12 ++++++++++++ lib/user/User.ts | 9 +++++++++ lib/user/Users.ts | 20 ++++++++++++++++++++ 5 files changed, 83 insertions(+) create mode 100644 lib/static/index.ts create mode 100644 lib/user/GithubUser.ts create mode 100644 lib/user/SocialNetwork.ts create mode 100644 lib/user/User.ts create mode 100644 lib/user/Users.ts diff --git a/lib/static/index.ts b/lib/static/index.ts new file mode 100644 index 0000000..85d4989 --- /dev/null +++ b/lib/static/index.ts @@ -0,0 +1,21 @@ +import SocialNetwork, { SocialNetworks } from "@lib/user/SocialNetwork"; +/** + * Some static information. + */ + +export const GITHUB_URL = "https://api.github.com/users/renantatsuo"; + +export const SOCIAL_NETWORKS: SocialNetwork[] = [ + { + name: SocialNetworks.GITHUB, + url: "https://github.com/renantatsuo", + }, + { + name: SocialNetworks.CODEPEN, + url: "https://codepen.io/renantatsuo", + }, + { + name: SocialNetworks.TWITTER, + url: "https://twitter.com/renantatsuo", + }, +]; diff --git a/lib/user/GithubUser.ts b/lib/user/GithubUser.ts new file mode 100644 index 0000000..293ab70 --- /dev/null +++ b/lib/user/GithubUser.ts @@ -0,0 +1,21 @@ +type GithubUser = { + login: string; + id: number; + avatar_url: string; + gravatar_id: string; + url: string; + html_url: string; + followers_url: string; + following_url: string; + gists_url: string; + starred_url: string; + subscriptions_url: string; + organizations_url: string; + repos_url: string; + events_url: string; + received_events_url: string; + type: string; + site_admin: boolean; +}; + +export default GithubUser; diff --git a/lib/user/SocialNetwork.ts b/lib/user/SocialNetwork.ts new file mode 100644 index 0000000..39f1ca9 --- /dev/null +++ b/lib/user/SocialNetwork.ts @@ -0,0 +1,12 @@ +export enum SocialNetworks { + TWITTER = "twitter", + GITHUB = "github", + CODEPEN = "codepen", +} + +type SocialNetwork = { + name: SocialNetworks; + url: string; +}; + +export default SocialNetwork; diff --git a/lib/user/User.ts b/lib/user/User.ts new file mode 100644 index 0000000..9a2a306 --- /dev/null +++ b/lib/user/User.ts @@ -0,0 +1,9 @@ +import SocialNetwork from "./SocialNetwork"; + +type User = { + username: string; + avatar: string; + social: SocialNetwork[]; +}; + +export default User; diff --git a/lib/user/Users.ts b/lib/user/Users.ts new file mode 100644 index 0000000..897e027 --- /dev/null +++ b/lib/user/Users.ts @@ -0,0 +1,20 @@ +import Http from "@lib/http/Http"; +import { GITHUB_URL, SOCIAL_NETWORKS } from "@lib/static"; +import { container } from "tsyringe"; +import "../AppContainer"; +import GithubUser from "./GithubUser"; +import SocialNetwork from "./SocialNetwork"; +import User from "./User"; + +const http: Http = container.resolve("Http"); + +export async function getUser(): Promise { + const user: GithubUser = await http.execute(GITHUB_URL); + const socialNetworks: SocialNetwork[] = SOCIAL_NETWORKS; + + return { + avatar: user.avatar_url, + username: user.login, + social: socialNetworks, + }; +}