Skip to content

Commit

Permalink
Added new card and f1 client
Browse files Browse the repository at this point in the history
  • Loading branch information
marcokreeft87 committed Dec 31, 2022
1 parent 1fa3aec commit 41c3114
Show file tree
Hide file tree
Showing 8 changed files with 426 additions and 7 deletions.
114 changes: 108 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"ts-jest": "^29.0.3",
"ts-loader": "^9.4.1",
"ttypescript": "^1.5.13",
"typed-rest-client": "^1.8.9",
"yarn": "^1.22.19"
}
}
31 changes: 31 additions & 0 deletions src/api/ergast-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//https://ergast.com/mrd/
import * as rm from 'typed-rest-client/RestClient';
import { Race, RaceTable, Root, Season } from './models';

export default class ErgastClient {

client: rm.RestClient;
baseUrl = 'https://ergast.com/api/f1';

constructor() {
this.client = new rm.RestClient('formulaone-card', this.baseUrl);
}

async GetResults(season: number, round: number) : Promise<RaceTable> {
const result = await this.client.get<Root>(`/${season}/${round}/results.json`)

return result.result.MRData.RaceTable;
}

async GetSeasons() : Promise<Season[]> {
const result = await this.client.get<Root>('seasons.json');

return result.result.MRData.SeasonTable.Seasons;
}

async GetSeasonRaces(season: number) : Promise<Race[]> {
const result = await this.client.get<Root>(`${season}.json`);

return result.result.MRData.RaceTable.Races;
}
}
136 changes: 136 additions & 0 deletions src/api/models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
export interface Root {
MRData: Mrdata
}

export interface Mrdata {
xmlns: string
series: string
url: string
limit: string
offset: string
total: string
RaceTable: RaceTable
SeasonTable: SeasonTable;
}

export interface RaceTable {
season: string
round: string
Races: Race[]
}

export interface Race {
season: string
round: string
url: string
raceName: string
Circuit: Circuit
date: string
time: string
Results: Result[]
}

export interface Circuit {
circuitId: string
url: string
circuitName: string
Location: Location
}

export interface Location {
lat: string
long: string
locality: string
country: string
}

export interface Result {
number: string
position: string
positionText: string
points: string
Driver: Driver
Constructor: Constructor
grid: string
laps: string
status: string
Time?: Time
FastestLap: FastestLap
FirstPractice: FirstPractice
SecondPractice: SecondPractice
ThirdPractice?: ThirdPractice
Qualifying: Qualifying
Sprint?: Sprint
}

export interface Driver {
driverId: string
permanentNumber: string
code: string
url: string
givenName: string
familyName: string
dateOfBirth: string
nationality: string
}

export interface Constructor {
constructorId: string
url: string
name: string
nationality: string
}

export interface Time {
millis: string
time: string
}

export interface FastestLap {
rank: string
lap: string
Time: Time2
AverageSpeed: AverageSpeed
}

export interface Time2 {
time: string
}

export interface AverageSpeed {
units: string
speed: string
}
export interface SeasonTable {
Seasons: Season[]
}

export interface Season {
season: string
url: string
}

export interface FirstPractice {
date: string
time: string
}

export interface SecondPractice {
date: string
time: string
}

export interface ThirdPractice {
date: string
time: string
}

export interface Qualifying {
date: string
time: string
}

export interface Sprint {
date: string
time: string
}
Loading

0 comments on commit 41c3114

Please sign in to comment.