Skip to content

Commit

Permalink
Issue #33 - Cleanup. Additional exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
sqmk committed Dec 28, 2012
1 parent 50ef1f6 commit 0bcf89e
Show file tree
Hide file tree
Showing 29 changed files with 164 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ before_install:
- composer install --dev

script:
- ./vendor/bin/phpcs --standard=tests/codesniffer.xml library/
- ./vendor/bin/phpcs --standard=tests/phpcs.xml library/
- ./vendor/bin/phpunit --configuration=tests

notifications:
Expand Down
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
],
"homepage": "http://github.com/sqmk/phue",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Michael Squires",
"email": "[email protected]",
"role": "lead"
}
],
"require": {
"php": "5.4.*"
},
Expand Down
4 changes: 2 additions & 2 deletions library/Phue/Command/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Phue\Command;

use Phue\Client;
use Phue\Transport\Http;
use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;

/**
Expand All @@ -34,7 +34,7 @@ public function send(Client $client)
// Get response
$response = $client->getTransport()->sendRequest(
'',
Http::METHOD_POST,
TransportInterface::METHOD_POST,
$this->buildRequestData($client)
);

Expand Down
4 changes: 2 additions & 2 deletions library/Phue/Command/CreateGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Phue\Command;

use Phue\Client;
use Phue\Transport\Http;
use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;

/**
Expand Down Expand Up @@ -92,7 +92,7 @@ public function send(Client $client)
{
$response = $client->getTransport()->sendRequest(
"{$client->getUsername()}/groups",
Http::METHOD_POST,
TransportInterface::METHOD_POST,
(object) [
'name' => $this->name,
'lights' => $this->lights
Expand Down
6 changes: 4 additions & 2 deletions library/Phue/Command/CreateSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Phue\Command;

use Phue\Client;
use Phue\Transport\Http;
use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;
use Phue\Command\SchedulableInterface;

Expand Down Expand Up @@ -70,6 +70,8 @@ public function __construct(
$time !== null && $this->time($time);
$command !== null && $this->command($command);

// Copy description
$this->description = $this->name;
}

/**
Expand Down Expand Up @@ -141,7 +143,7 @@ public function send(Client $client)
{
$scheduleId = $client->getTransport()->sendRequest(
"{$client->getUsername()}/schedules",
Http::METHOD_POST,
TransportInterface::METHOD_POST,
(object) [
'name' => $this->name,
'description' => $this->description,
Expand Down
4 changes: 2 additions & 2 deletions library/Phue/Command/DeleteGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Phue\Command;

use Phue\Client;
use Phue\Transport\Http;
use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;

/**
Expand Down Expand Up @@ -50,7 +50,7 @@ public function send(Client $client)
{
$client->getTransport()->sendRequest(
"{$client->getUsername()}/groups/{$this->groupId}",
Http::METHOD_DELETE
TransportInterface::METHOD_DELETE
);
}
}
4 changes: 2 additions & 2 deletions library/Phue/Command/DeleteSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Phue\Command;

use Phue\Client;
use Phue\Transport\Http;
use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;

/**
Expand Down Expand Up @@ -50,7 +50,7 @@ public function send(Client $client)
{
$client->getTransport()->sendRequest(
"{$client->getUsername()}/schedules/{$this->scheduleId}",
Http::METHOD_DELETE
TransportInterface::METHOD_DELETE
);
}
}
4 changes: 2 additions & 2 deletions library/Phue/Command/SetBridgeConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Phue\Command;

use Phue\Client;
use Phue\Transport\Http;
use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;

/**
Expand Down Expand Up @@ -50,7 +50,7 @@ public function send(Client $client)
{
$client->getTransport()->sendRequest(
"{$client->getUsername()}/config",
Http::METHOD_PUT,
TransportInterface::METHOD_PUT,
(object) $this->config
);
}
Expand Down
4 changes: 2 additions & 2 deletions library/Phue/Command/SetGroupAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Phue\Command;

use Phue\Client;
use Phue\Transport\Http;
use Phue\Transport\TransportInterface;
use Phue\Command\SetLightState;
use Phue\Command\SchedulableInterface;

Expand Down Expand Up @@ -72,7 +72,7 @@ public function getSchedulableParams(Client $client)
{
return [
'address' => "{$client->getUsername()}/groups/{$this->groupId}/action",
'method' => Http::METHOD_PUT,
'method' => TransportInterface::METHOD_PUT,
'body' => (object) $this->params
];
}
Expand Down
4 changes: 2 additions & 2 deletions library/Phue/Command/SetGroupConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Phue\Command;

use Phue\Client;
use Phue\Transport\Http;
use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;

/**
Expand Down Expand Up @@ -91,7 +91,7 @@ public function send(Client $client)
{
$client->getTransport()->sendRequest(
"{$client->getUsername()}/groups/{$this->groupId}",
Http::METHOD_PUT,
TransportInterface::METHOD_PUT,
(object) $this->params
);
}
Expand Down
4 changes: 2 additions & 2 deletions library/Phue/Command/SetLightName.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

use Phue\Client;
use Phue\Light;
use Phue\Transport\Http;
use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;

/**
Expand Down Expand Up @@ -60,7 +60,7 @@ public function send(Client $client)
{
$client->getTransport()->sendRequest(
"{$client->getUsername()}/lights/{$this->lightId}",
Http::METHOD_PUT,
TransportInterface::METHOD_PUT,
(object) [
'name' => $this->name
]
Expand Down
4 changes: 2 additions & 2 deletions library/Phue/Command/SetLightState.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Phue\Command;

use Phue\Client;
use Phue\Transport\Http;
use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;
use Phue\Command\SchedulableInterface;

Expand Down Expand Up @@ -327,7 +327,7 @@ public function getSchedulableParams(Client $client)
{
return [
'address' => "{$client->getUsername()}/lights/{$this->lightId}/state",
'method' => Http::METHOD_PUT,
'method' => TransportInterface::METHOD_PUT,
'body' => (object) $this->params
];
}
Expand Down
4 changes: 2 additions & 2 deletions library/Phue/Command/StartLightScan.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Phue\Command;

use Phue\Client;
use Phue\Transport\Http;
use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;

/**
Expand All @@ -34,7 +34,7 @@ public function send(Client $client)
// Get response
$response = $client->getTransport()->sendRequest(
"{$client->getUsername()}/lights",
Http::METHOD_POST
TransportInterface::METHOD_POST
);

return $response;
Expand Down
4 changes: 3 additions & 1 deletion library/Phue/Transport/Exception/InvalidBodyException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

namespace Phue\Transport\Exception;

use Phue\Transport\Exception\BridgeException;

/**
* Invalid body exception
*
* @category Phue
* @package Phue
*/
class InvalidBodyException extends \Exception
class InvalidBodyException extends BridgeException
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

