Nextbike API Client
, (*1)
Client to get some data from Nextbike API., (*2)
This library require PHP version >= 7., (*3)
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., (*4)
<?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:, (*5)
$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)., (*6)
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., (*7)
Collection
In collections you might use following methods:, (*8)
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., (*9)
License
MIT, (*10)