brieucthomas/ergast-client

PHP client for Ergast Developer API

v1.0.1 2020-09-09 14:09 UTC

This package is not auto-updated.

Last update: 2024-12-26 10:09:05 UTC


README

Build Status Software License Latest Version Total Downloads

PHP client for Ergast Developer API.

Requirements

PHP needs to be a minimum version of PHP 7.

Installation

This library can be easily installed via Composer:

composer require brieucthomas/ergast-client

or just add it to your composer.json file directly and run composer install.

Usage

use BrieucThomas\ErgastClient\ErgastClientBuilder;
use BrieucThomas\ErgastClient\Request\RequestBuilder;

$ergastClient = ErgastClientBuilder::createErgastClient();

$requestBuilder = new RequestBuilder();
$requestBuilder
    ->findCircuits()
    ->byId('monza')
;

$response = $ergastClient->execute($requestBuilder->build());
$circuit = $response->getCircuits()->first();

echo $circuit->getId();                       // "monza"
echo $circuit->getName();                     // "Autodromo Nazionale di Monza"
echo $circuit->getUrl();                      // "http://en.wikipedia.org/wiki/Autodromo_Nazionale_Monza"
echo $circuit->getLocation()->getLocality();  // "Monza"
echo $circuit->getLocation()->getCountry();   // "Italy"
echo $circuit->getLocation()->getLatitude();  // 45.6156
echo $circuit->getLocation()->getLongitude(); // 9.28111

Limit and offset

$uriBuilder
    ->setFirstResult(2)
    ->setMaxResults(5)
;