Skip to content

Commit

Permalink
Add the ability to process xml string responses
Browse files Browse the repository at this point in the history
  • Loading branch information
N1ghteyes committed Feb 21, 2019
1 parent 4e3c210 commit 0ca3041
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"require": {
"php" : "^5.3 || ^7.0",
"ext-json": "*",
"ext-simplexml": "*",
"guzzlehttp/guzzle": "^6.3"
},
"authors": [
Expand Down
7 changes: 6 additions & 1 deletion src/apicore/structure/response.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace n1ghteyes\apicore\structure;

use GuzzleHttp;

/**
* @todo make this better.
* Class response
Expand Down Expand Up @@ -42,7 +44,7 @@ public static function verbUsed($verb){

/**
* Process the provided guzzle response object.
* @param $guzzleResponse
* @param GuzzleHttp $guzzleResponse
*/
public static function processResult($guzzleResponse){
self::$response->dataType = array_shift($guzzleResponse->getHeader('Content-Type'));
Expand All @@ -51,6 +53,9 @@ public static function processResult($guzzleResponse){
self::$response->url = $guzzleResponse->getHeaderLine('Location');

switch(self::$response->dataType){
case 'text/xml':
self::$response->data = simplexml_load_string(self::$response->rawBodyData);
break;
case 'application/json':
default:
self::$response->data = json_decode(self::$response->rawBodyData);
Expand Down

0 comments on commit 0ca3041

Please sign in to comment.