Skip to content

Commit

Permalink
Merge pull request #139 from ticketevolution/dev-4.0.0
Browse files Browse the repository at this point in the history
Update to 4.0.0
  • Loading branch information
jwcobb authored May 24, 2017
2 parents 411cf08 + 7f9b1f7 commit 27eecc7
Show file tree
Hide file tree
Showing 17 changed files with 436 additions and 680 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 4.0.0 (May 24, 2017)
- Fix issue with parameters for `listCategories`.

## 4.0.0RC1 (March 20, 2017)
- Upgrade to [Guzzle 6.2](https://github.com/guzzle/guzzle).
- Create new `TEvoAuthMiddleware` to handle API authentication since the old Subscriber method no longer works.

## 3.0.8 (October 19, 2016)
- Correct the allowed `type`s for `listTicketGroups()`.

Expand Down
178 changes: 25 additions & 153 deletions Documentation.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PHP Client Library v3 for the [Ticket Evolution API](http://developer.ticketevolution.com/)
# PHP Client Library v4 for the [Ticket Evolution API](http://developer.ticketevolution.com/)

## Basic Usage
Here is the most basic usage.
Expand All @@ -14,7 +14,7 @@ $ php composer require ticketevolution/ticketevolution-php
use TicketEvolution\Client as TEvoClient;

// Require Composer’s autoloader
require 'vendor/autoload.php';
require_once '../vendor/autoload.php';

// Create an API Client
$apiClient = new TEvoClient([
Expand All @@ -39,53 +39,46 @@ var_dump($results);
```

## Advanced Usage
Here is a much more “real world” setup that also includes a logger ([Monolog](https://github.com/Seldaek/monolog) in this example), a [retry subscriber](https://github.com/guzzle/retry-subscriber/) and the included `RequestTimer` subscriber.
Here is a much more “real world” setup that also includes a logger ([Monolog](https://github.com/Seldaek/monolog) in this example) as a middleware.

In your Terminal:
```bash
$ php composer require ticketevolution/ticketevolution-php monolog/monolog guzzlehttp/log-subscriber guzzlehttp/retry-subscriber
$ php composer require ticketevolution/ticketevolution-php rtheunissen/guzzle-log-middleware monolog/monolog
```

```php
<?php

use GuzzleHttp\Subscriber\Log\Formatter;
use GuzzleHttp\Subscriber\Log\LogSubscriber;
use GuzzleHttp\Subscriber\Retry\RetrySubscriber;
use Concat\Http\Middleware\Logger;
use GuzzleHttp\MessageFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Monolog\Logger as MonoLogger;
use Psr\Log\LogLevel;
use TicketEvolution\Client as TEvoClient;
use TicketEvolution\Subscriber\RequestTimer;

// Require Composer’s autoloader
require 'vendor/autoload.php';
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 Logger('TEvoAPIClientLogger');
$log->pushHandler(new StreamHandler('/Users/jcobb/Sites/www.myaweometicketsite.dev/myaweometicketsite.com/app/storage/logs/guzzle.log', Logger::DEBUG));
$logSubscriber = new LogSubscriber($log, Formatter::DEBUG);
$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));

/**
* Setup Retry Subscriber
* This creates a retry subscriber that automatically retries requests that errored on connection (such as a timeout)
*/
$retrySubscriber = new RetrySubscriber([
'filter' => RetrySubscriber::createConnectFilter()
]);
// Add a formatter
$formatter = new MessageFormatter(MessageFormatter::DEBUG);

/**
* Setup Request Timer Subscriber
*
* This example includes a RequestTimer subscriber which allows you to see how
* long it took to send a request and receive the results.
*
* You probably do not want to use this in Production
*/
$requestTimer = new RequestTimer();
// 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([
Expand All @@ -95,15 +88,6 @@ $apiClient = new TEvoClient([
'apiSecret' => 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy',
]);

// Attach the log subscriber
$apiClient->getEmitter()->attach($logSubscriber);

// Attach the retry subscriber
$apiClient->getEmitter()->attach($retrySubscriber);

// Attach the RequestTimer subscriber
$apiClient->getEmitter()->attach($requestTimer);

// Get a list of the 25 most popular events sorted by descending popularity
try {
$results = $apiClient->listEvents([
Expand All @@ -121,117 +105,6 @@ echo 'Request took ' . $requestTimer->getElapsedTime() . ' seconds';
var_dump($results);
```

## Even More Advanced Usage
If you have a need to use some of Guzzle’s more advanced features such as [Pools for batching of requests](http://guzzle.readthedocs.org/en/latest/clients.html?highlight=batch#batching-requests) you can do that. You will need to specify explicit URLs as [Pools](http://guzzle.readthedocs.org/en/latest/clients.html?highlight=batch#sending-requests-with-a-pool) cannot be used with the provided Service Definition which provides the handy magic methods such as `listEvents()`.

In your Terminal:
```bash
$ php composer require ticketevolution/ticketevolution-php monolog/monolog guzzlehttp/log-subscriber guzzlehttp/retry-subscriber
```

```php
<?php

use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Pool;
use GuzzleHttp\Subscriber\Log\Formatter;
use GuzzleHttp\Subscriber\Log\LogSubscriber;
use GuzzleHttp\Subscriber\Retry\RetrySubscriber;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use TicketEvolution\Subscriber\RequestTimer;
use TicketEvolution\Subscriber\TEvoAuth;

// Require Composer’s autoloader
require '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 Logger('TEvoAPIClientLogger');
//$log->pushHandler(new StreamHandler('/Users/jcobb/Sites/www.myaweometicketsite.dev/myaweometicketsite.com/app/storage/logs/guzzle.log', Logger::DEBUG));
$log->pushHandler(new StreamHandler('/Users/jcobb/Sites/miscellaneous/library-documentation-tests/data/guzzle.log', Logger::DEBUG));
$logSubscriber = new LogSubscriber($log, Formatter::DEBUG);

/**
* Setup Retry Subscriber
* This creates a retry subscriber that automatically retries requests that errored on connection (such as a timeout)
*/
$retrySubscriber = new RetrySubscriber([
'filter' => RetrySubscriber::createConnectFilter()
]);

/**
* Setup Request Timer Subscriber
* This project includes a RequestTimer subscriber which allows you to see how long it took to send a request and receive the results.
* You probably want to turn this off in Production
*/
$requestTimer = new RequestTimer();

// Create an API client that can handle Pools
$poolClient = new GuzzleClient([
'base_url' => [
'https://api.sandbox.ticketevolution.com',
['apiVersion' => 'v9'],
],
'defaults' => [
'auth' => 'tevoauth',
]
]);


/**
* Attach various subscribers
*/
// Attach the TEvoAuth subscriber to handle [request signing](https://ticketevolution.atlassian.net/wiki/display/API/Signing)
$poolClient->getEmitter()->attach(new TEvoAuth(
'xxxxxxxxxxxxxxxxxxxxxxxx',
'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy')
);

// Attach the log subscriber
$poolClient->getEmitter()->attach($logSubscriber);

// Attach the retry subscriber
$poolClient->getEmitter()->attach($retrySubscriber);

// Attach the RequestTimer subscriber
$poolClient->getEmitter()->attach($requestTimer);


/**
* Create the requests to be pooled.
* Since you must specify the actual URLs be sure to [follow the documentation and sort your GET parameters](https://ticketevolution.atlassian.net/wiki/display/API/Signing#Signing-GETrequests).
*/
$requests = [
// Get a list of the 5 most popular SPORTS events anywhere sorted by descending popularity
$poolClient->createRequest('GET', '/v9/events?category_id=1&category_tree=true&order_by=events.popularity_score+DESC&page=1&per_page=5'),

// Get a list of the 5 most popular CONCERTS events anywhere sorted by descending popularity
$poolClient->createRequest('GET', 'v9/events?category_id=54&category_tree=true&order_by=events.popularity_score+DESC&page=1&per_page=5'),

// Get a list of the 5 most popular THEATRE events anywhere sorted by descending popularity
$poolClient->createRequest('GET', 'v9/events?category_id=68&category_tree=true&order_by=events.popularity_score+DESC&page=1&per_page=5'),
];

// $results is a GuzzleHttp\BatchResults object.
try {
$results = Pool::batch($poolClient, $requests);
} catch (\Exception $e) {
// Handle your Exceptions
}

// Use the RequestTimer to see how long the operation took.
echo 'Requests took ' . $requestTimer->getElapsedTime() . ' seconds';

// Can be accessed by index.
echo '<h2>First Response</h2>' . $results[0]->getBody();
echo '<h2>Second Response</h2>' . $results[1]->getBody();
echo '<h2>Third Response</h2>' . $results[2]->getBody();

```

## Installation for Laravel 5 ##

Expand All @@ -249,16 +122,16 @@ After updating composer add the `TEvoServiceProvider` to the `providers` array i
TicketEvolution\Laravel\TEvoServiceProvider::class,
```

If you want to use the `TEvo` facade add this to the `aliases` array in `config/app.php`:
If you want to use the `tevo` facade add this to the `aliases` array in `config/app.php`:

``` php
'TEvo' => TicketEvolution\Laravel\TEvoFacade::class,
'tevo' => TicketEvolution\Laravel\TEvoFacade::class,
```

To copy the default configuration file to `config/ticketevolution.php` run

``` bash
$ php artisan vendor:publish --provider="TicketEvolution\Laravel\TEvoServiceProvider"
$ 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](http://laravel.com/docs/5.0/configuration#environment-configuration) and that you do not publish that to your repo. In your `.env` you should include
Expand All @@ -268,6 +141,5 @@ TICKETEVOLUTION_API_BASEURL=https://api.sandbox.ticketevolution.com/v9
TICKETEVOLUTION_API_VERSION=v9
TICKETEVOLUTION_API_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
TICKETEVOLUTION_API_SECRET=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy

```

2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The BSD 3-Clause License

Copyright (c) 2015, Ticket Evolution, Inc.
Copyright (c) 2017, Ticket Evolution, Inc.

All rights reserved.

Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PHP Client Library v3 for the [Ticket Evolution API](http://developer.ticketevolution.com/)
# PHP Client Library v4 for the [Ticket Evolution API](http://developer.ticketevolution.com/)
The Ticket Evolution PHP Client is an open source framework created to simplify working with the [Ticket Evolution API web service](http://api.ticketevolution.com/). We created it to enable you to quickly implement the Ticket Evolution API web service on your own site whether you are creating a new site or switching from a different provider. We released it as open source so that you could make changes and improvements as you see fit. When you do we hope that you will give these changes back to the community by contributing them back to the project.


Expand All @@ -13,14 +13,17 @@ $ composer require ticketevolution/ticketevolution-php
## Usage

``` php
$apiClient = TicketEvolution::settings([
use TicketEvolution\Client as TEvoClient;

$apiClient = new TEvoClient([
'baseUrl' => 'https://api.ticketevolution.com',
'apiVersion' => 'v9',
'apiToken' => 'xxxxxxxxxxxxxxxxxxxxxxxx',
'apiSecret' => 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy',
]);

$events = $apiClient->listEvents();
var_dump($events);
```

## Contributing
Expand All @@ -36,7 +39,3 @@ Please see [CONTRIBUTING](https://github.com/ticketevolution/ticketevolution-php

The BSD 3-Clause License (New BSD). Please see [License File](LICENSE.md) for more information.


## Acknowledgments
Some inspiration was taken from the [ShopifyExtras/PHP-Shopify-API-Wrapper](https://github.com/ShopifyExtras/PHP-Shopify-API-Wrapper)

14 changes: 11 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"name": "ticketevolution/ticketevolution-php",
"description": "A PHP 5.4+ library for the Ticket Evolution API.",
"description": "A PHP 7.1+ library for the Ticket Evolution API.",
"type": "library",
"keywords": [
"library",
"Ticket Evolution",
"ticket",
"guzzle",
"guzzlehttp",
"guzzle-services",
"laravel"
],
"homepage": "https://github.com/ticketevolution/ticketevolution-php",
Expand All @@ -18,8 +21,13 @@
}
],
"require": {
"php": ">=5.4",
"guzzlehttp/guzzle-services": "~0.5"
"php": ">=7.1",
"guzzlehttp/guzzle-services": ">=1.1",
"gimler/guzzle-description-loader": "^0.0.4"
},
"suggest": {
"rtheunissen/guzzle-log-middleware": "Guzzle 6 middleware used to log requests and responses",
"monolog/monolog": "Sends your logs to files, sockets, inboxes, databases and various web services"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit 27eecc7

Please sign in to comment.