Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Create Viagogo API SDK for PHP
  • Loading branch information
maxab committed Apr 30, 2015
0 parents commit 92df715
Show file tree
Hide file tree
Showing 40 changed files with 1,255 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Composer
vendor
composer.lock
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# GogoKit - viagogo API Client Library for PHP

[![Build status](https://ci.appveyor.com/api/projects/status/ri2rbvoinudw27en/branch/master?svg=true)][appveyor]
[![NuGet version](https://badge.fury.io/nu/gogokit.svg)][badgefury]

[appveyor]: https://ci.appveyor.com/project/viagogo/gogokit-net/branch/master
[badgefury]: https://badge.fury.io/nu/gogokit

GogoKit is a lightweight, async viagogo API client library for PHP.

## Usage

```php
// All methods require authentication. To get your viagogo OAuth credentials,
// See TODO: docs url
$clientId = 'CLIENT_ID';
$clientSecret = 'CLIENT_SECRET';

$viagogo = new Viagogo\ViagogoClient($clientId, $clientSecret);
$viagogo->setToken($viagogo->getOAuthClient()->getClientAccessToken());

$event = $client->getEventClient()->getEvent(676615);
// Get a list of results that match your search query
$searchResults = $client->getEventClient()->getEvent(676615)("FC Barcelona tickets");
```

## Getting Started

GogoKit will be available on Composer.
27 changes: 27 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "gogokit",
"description": "Viagogo API SDK for PHP",
"keywords": ["viagogo", "sdk"],
"type": "library",
"homepage": "https://github.com/viagogo/gogokit.php",
"license": "MIT",
"authors": [
{
"name": "Viagogo",
"homepage": "https://github.com/viagogo/gogokit.php"
}
],
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "4.4.*",
"mockery/mockery": "0.9.*",
"guzzlehttp/guzzle": "~5.0"
},
"autoload": {
"psr-4": {
"Viagogo\\": "src/"
}
}
}
96 changes: 96 additions & 0 deletions src/ViagogoClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace Viagogo;

use Viagogo\Clients as Clients;
use Viagogo\Common as Common;
use Viagogo\Hal\HalClient;
/**
*
*/
class ViagogoClient
{
private $oauthClient;
private $tokenStore;
private $halClient;
private $categoryClient;
private $eventClient;
private $venueClient;
private $listingClient;
private $searchClient;
private $currencyClient;
private $countryClient;
private $languageClient;

function __construct($clientId, $clientSecret)
{
$this->oauthClient = new Common\OAuthClient($clientId, $clientSecret);
$this->tokenStore = new Common\OAuthTokenStore();
$this->halClient = new HalClient($this->tokenStore);
$this->categoryClient = new Clients\CategoryClient($this->halClient);
$this->eventClient = new Clients\EventClient($this->halClient);
$this->venueClient = new Clients\VenueClient($this->halClient);
$this->listingClient = new Clients\ListingClient($this->halClient);
$this->searchClient = new Clients\SearchClient($this->halClient);
$this->currencyClient = new Clients\CurrencyClient($this->halClient);
$this->countryClient = new Clients\CountryClient($this->halClient);
$this->languageClient = new Clients\LanguageClient($this->halClient);
}

public function setToken(Common\OAuthToken $token)
{
$this->tokenStore->setToken($token);

return $this;
}

public function getOAuthClient()
{
return $this->oauthClient;
}

public function getHalClient()
{
return $this->halClient;
}

public function getCategoryClient()
{
return $this->categoryClient;
}

public function getEventClient()
{
return $this->eventClient;
}

public function getVenueClient()
{
return $this->venueClient;
}

public function getListingClient()
{
return $this->listingClient;
}

public function getSearchClient()
{
return $this->searchClient;
}

public function getCountryClient()
{
return $this->countryClient;
}

public function getCurrencyClient()
{
return $this->currencyClient;
}

public function getLanguageClient()
{
return $this->languageClient;
}
}
15 changes: 15 additions & 0 deletions src/clients/CategoryClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Viagogo\Clients;

use Viagogo\Hal\HalClient;
use Viagogo\Hal\PagedResource;
use Viagogo\Resources\Category;
use Viagogo\Common\ViagogoRequestParams;

/**
*
*/
class CategoryClient extends Client
{
}
18 changes: 18 additions & 0 deletions src/clients/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Viagogo\Clients;

use Viagogo\Hal\HalClient;

/**
*
*/
abstract class Client
{
protected $client;

function __construct(HalClient $halClient)
{
$this->client = $halClient;
}
}
38 changes: 38 additions & 0 deletions src/clients/CountryClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Viagogo\Clients;

use Viagogo\Hal\HalClient;
use Viagogo\Hal\PagedResource;
use Viagogo\Resources\Country;
use Viagogo\Common\ViagogoRequestParams;

/**
*
*/
class CountryClient extends Client
{
public function getCountry($countryCode, ViagogoRequestParams $params = null)
{
$root = $this->client->getRoot();
$link = $root->getSelfLink()->getHref().'/countries/'.$countryCode;

return $this->client->getResource($link, $params, 'Viagogo\Resources\Country');
}

public function getCountries(ViagogoRequestParams $params = null)
{
$root = $this->client->getRoot();
$link = $root->getSelfLink()->getHref().'/countries';

return new PagedResource($this->client->getResource($link, $params), 'Viagogo\Resources\Country');
}

public function getAllCountries(ViagogoRequestParams $params = null)
{
$root = $this->client->getRoot();
$link = $root->getSelfLink()->getHref().'/countries';

return $this->client->getAllResources($link, $params, 'Viagogo\Resources\Country');
}
}
38 changes: 38 additions & 0 deletions src/clients/CurrencyClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Viagogo\Clients;

use Viagogo\Hal\HalClient;
use Viagogo\Hal\PagedResource;
use Viagogo\Resources\Currency;
use Viagogo\Common\ViagogoRequestParams;

/**
*
*/
class CurrencyClient extends Client
{
public function getCurrency($currencyCode, ViagogoRequestParams $params = null)
{
$root = $this->client->getRoot();
$link = $root->getCurrenciesLink()->getHref().'/'.$countryCode;

return $this->client->getResource($link, $params, 'Viagogo\Resources\Country');
}

public function getCurrencies(ViagogoRequestParams $params = null)
{
$root = $this->client->getRoot();
$link = $root->getCurrenciesLink()->getHref();

return new PagedResource($this->client->getResource($link, $params), 'Viagogo\Resources\Country');
}

public function getAllCurrencies(ViagogoRequestParams $params = null)
{
$root = $this->client->getRoot();
$link = $root->getCurrenciesLink()->getHref();

return $this->client->getAllResources($link, $params, 'Viagogo\Resources\Country');
}
}
38 changes: 38 additions & 0 deletions src/clients/EventClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Viagogo\Clients;

use Viagogo\Hal\HalClient;
use Viagogo\Hal\PagedResource;
use Viagogo\Resources\Event;
use Viagogo\Common\ViagogoRequestParams;

/**
*
*/
class EventClient extends Client
{
public function getEvent($eventId, ViagogoRequestParams $params = null)
{
$root = $this->client->getRoot();
$link = $root->getSelfLink()->getHref().'/events/'.$eventId;

return $this->client->getResource($link, $params, 'Viagogo\Resources\Event');
}

public function getEventsByCategory($categoryId, ViagogoRequestParams $params = null)
{
$root = $this->client->getRoot();
$link = $root->getSelfLink()->getHref().'/categories/'.$categoryId.'/events';

return new PagedResource($this->client->getResource($link, $params), 'Viagogo\Resources\Event');
}

public function getAllEventsByCategory($categoryId, ViagogoRequestParams $params = null)
{
$root = $this->client->getRoot();
$link = $root->getSelfLink()->getHref().'/categories/'.$categoryId.'/events';

return $this->client->getAllResources($link, $params, 'Viagogo\Resources\Event');
}
}
38 changes: 38 additions & 0 deletions src/clients/LanguageClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Viagogo\Clients;

use Viagogo\Hal\HalClient;
use Viagogo\Hal\PagedResource;
use Viagogo\Resources\Language;
use Viagogo\Common\ViagogoRequestParams;

/**
*
*/
class LanguageClient extends Client
{
public function getLanguage($languageCode, ViagogoRequestParams $params = null)
{
$root = $this->client->getRoot();
$link = $root->getLanguagesLink()->getHref().'/'.$languageCode;

return $this->client->getResource($link, $params, 'Viagogo\Resources\Country');
}

public function getLanguages(ViagogoRequestParams $params = null)
{
$root = $this->client->getRoot();
$link = $root->getLanguagesLink()->getHref();

return new PagedResource($this->client->getResource($link, $params), 'Viagogo\Resources\Country');
}

public function getAllLanguages(ViagogoRequestParams $params = null)
{
$root = $this->client->getRoot();
$link = $root->getLanguagesLink()->getHref();

return $this->client->getAllResources($link, $params, 'Viagogo\Resources\Country');
}
}
15 changes: 15 additions & 0 deletions src/clients/ListingClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Viagogo\Clients;

use Viagogo\Hal\HalClient;
use Viagogo\Hal\PagedResource;
use Viagogo\Resources\Listing;
use Viagogo\Common\ViagogoRequestParams;

/**
*
*/
class ListingClient extends Client
{
}
15 changes: 15 additions & 0 deletions src/clients/MetroAreaClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Viagogo\Clients;

use Viagogo\Hal\HalClient;
use Viagogo\Hal\PagedResource;
use Viagogo\Resources\MetroArea;
use Viagogo\Common\ViagogoRequestParams;

/**
*
*/
class MetroAreaClient extends Client
{
}
Loading

0 comments on commit 92df715

Please sign in to comment.