Skip to content

Commit bbab7fa

Browse files
committed
updates to add getResponseBody functionality
1 parent d259619 commit bbab7fa

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ delete($path)
6666
get($path)
6767
getHeaderLocation()
6868
getHeaderResponseCode()
69+
getResponseBody()
6970
patch($path, $data)
7071
post($path, $data)
7172
put($path, $data)

src/RESTful/CurlWrapper.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class CurlWrapper
1515
protected $_headerProperty = null;
1616
protected $_headerResponseCode = null;
1717
protected $_contentType;
18+
protected $_responseBody;
1819

1920
/**
2021
* Constructor
@@ -133,6 +134,7 @@ private function _parseCurlResponse($content)
133134
{
134135
list($headers, $body) = explode("\r\n\r\n", $content, 2);
135136
$this->_parseCurlHeader($headers);
137+
$this->_setResponseBody($body);
136138
return $body;
137139
}
138140

@@ -151,19 +153,18 @@ private function _parseCurlHeader($headers)
151153
}
152154
}
153155

154-
/**
155-
* @param string[] $headerArray
156-
*/
156+
private function _setResponseBody($body)
157+
{
158+
$this->_responseBody = $body;
159+
}
160+
157161
private function _addHeaderAuthentication(&$headerArray)
158162
{
159163
if ($this->_isHeaderAuthentication()) {
160164
array_push($headerArray, $this->_headerProperty . ': ' . $this->_token);
161165
}
162166
}
163167

164-
/**
165-
* @param string $location
166-
*/
167168
private function _setHeaderLocation($location)
168169
{
169170
$this->_headerLocation = $location;

src/RESTful/RESTful.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ public function getHeaderLocation()
109109
return $this->_headerLocation;
110110
}
111111

112+
/**
113+
* Get REST call Response Body
114+
*
115+
* @return "string"
116+
*/
117+
public function getResponseBody()
118+
{
119+
return $this->_responseBody;
120+
}
121+
112122
/**
113123
* Get REST call Header Status Code Property
114124
*

src/RESTful/RESTfulInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public function getHeaderLocation();
4747
*/
4848
public function getHeaderResponseCode();
4949

50+
/**
51+
* @return string
52+
*/
53+
public function getResponseBody();
54+
5055
/**
5156
* @return string
5257
*/

tests/unit/RESTfulTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ public function testGetHeaderResponseCodeNull()
123123
$this->assertNull($actualResponse);
124124
}
125125

126+
public function testGetResponseBody()
127+
{
128+
$this->_RESTful->patch(self::DEFAULT_PATH, self::DEFAULT_PATCH_DATA);
129+
$actualResponse = $this->_RESTful->getResponseBody();
130+
$this->assertEquals('{"lastName": "Baker-Boy"}', $actualResponse);
131+
}
132+
126133
/************ Providers ************/
127134

128135
public function headerAuthenticationProvider()

0 commit comments

Comments
 (0)