-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace useGitHub hook with React Query implementation
- Loading branch information
1 parent
e460413
commit 40eed27
Showing
4 changed files
with
43 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { IGitHubUser } from "../interfaces/github/IGitHubUser"; | ||
import { IGitHubRepository } from "../interfaces/github/IGitHubRepository"; | ||
|
||
export class GitHubService { | ||
private static BASE_URL = "https://api.github.com"; | ||
|
||
private async makeRequest<T>(path: string): Promise<T> { | ||
const res = await fetch(`${GitHubService.BASE_URL}/${path}`); | ||
|
||
return res.json(); | ||
} | ||
|
||
async getUserById(id: number): Promise<IGitHubUser> { | ||
const [user] = await this.makeRequest<IGitHubUser[]>(`users?since=${id - 1}&per_page=1`); | ||
|
||
return user; | ||
} | ||
|
||
async getUsersRepositories(username: string): Promise<IGitHubRepository[]> { | ||
return this.makeRequest(`users/${username.toLowerCase()}/repos`); | ||
} | ||
} | ||
|
||
export const githubService = new GitHubService(); |