Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 61 additions & 12 deletions src/Hyperwallet/Response/ListResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,28 @@
*
* @package Hyperwallet\Response
*/
class ListResponse implements \Countable, \ArrayAccess {
class ListResponse implements \Countable , \ArrayAccess{

/**
* Total number of matching objects
*
* @var int
*/
private $count;
private $limit;

/**
* Has Next Page objects
*
* @var boolean
*/
private $hasNextPage;

/**
* Has Previous Page objects
*
* @var boolean
*/
private $hasPreviousPage;

/**
* Array of Model's
Expand All @@ -22,6 +36,13 @@ class ListResponse implements \Countable, \ArrayAccess {
*/
private $data;

/**
* Array of Model's
*
* @var array
*/
private $links;

/**
* Creates a api list response instance
*
Expand All @@ -30,26 +51,28 @@ class ListResponse implements \Countable, \ArrayAccess {
*/
public function __construct(array $body, $convertEntry) {
if (count($body) == 0) {
$this->count = 0;
$this->hasNextPage = false;
$this->hasPreviousPage = false;
$this->limit = 0 ;
$this->data = array();
} else {
$this->count = $body['count'];
$this->hasNextPage = $body['hasNextPage'];
$this->hasPreviousPage = $body['hasPreviousPage'];
$this->limit = $body['limit'];
$this->links = $body['links'];
$this->data = array_map(function ($item) use ($convertEntry) {
if (isset($item['links'])) {
unset($item['links']);
}
return $convertEntry($item);
}, $body['data']);
}
}

/**
* Get the total number of matching objects
* Get the array of Model's
*
* @return int
* @return array
*/
public function getCount() {
return $this->count;
public function getLinks() {
return $this->links;
}

/**
Expand All @@ -61,6 +84,33 @@ public function getData() {
return $this->data;
}

/**
* Get the Total number of Model's
*
* @var int
*/
public function getLimit() {
return $this->limit;
}

/**
* Get Has Next Page of Model's
*
* @var boolean
*/
public function getHasNextPage() {
return $this->hasNextPage;
}

/**
* Get Has Previous Page of Model's
*
* @var boolean
*/
public function getHasPreviousPage() {
return $this->hasPreviousPage;
}


/**
* @internal
Expand All @@ -76,7 +126,6 @@ public function getData() {
public function count() {
return count($this->data);
}

/**
* @internal
*
Expand Down
6 changes: 2 additions & 4 deletions src/Hyperwallet/Util/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ApiClient {

/**
* The Guzzle http client
*
*
* @var Client
*/
private $client;
Expand Down Expand Up @@ -162,9 +162,7 @@ private function doRequest($method, $url, array $urlParams, array $options) {
$this->checkResponseHeaderContentType($response);
$body = $this->isEncrypted ? \GuzzleHttp\json_decode(\GuzzleHttp\json_encode($this->encryption->decrypt($response->getBody())), true) :
\GuzzleHttp\json_decode($response->getBody(), true);
if (isset($body['links'])) {
unset($body['links']);
}

return $body;
} catch (ConnectException $e) {
$errorResponse = new ErrorResponse(0, array('errors' => array(
Expand Down
Loading