Permalink
Browse files

Issue #33 - Cleanup. Additional exception.

  • Loading branch information...
1 parent 50ef1f6 commit 0bcf89e82a3dbdd29220e4e2afefcd5977621173 @sqmk committed Dec 28, 2012
Showing with 164 additions and 125 deletions.
  1. +1 −1 .travis.yml
  2. +7 −0 composer.json
  3. +2 −2 library/Phue/Command/Authenticate.php
  4. +2 −2 library/Phue/Command/CreateGroup.php
  5. +4 −2 library/Phue/Command/CreateSchedule.php
  6. +2 −2 library/Phue/Command/DeleteGroup.php
  7. +2 −2 library/Phue/Command/DeleteSchedule.php
  8. +2 −2 library/Phue/Command/SetBridgeConfig.php
  9. +2 −2 library/Phue/Command/SetGroupAction.php
  10. +2 −2 library/Phue/Command/SetGroupConfig.php
  11. +2 −2 library/Phue/Command/SetLightName.php
  12. +2 −2 library/Phue/Command/SetLightState.php
  13. +2 −2 library/Phue/Command/StartLightScan.php
  14. +3 −1 library/Phue/Transport/Exception/InvalidBodyException.php
  15. +3 −1 library/Phue/Transport/Exception/InvalidParameterException.php
  16. +3 −1 library/Phue/Transport/Exception/InvalidValueException.php
  17. +3 −1 library/Phue/Transport/Exception/MethodException.php
  18. +3 −1 library/Phue/Transport/Exception/ParameterUnavailableException.php
  19. +23 −0 library/Phue/Transport/Exception/ParameterUnmodifiableException.php
  20. +3 −1 library/Phue/Transport/Exception/ResourceException.php
  21. +2 −22 library/Phue/Transport/Http.php
  22. +6 −4 tests/PhueTest/Command/CreateGroupTest.php
  23. +21 −15 tests/PhueTest/Command/CreateScheduleTest.php
  24. +5 −3 tests/PhueTest/Command/IsAuthorizedTest.php
  25. +5 −3 tests/PhueTest/Command/SetGroupActionTest.php
  26. +6 −4 tests/PhueTest/Command/SetGroupConfigTest.php
  27. +45 −27 tests/PhueTest/Command/SetLightStateTest.php
  28. +1 −18 tests/PhueTest/Transport/HttpTest.php
  29. 0 tests/{codesniffer.xml → phpcs.xml}
View
@@ -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:
View
@@ -10,6 +10,13 @@
],
"homepage": "http://github.com/sqmk/phue",
"license": "BSD-3-Clause",
+ "authors": [
+ {
+ "name": "Michael Squires",
+ "email": "sqmk@php.net",
+ "role": "lead"
+ }
+ ],
"require": {
"php": "5.4.*"
},
@@ -11,7 +11,7 @@
namespace Phue\Command;
use Phue\Client;
-use Phue\Transport\Http;
+use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;
/**
@@ -34,7 +34,7 @@ public function send(Client $client)
// Get response
$response = $client->getTransport()->sendRequest(
'',
- Http::METHOD_POST,
+ TransportInterface::METHOD_POST,
$this->buildRequestData($client)
);
@@ -11,7 +11,7 @@
namespace Phue\Command;
use Phue\Client;
-use Phue\Transport\Http;
+use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;
/**
@@ -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
@@ -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;
@@ -70,6 +70,8 @@ public function __construct(
$time !== null && $this->time($time);
$command !== null && $this->command($command);
+ // Copy description
+ $this->description = $this->name;
}
/**
@@ -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,
@@ -11,7 +11,7 @@
namespace Phue\Command;
use Phue\Client;
-use Phue\Transport\Http;
+use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;
/**
@@ -50,7 +50,7 @@ public function send(Client $client)
{
$client->getTransport()->sendRequest(
"{$client->getUsername()}/groups/{$this->groupId}",
- Http::METHOD_DELETE
+ TransportInterface::METHOD_DELETE
);
}
}
@@ -11,7 +11,7 @@
namespace Phue\Command;
use Phue\Client;
-use Phue\Transport\Http;
+use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;
/**
@@ -50,7 +50,7 @@ public function send(Client $client)
{
$client->getTransport()->sendRequest(
"{$client->getUsername()}/schedules/{$this->scheduleId}",
- Http::METHOD_DELETE
+ TransportInterface::METHOD_DELETE
);
}
}
@@ -11,7 +11,7 @@
namespace Phue\Command;
use Phue\Client;
-use Phue\Transport\Http;
+use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;
/**
@@ -50,7 +50,7 @@ public function send(Client $client)
{
$client->getTransport()->sendRequest(
"{$client->getUsername()}/config",
- Http::METHOD_PUT,
+ TransportInterface::METHOD_PUT,
(object) $this->config
);
}
@@ -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;
@@ -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
];
}
@@ -11,7 +11,7 @@
namespace Phue\Command;
use Phue\Client;
-use Phue\Transport\Http;
+use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;
/**
@@ -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
);
}
@@ -12,7 +12,7 @@
use Phue\Client;
use Phue\Light;
-use Phue\Transport\Http;
+use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;
/**
@@ -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
]
@@ -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;
@@ -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
];
}
@@ -11,7 +11,7 @@
namespace Phue\Command;
use Phue\Client;
-use Phue\Transport\Http;
+use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;
/**
@@ -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;
@@ -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
{
}
@@ -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
{
}
@@ -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
{
}
@@ -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
{
}
@@ -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
{
}
@@ -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
+{
+}
@@ -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
{
}
@@ -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',
];
@@ -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();
@@ -153,27 +154,6 @@ public function sendRequest($address, $method = self::METHOD_GET, \stdClass $bod
}
/**
- * 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
*
* @param string $type Error type
Oops, something went wrong.

0 comments on commit 0bcf89e

Please sign in to comment.