-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
168 additions
and
1 deletion.
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 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,23 @@ | ||
# logs.tf | ||
|
||
The types and SDK that can interact with the [rgl.gg](https://api.rgl.gg/docs) | ||
|
||
## Install | ||
|
||
Checkout the [jsr page](https://jsr.io/@tf2software/rgl) for more details. | ||
|
||
### Examples | ||
|
||
A simple example that can request the log json of a particular game: | ||
|
||
```ts | ||
const logJson = await getById("3750052"); | ||
|
||
console.log(logJson); | ||
``` | ||
|
||
For more examples, see the [documentation on jsr](https://jsr.io/@tf2software/rgl/doc) | ||
|
||
## License | ||
|
||
Distributed under the MIT License. See [LICENSE](LICENSE) for more information. |
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 @@ | ||
export * from "./rgl.ts"; |
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,60 @@ | ||
import type { BanPagedResponse, PagedBanOptions } from "../types/bans.ts"; | ||
import type { | ||
TeamByIdResponse, | ||
TeamSearchParameters, | ||
TeamSearchResponse, | ||
} from "../types/teams.ts"; | ||
|
||
const rglApiUrl = "https://api.rgl.gg/v0/"; | ||
|
||
export async function getBansPaged(options: PagedBanOptions) { | ||
const { skip = 0, take = 10 } = options; | ||
|
||
if (take > 100) { | ||
throw new Error("Skip must be less than 100"); | ||
} | ||
|
||
const params = new URLSearchParams([ | ||
["skip", skip.toString()], | ||
["take", take.toString()], | ||
]); | ||
|
||
const response = await fetch(`${rglApiUrl}/bans/paged?${params.toString()}`); | ||
|
||
return (await response.json()) as BanPagedResponse; | ||
} | ||
|
||
export async function getSeasonById(seasonId: string) { | ||
if (!seasonId) { | ||
throw new Error("Skip must be less than 100"); | ||
} | ||
|
||
const response = await fetch(`${rglApiUrl}/seasons/${seasonId}`); | ||
|
||
return (await response.json()) as BanPagedResponse; | ||
} | ||
|
||
export async function getTeamById(teamId: string) { | ||
if (!teamId) { | ||
throw new Error("Skip must be less than 100"); | ||
} | ||
|
||
const response = await fetch(`${rglApiUrl}/teams/${teamId}`); | ||
|
||
return (await response.json()) as TeamByIdResponse; | ||
} | ||
|
||
export async function searchTeams(parameters: TeamSearchParameters) { | ||
const { skip = 0, take = 10 } = parameters; | ||
|
||
const params = new URLSearchParams([ | ||
["skip", skip.toString()], | ||
["take", take.toString()], | ||
]); | ||
|
||
const response = await fetch(`${rglApiUrl}/search/teams${params}`, { | ||
body: JSON.stringify(parameters), | ||
}); | ||
|
||
return (await response.json()) as TeamSearchResponse; | ||
} |
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,10 @@ | ||
{ | ||
"name": "@tf2software/rgl", | ||
"version": "0.0.1-alpha1", | ||
"exports": { | ||
".": "./mod.ts", | ||
"./api": "./mod.ts", | ||
"./types": "./types/mod.ts" | ||
} | ||
} | ||
|
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,10 @@ | ||
/** | ||
* The [rgl.gg](https://api.rgl.gg/docs) SDK | ||
* | ||
* This API provides both the types and methods to interact with the API | ||
* | ||
* @module | ||
*/ | ||
|
||
export * from "../api/mod.ts"; | ||
export * from "../types/mod.ts"; |
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,12 @@ | ||
export type PagedBanOptions = { | ||
take: number; | ||
skip: number; | ||
}; | ||
|
||
export type BanPagedResponse = { | ||
steamId: string; | ||
alias: string; | ||
expiresAt: Date; | ||
createdAt: Date; | ||
reason: string; | ||
}; |
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 @@ | ||
export * from "./bans.ts"; |
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,4 @@ | ||
export type PagedRequest = { | ||
take: number; | ||
skip: number; | ||
}; |
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,5 @@ | ||
export type SearchResponse<T> = { | ||
results: T[]; | ||
count: number; | ||
totalHitCount: number; | ||
}; |
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,9 @@ | ||
export type SeasonByIdResponse = { | ||
name: string; | ||
divisionSorting: Record<string, number>; | ||
formatName: string; | ||
regionName: string; | ||
maps: string[]; | ||
participatingTeams: number[]; | ||
matchesPlayedDuringSeason: number[]; | ||
}; |
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,32 @@ | ||
import type { PagedRequest } from "./pagedRequest.ts"; | ||
import type { SearchResponse } from "./searchResponse.ts"; | ||
|
||
export type TeamByIdResponse = { | ||
teamId: number; | ||
linkedTeams: number[]; | ||
seasonId: number; | ||
divisionId: number; | ||
divisionName: string; | ||
teamLeader: string; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
tag: string; | ||
name: string; | ||
finalRank: number; | ||
teamStatus: string; | ||
teamReady: boolean; | ||
players: RosteredPlayer; | ||
}; | ||
|
||
export type TeamSearchResponse = SearchResponse<string>; | ||
export type TeamSearchParameters = PagedRequest & { | ||
nameContains?: string | null; | ||
}; | ||
|
||
export type RosteredPlayer = { | ||
name: string; | ||
steamId: string; | ||
isLeader: boolean; | ||
joinedAt: Date; | ||
leftAt: Date; | ||
}; |