awaluk / nextbike-api-client
用于从Nextbike API获取数据的客户端
v1.0
2018-05-20 14:17 UTC
Requires
- php: >= 7
- guzzlehttp/guzzle: ^6.3
Requires (Dev)
- phpunit/phpunit: ^6
This package is not auto-updated.
Last update: 2024-09-18 03:32:38 UTC
README
用于从Nextbike API获取数据的客户端。
此库需要 PHP版本 >= 7。
安装
composer require awaluk/nextbike-api-client
使用
要使用,请包含Composer自动加载器。接下来,创建HTTP客户端(基于Guzzle)和Nextbike
类实例。
<?php require_once 'vendor/autoload.php'; use awaluk\NextbikeClient\HttpClient; use awaluk\NextbikeClient\Nextbike; $httpClient = new HttpClient(); $nextbike = new Nextbike($httpClient);
如果需要,可以在Nextbike
类的第二个参数中传递自定义API地址
$nextbike = new Nextbike($httpClient, 'https://example.com');
方法
Nextbike
类提供从API获取数据的方法。在结果中,您将收到 结构(一个对象) 或 集合(更多对象)。
结构
每个结构提供自己的方法来获取数据。有关详细信息,请参阅必要的类。此外,每个结构都有一个get(string $name)
方法,可以按给定的名称获取数据。
集合
在集合中,您可以使用以下方法
示例
- 获取所有系统名称
<?php $httpClient = new HttpClient(); $nextbike = new Nextbike($httpClient); $systems = $nextbike->getSystems()->getAll(); foreach ($systems as $system) { echo $system->getName() . ', '; }
- 获取给定城市(在此示例中: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文件。