Skip to content

Commit

Permalink
chore: start rgl
Browse files Browse the repository at this point in the history
  • Loading branch information
c43721 committed Dec 9, 2024
1 parent a694c01 commit c596c9b
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 1 deletion.
2 changes: 1 addition & 1 deletion javascript-sdk/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"tasks": {
"test": "deno test -A --clean"
},
"workspace": ["./logstf", "./etf2l"]
"workspace": ["./logstf", "./etf2l", "./rgl"]
}
23 changes: 23 additions & 0 deletions javascript-sdk/rgl/README.md
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.
1 change: 1 addition & 0 deletions javascript-sdk/rgl/api/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./rgl.ts";
60 changes: 60 additions & 0 deletions javascript-sdk/rgl/api/rgl.ts
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;
}
10 changes: 10 additions & 0 deletions javascript-sdk/rgl/deno.json
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"
}
}

10 changes: 10 additions & 0 deletions javascript-sdk/rgl/mod.ts
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";
12 changes: 12 additions & 0 deletions javascript-sdk/rgl/types/bans.ts
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;
};
1 change: 1 addition & 0 deletions javascript-sdk/rgl/types/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./bans.ts";
4 changes: 4 additions & 0 deletions javascript-sdk/rgl/types/pagedRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type PagedRequest = {
take: number;
skip: number;
};
5 changes: 5 additions & 0 deletions javascript-sdk/rgl/types/searchResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type SearchResponse<T> = {
results: T[];
count: number;
totalHitCount: number;
};
9 changes: 9 additions & 0 deletions javascript-sdk/rgl/types/seasons.ts
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[];
};
32 changes: 32 additions & 0 deletions javascript-sdk/rgl/types/teams.ts
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;
};

0 comments on commit c596c9b

Please sign in to comment.