-
Notifications
You must be signed in to change notification settings - Fork 10
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
1 parent
1fa3aec
commit 41c3114
Showing
8 changed files
with
426 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,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; | ||
} | ||
} |
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,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 | ||
} |
Oops, something went wrong.