namespace Phue\Transport\Exception;

use Phue\Transport\Exception\BridgeException;

/**
* Invalid parameter exception
*
* @category Phue
* @package Phue
*/
class InvalidParameterException extends \Exception
class InvalidParameterException extends BridgeException
{
}
4 changes: 3 additions & 1 deletion library/Phue/Transport/Exception/InvalidValueException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

namespace Phue\Transport\Exception;

use Phue\Transport\Exception\BridgeException;

/**
* Invalid value exception
*
* @category Phue
* @package Phue
*/
class InvalidValueException extends \Exception
class InvalidValueException extends BridgeException
{
}
4 changes: 3 additions & 1 deletion library/Phue/Transport/Exception/MethodException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

namespace Phue\Transport\Exception;

use Phue\Transport\Exception\BridgeException;

/**
* Method exception
*
* @category Phue
* @package Phue
*/
class MethodException extends \Exception
class MethodException extends BridgeException
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

namespace Phue\Transport\Exception;

use Phue\Transport\Exception\BridgeException;

/**
* Parameter unavailable exception
*
* @category Phue
* @package Phue
*/
class ParameterUnavailableException extends \Exception
class ParameterUnavailableException extends BridgeException
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* Phue: Philips Hue PHP Client
*
* @author Michael Squires <sqmk@php.net>
* @copyright Copyright (c) 2012 Michael K. Squires
* @license http://github.com/sqmk/Phue/wiki/License
* @package Phue
*/

namespace Phue\Transport\Exception;

use Phue\Transport\Exception\BridgeException;

/**
* Parameter unmodifiable exception
*
* @category Phue
* @package Phue
*/
class ParameterUnmodifiableException extends BridgeException
{
}
4 changes: 3 additions & 1 deletion library/Phue/Transport/Exception/ResourceException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

namespace Phue\Transport\Exception;

use Phue\Transport\Exception\BridgeException;

/**
* Resource exception
*
* @category Phue
* @package Phue
*/
class ResourceException extends \Exception
class ResourceException extends BridgeException
{
}
24 changes: 2 additions & 22 deletions library/Phue/Transport/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Http implements TransportInterface
6 => 'Phue\Transport\Exception\ParameterUnavailableException',
7 => 'Phue\Transport\Exception\InvalidValueException',
101 => 'Phue\Transport\Exception\LinkButtonException',
201 => 'Phue\Transport\Exception\ParameterUnmodifiableException',
301 => 'Phue\Transport\Exception\GroupTableFullException',
901 => 'Phue\Transport\Exception\ThrottleException',
];
Expand Down Expand Up @@ -110,7 +111,7 @@ public function setAdapter(AdapterInterface $adapter)
public function sendRequest($address, $method = self::METHOD_GET, \stdClass $body = null)
{
// Build request url
$url = $this->buildRequestUrl($address, true);
$url = "http://{$this->client->getHost()}/api/{$address}";

// Open connection
$this->getAdapter()->open();
Expand Down Expand Up @@ -152,27 +153,6 @@ public function sendRequest($address, $method = self::METHOD_GET, \stdClass $bod
return $jsonResults;
}

/**
* Build request URL
*
* @param string $path Request path
* @param bool $includeHost Include host in path
*
* @return string Request URL
*/
public function buildRequestUrl($path, $includeHost = false)
{
// Start with full path
$fullPath = "/api/{$path}";

// Include host if necessary
if ($includeHost) {
$fullPath = "http://{$this->client->getHost()}" . $fullPath;
}

return $fullPath;
}

/**
* Get exception by type
*
Expand Down
Loading

0 comments on commit 0bcf89e

Please sign in to comment.