Skip to content

awaluk/nextbike-api-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nextbike API Client

Build Status

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

  1. Get all systems names:
<?php

$httpClient = new HttpClient();
$nextbike = new Nextbike($httpClient);
$systems = $nextbike->getSystems()->getAll();

foreach ($systems as $system) {
    echo $system->getName() . ', ';
}
  1. 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.

License

MIT

About

Client to get some data from Nextbike API

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages