diff --git a/VERSION b/VERSION index a67658d..b1b57dd 100755 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.0-beta +0.1.0-beta.2 diff --git a/composer.json b/composer.json index 21da51d..9992bd8 100755 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "vhx/vhx-php", - "version": "1.0.0-beta", + "version": "1.0.0-beta.2", "description": "VHX PHP API Wrapper", "keywords": [ "vhx", diff --git a/init.php b/init.php index 8a091da..e5d14e5 100755 --- a/init.php +++ b/init.php @@ -12,8 +12,8 @@ // Errors require(dirname(__FILE__) . '/lib/errors/base.php'); -// require(dirname(__FILE__) . '/lib/Error/Api.php'); -// require(dirname(__FILE__) . '/lib/Error/ApiConnection.php'); -// require(dirname(__FILE__) . '/lib/Error/Authentication.php'); +require(dirname(__FILE__) . '/lib/errors/api.php'); +require(dirname(__FILE__) . '/lib/errors/connection.php'); +require(dirname(__FILE__) . '/lib/errors/authentication.php'); require(dirname(__FILE__) . '/lib/errors/invalidRequest.php'); -// require(dirname(__FILE__) . '/lib/Error/RateLimit.php'); +require(dirname(__FILE__) . '/lib/errors/resourceNotFound.php'); diff --git a/lib/api.php b/lib/api.php index f05056a..d40777c 100644 --- a/lib/api.php +++ b/lib/api.php @@ -5,10 +5,8 @@ class API { public static $key; - const HOST = 'api.crystal.dev'; - const PROTOCOL = 'http://'; - const PORT = '7000'; - const BASE_PATH = '/v1/'; + const HOST = 'api.vhx.tv'; + const PROTOCOL = 'https://'; const API_VERSION = null; public static function setKey($api_key) { diff --git a/lib/errors/api.php b/lib/errors/api.php new file mode 100644 index 0000000..de20f2b --- /dev/null +++ b/lib/errors/api.php @@ -0,0 +1,9 @@ +message = $message; - $this->httpStatus = $http_status; - $this->httpBody = $http_body; - $this->jsonBody = $json_body; - $this->httpHeaders = $http_headers; + public function __construct($message, $http_status = null) { + $this->message = $message; + $this->httpStatus = $http_status; + } + public function getHttpStatus() { + return $this->httpStatus; + } + public function getErrorResponse() { + return json_decode($this->message, true); + } + public function getErrorJSONResponse() { + return $this->message; } } diff --git a/lib/errors/connection.php b/lib/errors/connection.php index fc72bf4..40868b8 100644 --- a/lib/errors/connection.php +++ b/lib/errors/connection.php @@ -2,7 +2,7 @@ namespace VHX\Error; -class Connection extends Base { +class ApiConnection extends Base { public function __construct($message = null, $http_status = null, $http_body = null, $json_body = null, $http_headers = null) { parent::__construct($message, $http_status, $http_body, $json_body, $http_headers); } diff --git a/lib/errors/resourceNotFound.php b/lib/errors/resourceNotFound.php new file mode 100644 index 0000000..32f7403 --- /dev/null +++ b/lib/errors/resourceNotFound.php @@ -0,0 +1,9 @@ += 200 && $code < 300): + return json_decode($body, true); + else: + self::_handleResponseError($body, $code); + endif; + } + + protected static function _handleResponseError($result, $code) { + switch ($code) { + case 400: + throw new Error\InvalidRequest($result, $code); + break; + case 401: + throw new Error\Authentication($result, $code); + break; + case 404: + throw new Error\ResourceNotFound($result, $code); + break; + case 408: + throw new Error\ApiConnection($result, $code); + break; + case 500: + default: + throw new Error\API($result, $code); + break; + } + } + + protected static function handleCurlError($url, $errno, $message) { + switch ($errno) { + case CURLE_COULDNT_CONNECT: + case CURLE_COULDNT_RESOLVE_HOST: + case CURLE_OPERATION_TIMEOUTED: + $msg = "Could not connect to VHX ($url). Please check your internet connection and try again. If this problem persists, you should check VHX's service status at https://twitter.com/vhxstatus, http://status.vhx.tv/, or"; + break; + default: + $msg = "Unexpected error communicating with VHX. If this problem persists,"; + } + $msg .= " let us know at support@vhx.tv. \n\n(Network error [errno $errno]: $message)"; + throw new Error\ApiConnection(msg, 408); } }