From a5816f9896992c28a6ade586d0ea286be7c11924 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Tue, 5 Sep 2017 21:13:14 +0530 Subject: [PATCH] response split to content & json --- src/GuzzleClient.php | 20 ++++++++++++++++++-- src/RequestClientContract.php | 4 ++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/GuzzleClient.php b/src/GuzzleClient.php index c9daa89..8a8a8a5 100755 --- a/src/GuzzleClient.php +++ b/src/GuzzleClient.php @@ -9,6 +9,8 @@ class GuzzleClient implements RequestClientContract { protected $client; + protected $response; + /** * GuzzleClient constructor. */ @@ -19,12 +21,26 @@ public function __construct() public function send(string $method, string $uri, array $body = null, array $headers = null, array $options = null) { - return json_decode($this->client->request($method, $uri, [ + $this->response = $this->client->request($method, $uri, [ 'form_params' => $body, 'headers' => $headers, 'options' => $options, - ])->getBody()); + ])->getBody(); + + return $this; + } + + public function content() : string + { + return $this->response; + } + public function json() + { + return json_decode($this->response); + } + + } \ No newline at end of file diff --git a/src/RequestClientContract.php b/src/RequestClientContract.php index 052d639..1a2df58 100644 --- a/src/RequestClientContract.php +++ b/src/RequestClientContract.php @@ -6,4 +6,8 @@ interface RequestClientContract { public function send(string $method, string $uri, array $body = null, array $headers = null, array $options = null); + + public function json(); + + public function content(); } \ No newline at end of file