Skip to content

Commit

Permalink
Use SickBeardException
Browse files Browse the repository at this point in the history
  • Loading branch information
Jleagle committed Jun 18, 2015
1 parent cd8afb9 commit 4c51cd0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
6 changes: 6 additions & 0 deletions src/Exceptions/SickBeardException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
namespace Jleagle\SickBeard\Exceptions;

class SickBeardException extends \Exception
{
}
50 changes: 23 additions & 27 deletions src/SickBeard.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,22 @@
use Jleagle\SickBeard\Enums\LogEnum;
use Jleagle\SickBeard\Enums\ShowsSortEnum;
use Jleagle\SickBeard\Enums\SortOrderEnum;
use Jleagle\SickBeard\Exceptions\SickBeardException;

class SickBeard
{
private $url;
private $apiKey;
protected $_url;
protected $_apiKey;

private $debug = 0;
private $profile = 0;
private $help = 0;
private $callback = '';
protected $_debug = 0;
protected $_profile = 0;
protected $_help = 0;
protected $_callback = '';

public function __construct($url, $apiKey)
{
if(!$url || !$apiKey)
{
throw new \Exception('URL & API key are required');
}

$this->url = $url;
$this->apiKey = $apiKey;
$this->_url = $url;
$this->_apiKey = $apiKey;
}

/**
Expand Down Expand Up @@ -731,37 +727,37 @@ public function sickBeardShutdown()
*
* @return array
*
* @throws \Exception
* @throws SickBeardException
*/
private function _request($params)
protected function _request($params)
{

if($this->debug)
if($this->_debug)
{
$params['debug'] = 1;
}
if($this->profile)
if($this->_profile)
{
$params['profile'] = 1;
}
if($this->help)
if($this->_help)
{
$params['help'] = 1;
}
if($this->callback)
if($this->_callback)
{
$params['callback'] = $this->callback;
$params['callback'] = $this->_callback;
}

$url = $this->url . '/api/' . $this->apiKey . '/?';
$url = $this->_url . '/api/' . $this->_apiKey . '/?';
$query = http_build_query($params);

$client = new Guzzle();
$response = $client->get($url . $query);

if($response->getStatusCode() != 200)
{
throw new \Exception('Invalid response');
throw new SickBeardException('Invalid response');
}

$body = $response->getBody();
Expand All @@ -773,7 +769,7 @@ private function _request($params)

if(isset($array['result']) && $array['result'] != 'success')
{
throw new \Exception($array['message']);
throw new SickBeardException($array['message']);
}

return $array['data'];
Expand All @@ -792,7 +788,7 @@ private function _request($params)
*/
public function setDebug($debug = true)
{
$this->debug = $debug ? 1 : 0;
$this->_debug = $debug ? 1 : 0;
return $this;
}

Expand All @@ -803,7 +799,7 @@ public function setDebug($debug = true)
*/
public function setHelp($help = true)
{
$this->help = $help ? 1 : 0;
$this->_help = $help ? 1 : 0;
return $this;
}

Expand All @@ -814,7 +810,7 @@ public function setHelp($help = true)
*/
public function setProfile($profile = true)
{
$this->profile = $profile ? 1 : 0;
$this->_profile = $profile ? 1 : 0;
return $this;
}

Expand All @@ -825,7 +821,7 @@ public function setProfile($profile = true)
*/
public function setCallback($callback)
{
$this->callback = $callback;
$this->_callback = $callback;
return $this;
}
}

0 comments on commit 4c51cd0

Please sign in to comment.