PHP Client Library v4 for the Ticket Evolution API
Here is the most basic usage.
In your Terminal:
$ php composer require ticketevolution/ticketevolution-php
<?php
use TicketEvolution\Client as TEvoClient;
// Require Composer’s autoloader
require_once '../vendor/autoload.php';
// Create an API Client
$apiClient = new TEvoClient([
'baseUrl' => 'https://api.sandbox.ticketevolution.com',
'apiVersion' => 'v9',
'apiToken' => 'xxxxxxxxxxxxxxxxxxxxxxxx',
'apiSecret' => 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy',
]);
// Get a list of the 25 most popular events sorted by descending popularity
try {
$results = $apiClient->listEvents([
'page' => 1,
'per_page' => 25,
'order_by' => 'events.popularity_score DESC',
]);
} catch (\Exception $e) {
// Handle your Exceptions
}
var_dump($results);
Here is a much more “real world” setup that also includes a logger (Monolog in this example) as a middleware.
In your Terminal:
$ php composer require ticketevolution/ticketevolution-php rtheunissen/guzzle-log-middleware monolog/monolog
<?php
use Concat\Http\Middleware\Logger;
use GuzzleHttp\MessageFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger as MonoLogger;
use Psr\Log\LogLevel;
use TicketEvolution\Client as TEvoClient;
// Require Composer’s autoloader
require_once '../vendor/autoload.php';
/**
* Setup Logger
* This creates a file logger with a level of Debug mode for development.
* For Production you probably want to adjust the log level.
*/
$log = new MonoLogger('TEvoAPILogger');
//$log->pushHandler(new StreamHandler('/Users/jcobb/Sites/www.myaweometicketsite.dev/myaweometicketsite.com/app/storage/logs/guzzle.log', LogLevel::DEBUG));
$log->pushHandler(new StreamHandler('../../app/storage/logs/guzzler.log', LogLevel::DEBUG));
// Add a formatter
$formatter = new MessageFormatter(MessageFormatter::DEBUG);
// Create a middleware for logging
$middleware = new Logger($log);
// Apply the formatter
$middleware->setFormatter($formatter);
// Add it to the middleware array so it will get pushed to the client’s stack
$middlewares[] = $middleware;
// Create an API Client
$apiClient = new TEvoClient([
'baseUrl' => 'https://api.sandbox.ticketevolution.com',
'apiVersion' => 'v9',
'apiToken' => 'xxxxxxxxxxxxxxxxxxxxxxxx',
'apiSecret' => 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy',
], $middlewares);
// Get a list of the 25 most popular events sorted by descending popularity
try {
$results = $apiClient->listEvents([
'page' => 1,
'per_page' => 25,
'order_by' => 'events.popularity_score DESC',
]);
} catch (\Exception $e) {
// Handle your Exceptions
}
// Use the RequestTimer to see how long the operation took.
echo 'Request took ' . $requestTimer->getElapsedTime() . ' seconds';
var_dump($results);
Laravel 5 is not required, but if you are using Laravel 5 this package includes both a ServiceProvider and a Facade for easy integration.
Install the package via Composer
$ composer require ticketevolution/ticketevolution-php
Package Auto-Discovery will automatically add the ServiceProvider and TEvo
facade.
After updating composer add the TEvoServiceProvider
to the providers
array in config/app.php
:
TicketEvolution\Laravel\TEvoServiceProvider::class,
If you want to use the TEvo
facade add this to the aliases
array in config/app.php
:
'TEvo' => TicketEvolution\Laravel\TEvoFacade::class,
To copy the default configuration file to config/ticketevolution.php
run
$ php artisan vendor:publish --provider="TicketEvolution\Laravel\TEvoServiceProvider" --tag=config
In Laravel 5 it is recommended that you keep your API credentials in your .env
file and that you do not publish that to your repo. In your .env
you should include
TICKETEVOLUTION_API_BASEURL=https://api.sandbox.ticketevolution.com/v9
TICKETEVOLUTION_API_VERSION=v9
TICKETEVOLUTION_API_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
TICKETEVOLUTION_API_SECRET=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy