diff --git a/lib/SeatsIo/SeatsIo.php b/lib/SeatsIo/SeatsIo.php index eb97c4a..b111bc2 100644 --- a/lib/SeatsIo/SeatsIo.php +++ b/lib/SeatsIo/SeatsIo.php @@ -3,6 +3,7 @@ namespace Ticketpark\SeatsIo; use Buzz\Browser; +use Buzz\Client\Curl; use Buzz\Message\Response; /** @@ -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 */ @@ -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; + } } /** @@ -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) @@ -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)) diff --git a/tests/SeatsIo/Tests/SeatsIoTest.php b/tests/SeatsIo/Tests/SeatsIoTest.php index efd3d50..feea11a 100644 --- a/tests/SeatsIo/Tests/SeatsIoTest.php +++ b/tests/SeatsIo/Tests/SeatsIoTest.php @@ -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'));