Skip to content

Commit

Permalink
Rework abstract api to allow replacements within extended apis
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Nov 21, 2014
1 parent 78b47b8 commit 3955046
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions src/Abstracts/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,12 @@ protected function _buildEndpointUrl(EndpointInterface $endpointInterface)
*/
public function processRequest(ApiRequestInterface $request)
{
$client = $this->_getClient();
$verb = $request->getVerb();
$options = [];

if($verb == HttpVerb::POST)
{
$options['body'] = $request->getPostData();
}

$apiRequest = $client->createRequest(
$verb,
build_path_unix($this->getUrl(), $request->getPath())
. $request->getQueryString(),
$options
);
$apiRequest = $this->_createRequest($request);

$time = microtime(true);
try
{
$response = $client->send($apiRequest);
$response = $this->_getClient()->send($apiRequest);
}
catch(ClientException $e)
{
Expand All @@ -92,4 +78,36 @@ public function processRequest(ApiRequestInterface $request)
$format = new JsonFormat();
return $format->decode($response, number_format($totalTime * 1000, 3));
}

/**
* @param ApiRequestInterface $request
*
* @return \GuzzleHttp\Message\RequestInterface
*/
protected function _createRequest(ApiRequestInterface $request)
{
return $this->_getClient()->createRequest(
$request->getVerb(),
build_path_unix($this->getUrl(), $request->getPath())
. $request->getQueryString(),
$this->_makeOptions($request)
);
}

/**
* @param ApiRequestInterface $request
*
* @return array
*/
protected function _makeOptions(ApiRequestInterface $request)
{
$options = [];

if($request->getVerb() == HttpVerb::POST)
{
$options['body'] = $request->getPostData();
}

return $options;
}
}

0 comments on commit 3955046

Please sign in to comment.