Client to get some data from Nextbike API.
This library require PHP version >= 7.
composer require awaluk/nextbike-api-client
To use, please include Composer autoloader. Next, create HTTP client (based on Guzzle) and Nextbike
class instance.
<?php
require_once 'vendor/autoload.php';
use awaluk\NextbikeClient\HttpClient;
use awaluk\NextbikeClient\Nextbike;
$httpClient = new HttpClient();
$nextbike = new Nextbike($httpClient);
If it's necessary, you might pass custom API address in second parameter of Nextbike
class:
$nextbike = new Nextbike($httpClient, 'https://example.com');
Nextbike
class provide methods to get data from API. In results you receive structure (one object) or collection (more objects).
Method | Description | Result |
---|---|---|
getSystems() |
get all Nextbike systems | SystemCollection |
getCities() |
get all cities from all systems | CityCollection |
getCity(int $cityId) |
get one city by passed id | City |
Each structure provides own methods to get data. For details, please see to necessary class. In addition, each structure have method get(string $name)
to get data by given name.
In collections you might use following methods:
Method | Description | Result |
---|---|---|
isEmpty() |
check is structure have any data | bool |
count() |
get number of objects in collection | int |
getAll() |
get all data | array |
getFirst() |
get first object | structure class |
- Get all systems names:
<?php
$httpClient = new HttpClient();
$nextbike = new Nextbike($httpClient);
$systems = $nextbike->getSystems()->getAll();
foreach ($systems as $system) {
echo $system->getName() . ', ';
}
- Get stations with number of available bikes in given city (in this example: 496 - Koszalin, Poland):
<?php
$httpClient = new HttpClient();
$nextbike = new Nextbike($httpClient);
$city = $nextbike->getCity(496);
foreach ($city->getStationCollection()->getAll() as $station) {
echo 'Station: ' . $station->getName() . ' - available bikes: ' . $station->getBikesAmount() . ', ';
}
Do you want to help develop this library? See CONTRIBUTING file.