Skip to content

Commit

Permalink
refactor: remove query pagination getter/setter
Browse files Browse the repository at this point in the history
  • Loading branch information
faustbrian committed Dec 18, 2018
1 parent dbf9766 commit a3cbdf8
Showing 1 changed file with 3 additions and 53 deletions.
56 changes: 3 additions & 53 deletions src/API/AbstractAPI.php
Expand Up @@ -32,20 +32,6 @@ abstract class AbstractAPI
*/
public $connection;

/**
* The requested offset.
*
* @var null|int
*/
protected $offset;

/**
* Number of items per request.
*
* @var null|int
*/
protected $limit;

/**
* Create a new API class instance.
*
Expand All @@ -56,53 +42,17 @@ public function __construct(Connection $connection)
$this->connection = $connection;
}

public function getOffset(): ?int
{
return $this->offset;
}

public function setOffset(int $offset): API
{
$this->offset = (null === $offset ? $offset : (int) $offset);

return $this;
}

public function getLimit(): ?int
{
return $this->limit;
}

public function setLimit(int $limit): API
{
$this->limit = (null === $limit ? $limit : (int) $limit);

return $this;
}

/**
* Send a GET request with query parameters.
*
* @param string $path
* @param array $parameters
* @param array $query
*
* @return array|string
*/
protected function get(string $path, array $parameters = [])
protected function get(string $path, array $query = [])
{
if (null !== $this->offset && ! isset($parameters['offset'])) {
$parameters['offset'] = $this->offset;
}

if (null !== $this->limit && ! isset($parameters['limit'])) {
$parameters['limit'] = $this->limit;
}

if (count($parameters) > 0) {
$path .= '?'.http_build_query($parameters);
}

$response = $this->connection->getHttpClient()->get($path);
$response = $this->connection->getHttpClient()->get($path, compact('query'));

return json_decode($response->getBody()->getContents(), true);
}
Expand Down

0 comments on commit a3cbdf8

Please sign in to comment.