festivalslab/api-client-php

PHP client for the Edinburgh Festivals Listings API

v2.3.0 2024-11-28 21:38 UTC

This package is auto-updated.

Last update: 2024-11-28 21:38:43 UTC


README

The Edinburgh Festivals Listings API client for PHP makes it easy for developers to access the Edinburgh Festivals Listings API in their PHP code.

You can get started quickly by installing the client through composer

Build Status

Quick Examples

Create a client

// Require the Composer autoloader.
require 'vendor/autoload.php';

use FestivalsApi\FestivalsApiClientFactory;

// Instantiate a Festivals API Client.
$client = FestivalsApiClientFactory::createWithCredentials('key', 'secret');

Find some events

use FestivalsApi\FestivalsApiClientException;

try {
    $result = $client->searchEvents(['title' => 'Foo']);
    $events = $result->getEvents();
} catch (FestivalsApiClientException $e){
    echo "There was an error: " . $e->getMessage();
}

Iterate all results

The API delivers results in pages, by default 25 results at a time, configurable up to 100. Using FestivalsApi\FestivalsApiEventSearch will take care for the pagination for you so you can iterate all results for a search query easily.

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();
}

Resources

  • API Docs - Details about parameters & responses
  • API Browser - Interactive tool to explore API options and responses

Installing

The recommended way to install the php client is through Composer.

Install Composer https://getcomposer.org/

Next, run the Composer command to install the latest stable version of the client:

composer require festivalslab/api-client-php

After installing, you need to require Composer's autoloader:

require 'vendor/autoload.php';

You can then later update the client using composer:

composer update