Skip to content

Commit

Permalink
Update with latest entry model for pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhall17 committed May 16, 2020
1 parent 71f9173 commit 650cb94
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"guzzlehttp/guzzle": "~6.0|~5.0|~4.0",
"firebase/php-jwt": "^5.0",
"illuminate/support": "^5.5|^6.0",
"macsidigital/laravel-oauth2-client": "^1.0"
"macsidigital/laravel-oauth2-client": "v1.x-dev"
},
"require-dev": {
"mockery/mockery": "^1.0|^1.3",
Expand Down
121 changes: 118 additions & 3 deletions src/Support/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,47 @@
use MacsiDigital\API\Facades\Client;
use MacsiDigital\API\Facades\ClientContract;
use MacsiDigital\API\Exceptions\NodeNotFoundException;
use MacsiDigital\API\Exceptions\NoClientSetException;
use MacsiDigital\API\Contracts\Entry as EntryContract;

class Entry implements EntryContract
abstract class Entry implements EntryContract
{
protected $request = null;
// The Entry model is where we build our API gateway and set the defaults.
// This should be extended in the core API, with a newRequest() method
// that returns the client.

protected $modelNamespace = '';

// deafult query string names for page and per_page fields
protected $perPageField = 'page_size';
protected $pageField = 'page';

// Should return raw responses and not models/resultsets
protected $raw = false;

// Should results be paginated by default.
protected $pagination = true;

// Amount of pagination results per page by default, leave blank if should not paginate
// Without pagination rate limits could be hit
protected $defaultPaginationRecords = '20';

// Max and Min pagination records per page, will vary by API server
protected $maxPaginationRecords = '100';
protected $minPaginationRecords = '1';

// If not paginated, how many queries should we allow per search, leave '' or 0
// for unlimited queries. This of course will eat up any rate limits
protected $maxQueries = '5';

// Most API's should include pagination data - this is the fields we should be looking
// in on the response to get htis information. We can use start names or dot notation,
// so for exmple 'current_page' or 'meta.current_page'
protected $resultsPageField = 'meta.current_page';
protected $resultsTotalPagesField = 'meta.last_page';
protected $resultsPageSizeField = 'meta.per_page';
protected $resultsTotalRecordsField = 'meta.total';

public static function __callStatic($method, $parameters)
{
return (new static)->$method(...$parameters);
Expand Down Expand Up @@ -69,7 +103,88 @@ public function setRequest($request)

public function newRequest()
{
$this->setRequest(new Client);
throw new NoClientSetException;
}

public function getPerPageField()
{
return $this->perPageField;
}

public function getPageField()
{
return $this->pageField;
}

public function getDefaultPaginationRecords()
{
if($this->defaultPaginationRecords == '')
{
return 20;
}
return $this->defaultPaginationRecords;
}

public function getMaxPaginationRecords()
{
if($this->maxPaginationRecords == '')
{
return 100;
}
return $this->maxPaginationRecords;
}

public function getMinPaginationRecords()
{
if($this->minPaginationRecords == '')
{
return 1;
}
return $this->minPaginationRecords;
}

public function getPagination()
{
return $this->pagination;
}

public function getRaw()
{
return $this->raw;
}

public function hasMaxQueryLimit()
{
if($this->maxQueries != '' && $this->maxQueries > 0)
{
return true;
}
return false;
}

public function getMaxQueries()
{
return $this->maxQueries;
}

public function getResultsPageField()
{
return $this->resultsPageField;
}

public function getResultsTotalPagesField()
{
return $this->resultsTotalPagesField;
}

public function getResultsPageSizeField()
{
return $this->resultsPageSizeField;
}

public function getResultsTotalRecordsField()
{
return $this->resultsTotalRecordsField;
}

}

0 comments on commit 650cb94

Please sign in to comment.