festivalslab / api-client-php
Edinburgh Festivals Listings API的PHP客户端
v2.1.0
2022-10-25 09:13 UTC
Requires
- php: ~8.0.0 || ~8.1.0 || ~8.2.0
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- johnkary/phpunit-speedtrap: ^3.3
- phpunit/phpunit: ^9.5.5
README
PHP客户端使得开发者可以轻松地在代码中访问Edinburgh Festivals Listings API。
您可以通过通过composer安装客户端快速开始。
快速示例
创建客户端
// Require the Composer autoloader. require 'vendor/autoload.php'; use FestivalsApi\FestivalsApiClientFactory; // Instantiate a Festivals API Client. $client = FestivalsApiClientFactory::createWithCredentials('key', 'secret');
查找一些活动
use FestivalsApi\FestivalsApiClientException; try { $result = $client->searchEvents(['title' => 'Foo']); $events = $result->getEvents(); } catch (FestivalsApiClientException $e){ echo "There was an error: " . $e->getMessage(); }
遍历所有结果
API默认以每页25个结果的方式提供结果,最多可配置为100个。使用FestivalsApi\FestivalsApiEventSearch
将为您处理分页,从而使您能够轻松地遍历搜索查询的所有结果。
use FestivalsApi\EventSearchIterator; use FestivalsApi\FestivalsApiClientException; $search = new EventSearchIterator($client); $search->setQuery(['festival' => 'jazz']); try { foreach ($search as $event){ echo $event['title']; } } catch (FestivalsApiClientException $e){ echo "There was an error: " . $e->getMessage(); }
资源
安装
推荐通过Composer安装PHP客户端。
安装Composer https://getcomposer.org.cn/
接下来,运行Composer命令安装客户端的最新稳定版本
composer require festivalslab/api-client-php
安装后,您需要引入Composer的自动加载器
require 'vendor/autoload.php';
然后您可以使用Composer更新客户端
composer update