Skip to content

Commit

Permalink
Create User lib
Browse files Browse the repository at this point in the history
  • Loading branch information
renantatsuo committed Sep 29, 2020
1 parent 1c628ef commit 64c6aa3
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/static/index.ts
Original file line number Diff line number Diff line change
@@ -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",
},
];
21 changes: 21 additions & 0 deletions lib/user/GithubUser.ts
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 12 additions & 0 deletions lib/user/SocialNetwork.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export enum SocialNetworks {
TWITTER = "twitter",
GITHUB = "github",
CODEPEN = "codepen",
}

type SocialNetwork = {
name: SocialNetworks;
url: string;
};

export default SocialNetwork;
9 changes: 9 additions & 0 deletions lib/user/User.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import SocialNetwork from "./SocialNetwork";

type User = {
username: string;
avatar: string;
social: SocialNetwork[];
};

export default User;
20 changes: 20 additions & 0 deletions lib/user/Users.ts
Original file line number Diff line number Diff line change
@@ -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<User> {
const user: GithubUser = await http.execute<GithubUser>(GITHUB_URL);
const socialNetworks: SocialNetwork[] = SOCIAL_NETWORKS;

return {
avatar: user.avatar_url,
username: user.login,
social: socialNetworks,
};
}

0 comments on commit 64c6aa3

Please sign in to comment.