summaryrefslogtreecommitdiffstats
path: root/lib/SparkPost/SparkPostResponse.php
diff options
context:
space:
mode:
authorAvi Goldman <avrahamymgoldman@gmail.com>2016-06-24 15:51:34 -0400
committerAvi Goldman <avrahamymgoldman@gmail.com>2016-06-24 15:51:34 -0400
commit55d1bdc1ac65d63df6490f588f3d6e9eb506da79 (patch)
treeb21a8ac66224692fe10b2a3cced0374d18ee7de1 /lib/SparkPost/SparkPostResponse.php
parent1b61a81471fc46cde5a515381e9642e0c884481c (diff)
parent12f363bb1f99891fb4b105009d20c596c35c87ae (diff)
downloadphp-sparkpost-55d1bdc1ac65d63df6490f588f3d6e9eb506da79.zip
php-sparkpost-55d1bdc1ac65d63df6490f588f3d6e9eb506da79.tar.gz
php-sparkpost-55d1bdc1ac65d63df6490f588f3d6e9eb506da79.tar.bz2
merged in 2x
Diffstat (limited to 'lib/SparkPost/SparkPostResponse.php')
-rw-r--r--lib/SparkPost/SparkPostResponse.php107
1 files changed, 107 insertions, 0 deletions
diff --git a/lib/SparkPost/SparkPostResponse.php b/lib/SparkPost/SparkPostResponse.php
new file mode 100644
index 0000000..e6a8fd1
--- /dev/null
+++ b/lib/SparkPost/SparkPostResponse.php
@@ -0,0 +1,107 @@
+<?php
+
+namespace SparkPost;
+
+use Psr\Http\Message\ResponseInterface as ResponseInterface;
+use Psr\Http\Message\StreamInterface as StreamInterface;
+
+class SparkPostResponse implements ResponseInterface
+{
+ /**
+ * ResponseInterface to be wrapped by SparkPostResponse.
+ */
+ private $response;
+
+ /**
+ * set the response to be wrapped.
+ *
+ * @param ResponseInterface $response
+ */
+ public function __construct(ResponseInterface $response)
+ {
+ $this->response = $response;
+ }
+
+ /**
+ * Returns the body.
+ *
+ * @return array $body - the json decoded body from the http response
+ */
+ public function getBody()
+ {
+ $body = $this->response->getBody();
+ $body_string = $body->__toString();
+
+ $json = json_decode($body_string, true);
+
+ return $json;
+ }
+
+ /**
+ * pass these down to the response given in the constructor.
+ */
+ public function getProtocolVersion()
+ {
+ return $this->response->getProtocolVersion();
+ }
+
+ public function withProtocolVersion($version)
+ {
+ return $this->response->withProtocolVersion($version);
+ }
+
+ public function getHeaders()
+ {
+ return $this->response->getHeaders();
+ }
+
+ public function hasHeader($name)
+ {
+ return $this->response->hasHeader($name);
+ }
+
+ public function getHeader($name)
+ {
+ return $this->response->getHeader($name);
+ }
+
+ public function getHeaderLine($name)
+ {
+ return $this->response->getHeaderLine($name);
+ }
+
+ public function withHeader($name, $value)
+ {
+ return $this->response->withHeader($name, $value);
+ }
+
+ public function withAddedHeader($name, $value)
+ {
+ return $this->response->withAddedHeader($name, $value);
+ }
+
+ public function withoutHeader($name)
+ {
+ return $this->response->withoutHeader($name);
+ }
+
+ public function withBody(StreamInterface $body)
+ {
+ return $this->response->withBody($body);
+ }
+
+ public function getStatusCode()
+ {
+ return $this->response->getStatusCode();
+ }
+
+ public function withStatus($code, $reasonPhrase = '')
+ {
+ return $this->response->withStatus($code, $reasonPhrase);
+ }
+
+ public function getReasonPhrase()
+ {
+ return $this->response->getReasonPhrase();
+ }
+}