From 972f8e9c260a041ec2a4dd9c9593a20bead46e5b Mon Sep 17 00:00:00 2001 From: PJ Dietz Date: Tue, 26 Mar 2013 21:05:36 -0400 Subject: [PATCH] Update Request and Response Add constructor for Request to provide URI and method on instantiation. Add success property and getSuccess() method Response. Closes #1 --- src/pjdietz/WellRESTed/Request.php | 17 +++++++++++++++++ src/pjdietz/WellRESTed/Response.php | 12 +++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/pjdietz/WellRESTed/Request.php b/src/pjdietz/WellRESTed/Request.php index d517c31..46740ac 100644 --- a/src/pjdietz/WellRESTed/Request.php +++ b/src/pjdietz/WellRESTed/Request.php @@ -74,6 +74,23 @@ class Request extends Message */ static protected $theRequest; + // ------------------------------------------------------------------------- + + /** + * Create a new Request instance. + * + * @param string|null $uri + * @param string $method + */ + public function __construct($uri = null, $method = 'GET') + { + if (!is_null($uri)) { + $this->setUri($uri); + } + + $this->method = $method; + } + // ------------------------------------------------------------------------- // Accessors diff --git a/src/pjdietz/WellRESTed/Response.php b/src/pjdietz/WellRESTed/Response.php index 1ed06e8..98a1211 100644 --- a/src/pjdietz/WellRESTed/Response.php +++ b/src/pjdietz/WellRESTed/Response.php @@ -19,10 +19,10 @@ use \InvalidArgumentException; * @property string reasonPhrase Text explanation of status code. * @property int statusCode HTTP status code * @property-read string statusLine HTTP status line, e.g. "HTTP/1.1 200 OK" + * @property-read bool success True if the status code is 2xx */ class Response extends Message { - /** * Text explanation of the HTTP Status Code. You only need to set this if * you are using nonstandard status codes. Otherwise, the instance will @@ -94,6 +94,16 @@ class Response extends Message return $this->reasonPhrase; } + /** + * Return true if the status code is in the 2xx range. + * + * @return bool + */ + public function getSuccess() + { + return $this->statusCode >= 200 && $this->statusCode < 300; + } + /** * Assign an explaination for the status code. Not normally needed. *