Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

Commit

Permalink
Added support for staging env
Browse files Browse the repository at this point in the history
  • Loading branch information
sprain committed Sep 24, 2015
1 parent e5b095a commit c330619
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
32 changes: 29 additions & 3 deletions lib/SeatsIo/SeatsIo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Ticketpark\SeatsIo;

use Buzz\Browser;
use Buzz\Client\Curl;
use Buzz\Message\Response;

/**
Expand All @@ -18,6 +19,11 @@ class SeatsIo
*/
const BASE_URL = 'https://app.seats.io/api/';

/**
* @const string BASE_URL_STAGING
*/
const BASE_URL_STAGING = 'https://app-staging.seats.io/api/';

/**
* @var string $secretKey
*/
Expand All @@ -44,16 +50,36 @@ class SeatsIo
*/
protected $lastErrorStatusCode;

/**
* @var string
*/
protected $baseUrl;

/**
* Constructor
*
* @param string $secretKey
* @param Browser $browser
*/
public function __construct($secretKey = null, Browser $browser = null)
public function __construct($secretKey = null, Browser $browser = null, $stagingEnvironment = false)
{
$this->setSecretKey($secretKey);
$this->setBrowser($browser);
$this->baseUrl = self::BASE_URL;

if ($stagingEnvironment) {

// Force the browser to ignore SSL errors when using the stage environment
$curlClient = new Curl();
$curlClient->setOption(CURLOPT_SSL_VERIFYHOST, 0);
$curlClient->setOption(CURLOPT_SSL_VERIFYPEER, 0);

$browser = clone $browser;
$browser->setClient($curlClient);
$this->setBrowser($browser);

$this->baseUrl = self::BASE_URL_STAGING;
}
}

/**
Expand Down Expand Up @@ -288,7 +314,7 @@ protected function get($url)
{
$this->checkSetup();

$url = self::BASE_URL . $url;
$url = $this->baseUrl . $url;

return $this->handleResponse(
$this->getBrowser()->get($url)
Expand All @@ -305,7 +331,7 @@ protected function post($url, $data = null)
{
$this->checkSetup();

$url = self::BASE_URL . $url;
$url = $this->baseUrl . $url;

return $this->handleResponse(
$this->getBrowser()->post($url, array(), json_encode($data))
Expand Down
10 changes: 10 additions & 0 deletions tests/SeatsIo/Tests/SeatsIoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ public function testGetCharts()
);
}

public function testGetChartsStaging()
{
$seatsIo = new SeatsIo('secretKey', $this->getBrowserMock('get'), true);

$this->assertSame(
'https://app-staging.seats.io/api/charts/secretKey',
$seatsIo->getCharts()
);
}

public function testGetChartForEvent()
{
$seatsIo = new SeatsIo('secretKey', $this->getBrowserMock('get'));
Expand Down

0 comments on commit c330619

Please sign in to comment.