Skip to content

Commit 1afe9d4

Browse files
github-actions[bot]CI
andauthored
ci: update api (#16)
Co-authored-by: CI <ci@rman.dev>
1 parent c922571 commit 1afe9d4

9 files changed

+168
-7
lines changed

specs/lichess-api.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
openapi: "3.1.0"
22
info:
3-
version: 2.0.120
3+
version: 2.0.123
44
title: Lichess.org API reference
55
contact:
66
name: "Lichess.org API"
@@ -538,6 +538,9 @@ paths:
538538
/api/fide/player/{playerId}:
539539
$ref: "./tags/fide/api-fide-player-playerId.yaml"
540540

541+
/api/fide/player/{playerId}/ratings:
542+
$ref: "./tags/fide/api-fide-player-playerId-ratings.yaml"
543+
541544
/api/fide/player:
542545
$ref: "./tags/fide/api-fide-player-search.yaml"
543546

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
type: object
2+
description: |
3+
Data points are encoded. Each number contains a year, a month, and an ELO rating.
4+
5+
`2015081568` -> `August 2015: 1568`
6+
7+
Here's an example decoding implementation in JS:
8+
9+
```js
10+
const decodePoint = point => {
11+
const elo = point % 10000;
12+
const dateNum = Math.floor(point / 10000);
13+
const year = Math.floor(dateNum / 100);
14+
const month = dateNum % 100;
15+
return [year, month, elo];
16+
};
17+
```
18+
19+
Consecutive months with same ELO are omitted. For a given ELO, only the first and last month are provided.
20+
21+
properties:
22+
standard:
23+
type: array
24+
items:
25+
type: number
26+
rapid:
27+
type: array
28+
items:
29+
type: number
30+
blitz:
31+
type: array
32+
items:
33+
type: number
34+
35+
required:
36+
- standard
37+
- rapid
38+
- blitz

specs/tags/broadcasts/api-broadcast-broadcastTournamentId-pgn.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ get:
1919
type: string
2020
minLength: 8
2121
maxLength: 8
22+
- in: query
23+
name: clocks
24+
description: |
25+
Include clock comments in the PGN moves, when available.
26+
Example: `2. exd5 { [%clk 1:01:27] } e5 { [%clk 1:01:28] }`
27+
schema:
28+
type: boolean
29+
default: true
30+
- in: query
31+
name: comments
32+
description: |
33+
Include analysis comments in the PGN moves, when available.
34+
Example: `12. Bxf6 { [%eval 0.23] }`
35+
schema:
36+
type: boolean
37+
default: true
2238
responses:
2339
"200":
2440
description: The PGN representation of the broadcast.

specs/tags/broadcasts/api-broadcast-round-broadcastRoundId-pgn.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ get:
1919
type: string
2020
minLength: 8
2121
maxLength: 8
22+
- in: query
23+
name: clocks
24+
description: |
25+
Include clock comments in the PGN moves, when available.
26+
Example: `2. exd5 { [%clk 1:01:27] } e5 { [%clk 1:01:28] }`
27+
schema:
28+
type: boolean
29+
default: true
30+
- in: query
31+
name: comments
32+
description: |
33+
Include analysis comments in the PGN moves, when available.
34+
Example: `12. Bxf6 { [%eval 0.23] }`
35+
schema:
36+
type: boolean
37+
default: true
2238
responses:
2339
"200":
2440
description: The PGN representation of the round.

specs/tags/broadcasts/api-stream-broadcast-round-broadcastRoundId-pgn.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ get:
1919
type: string
2020
minLength: 8
2121
maxLength: 8
22+
- in: query
23+
name: clocks
24+
description: |
25+
Include clock comments in the PGN moves, when available.
26+
Example: `2. exd5 { [%clk 1:01:27] } e5 { [%clk 1:01:28] }`
27+
schema:
28+
type: boolean
29+
default: true
30+
- in: query
31+
name: comments
32+
description: |
33+
Include analysis comments in the PGN moves, when available.
34+
Example: `12. Bxf6 { [%eval 0.23] }`
35+
schema:
36+
type: boolean
37+
default: true
2238
responses:
2339
"200":
2440
description: The PGN representation of the round games, then the PGNs of games as they are updated.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
get:
2+
operationId: fidePlayerRatings
3+
summary: Get ratings history of a FIDE player
4+
description: |
5+
Historical standard, rapid and blitz ratings of a FIDE player
6+
tags:
7+
- FIDE
8+
security: []
9+
parameters:
10+
- in: path
11+
name: playerId
12+
description: The FIDE player ID.
13+
required: true
14+
schema:
15+
type: integer
16+
responses:
17+
"200":
18+
description: The rating histories
19+
content:
20+
application/json:
21+
schema:
22+
$ref: "../../schemas/FIDEPlayerRatings.yaml"
23+
examples:
24+
example player:
25+
$ref: "../../examples/fide-getFidePlayerRatings.json.yaml"

src/client/index.ts

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,26 +2177,50 @@ export class Lichess {
21772177
/**
21782178
* Stream an ongoing broadcast round as PGN
21792179
*/
2180-
async broadcastStreamRoundPgn(params: { broadcastRoundId: string }) {
2180+
async broadcastStreamRoundPgn(
2181+
params: { broadcastRoundId: string } & {
2182+
clocks?: boolean;
2183+
comments?: boolean;
2184+
},
2185+
) {
21812186
const path =
21822187
`/api/stream/broadcast/round/${params.broadcastRoundId}.pgn` as const;
2183-
return await this.requestor.get({ path }, { 200: { kind: "chess-pgn" } });
2188+
return await this.requestor.get(
2189+
{ path, query: { clocks: params.clocks, comments: params.comments } },
2190+
{ 200: { kind: "chess-pgn" } },
2191+
);
21842192
}
21852193

21862194
/**
21872195
* Export one round as PGN
21882196
*/
2189-
async broadcastRoundPgn(params: { broadcastRoundId: string }) {
2197+
async broadcastRoundPgn(
2198+
params: { broadcastRoundId: string } & {
2199+
clocks?: boolean;
2200+
comments?: boolean;
2201+
},
2202+
) {
21902203
const path = `/api/broadcast/round/${params.broadcastRoundId}.pgn` as const;
2191-
return await this.requestor.get({ path }, { 200: { kind: "chess-pgn" } });
2204+
return await this.requestor.get(
2205+
{ path, query: { clocks: params.clocks, comments: params.comments } },
2206+
{ 200: { kind: "chess-pgn" } },
2207+
);
21922208
}
21932209

21942210
/**
21952211
* Export all rounds as PGN
21962212
*/
2197-
async broadcastAllRoundsPgn(params: { broadcastTournamentId: string }) {
2213+
async broadcastAllRoundsPgn(
2214+
params: { broadcastTournamentId: string } & {
2215+
clocks?: boolean;
2216+
comments?: boolean;
2217+
},
2218+
) {
21982219
const path = `/api/broadcast/${params.broadcastTournamentId}.pgn` as const;
2199-
return await this.requestor.get({ path }, { 200: { kind: "chess-pgn" } });
2220+
return await this.requestor.get(
2221+
{ path, query: { clocks: params.clocks, comments: params.comments } },
2222+
{ 200: { kind: "chess-pgn" } },
2223+
);
22002224
}
22012225

22022226
/**
@@ -2221,6 +2245,17 @@ export class Lichess {
22212245
);
22222246
}
22232247

2248+
/**
2249+
* Get ratings history of a FIDE player
2250+
*/
2251+
async fidePlayerRatings(params: { playerId: number }) {
2252+
const path = `/api/fide/player/${params.playerId}/ratings` as const;
2253+
return await this.requestor.get(
2254+
{ path },
2255+
{ 200: { kind: "json", schema: schemas.FIDEPlayerRatings } },
2256+
);
2257+
}
2258+
22242259
/**
22252260
* Search FIDE players
22262261
*/

src/schemas/FIDEPlayerRatings.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as z from "zod/mini";
2+
3+
const FIDEPlayerRatings = z.object({
4+
standard: z.array(z.number()),
5+
rapid: z.array(z.number()),
6+
blitz: z.array(z.number()),
7+
});
8+
9+
type FIDEPlayerRatings = z.infer<typeof FIDEPlayerRatings>;
10+
11+
export { FIDEPlayerRatings };

src/schemas/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export { ExternalEngineWork } from "./ExternalEngineWork";
6262
export { ExternalEngineWorkCommon } from "./ExternalEngineWorkCommon";
6363
export { FIDEPlayer } from "./FIDEPlayer";
6464
export { FIDEPlayerPhoto } from "./FIDEPlayerPhoto";
65+
export { FIDEPlayerRatings } from "./FIDEPlayerRatings";
6566
export { FideTimeControl } from "./FideTimeControl";
6667
export { Flair } from "./Flair";
6768
export { FromPositionFEN } from "./FromPositionFEN";

0 commit comments

Comments
 (0)