awaluk / nextbike-api-client
Client to get some data from Nextbike API
Requires
- php: >= 7
- guzzlehttp/guzzle: ^6.3
Requires (Dev)
- phpunit/phpunit: ^6
This package is not auto-updated.
Last update: 2025-04-30 06:17:08 UTC
README
Client to get some data from Nextbike API.
This library require PHP version >= 7.
Installation
composer require awaluk/nextbike-api-client
Usage
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');
Methods
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 |
Structure
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.
Collection
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 |
Examples
- 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() . ', '; }
Contributing rules
Do you want to help develop this library? See CONTRIBUTING file.