Skip to content

Commit

Permalink
API Request Detail json
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Jan 25, 2016
1 parent 9b97ead commit bead72f
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/ApiRequestDetail.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php
namespace Fortifi\Api\Core;

class ApiRequestDetail implements IApiRequestDetail
use Packaged\Helpers\Objects;

class ApiRequestDetail implements IApiRequestDetail, \JsonSerializable
{
protected $_url = '';
protected $_headers = [];
Expand Down Expand Up @@ -250,4 +252,38 @@ public function requiresAuth()
return (bool)$this->_requireAuth;
}

/**
* @inheritDoc
*/
public function jsonSerialize()
{
return [
'url' => $this->_url,
'headers' => $this->_headers,
'options' => $this->_options,
'post' => $this->_post,
'query' => $this->_query,
'body' => $this->_body,
'method' => $this->_method,
'isAsync' => $this->_isAsync,
'requireAuth' => $this->_requireAuth,
];
}

public static function fromJson($json)
{
$obj = is_scalar($json) ? json_decode($json) : $json;
$requestDetail = new static;
$requestDetail->_url = Objects::property($obj, 'url');
$requestDetail->_headers = Objects::property($obj, 'headers');
$requestDetail->_options = Objects::property($obj, 'options');
$requestDetail->_post = Objects::property($obj, 'post');
$requestDetail->_query = Objects::property($obj, 'query');
$requestDetail->_body = Objects::property($obj, 'body');
$requestDetail->_method = Objects::property($obj, 'method');
$requestDetail->_isAsync = Objects::property($obj, 'isAsync');
$requestDetail->_requireAuth = Objects::property($obj, 'requireAuth');
return $requestDetail;
}

}

0 comments on commit bead72f

Please sign in to comment.