1
0
mirror of synced 2024-11-24 14:26:06 +03:00

Merge pull request #65 from gwinn/master

add getters for response & raw response
This commit is contained in:
Alex Lushpai 2019-04-23 14:23:42 +03:00 committed by GitHub
commit ae1c1fa360
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -13,7 +13,8 @@
],
"require": {
"php": ">=5.4.0",
"ext-curl": "*"
"ext-curl": "*",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "4.*",

View File

@ -33,6 +33,9 @@ class ApiResponse implements \ArrayAccess
// HTTP response status code
protected $statusCode;
// raw json response
protected $rawResponse;
// response assoc array
protected $response;
@ -47,6 +50,7 @@ class ApiResponse implements \ArrayAccess
public function __construct($statusCode, $responseBody = null)
{
$this->statusCode = (int) $statusCode;
$this->rawResponse = $responseBody;
if (!empty($responseBody)) {
$response = json_decode($responseBody, true);
@ -72,6 +76,26 @@ class ApiResponse implements \ArrayAccess
return $this->statusCode;
}
/**
* Return HTTP response
*
* @return array
*/
public function getResponse()
{
return $this->response;
}
/**
* Return HTTP raw response body
*
* @return string
*/
public function getResponseBody()
{
return $this->rawResponse;
}
/**
* HTTP request was successful
*
@ -191,3 +215,4 @@ class ApiResponse implements \ArrayAccess
return $this->response[$offset];
}
}