Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for new pagination #249

Merged
merged 3 commits into from
Aug 1, 2016
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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

* Added support for `original_transaction` to `Recurly_Transaction` [#238](https://github.com/recurly/recurly-client-php/pull/238)
* Added `Recurly_AccountBalance` [#239](https://github.com/recurly/recurly-client-php/pull/239)
* Print warnings when using a deprecated version of the API.
* Print warnings when using a deprecated version of the API. [#250](https://github.com/recurly/recurly-client-php/pull/250):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized this one didn't have a PR links so I just stuck it in here while rebasing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Good enough

* Added support new pagination options [#249](https://github.com/recurly/recurly-client-php/pull/249):
- `sort` accepts `created_at` or `updated_at`, defaults to `created_at`.
- `order` accepts `desc` or `asc`, defaults to `desc`.
- `begin_time` and `end_time` accepts an ISO 8601 date or date and time.
* Changed `Recurly_AddonList::get()` and `Recurly_NoteList::get()` to add `$params` as the second parameter so sort, order and date filtering can be passed in [#249](https://github.com/recurly/recurly-client-php/pull/249)

## Version 2.5.3 (July 5th, 2016)

Expand Down
4 changes: 2 additions & 2 deletions Tests/Recurly/Note_List_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
class Recurly_NoteListTest extends Recurly_TestCase
{
public function testGetNotes() {
$this->client->addResponse('GET', '/accounts/abcdef1234567890/notes', 'notes/index-200.xml');
$this->client->addResponse('GET', '/accounts/abcdef1234567890/notes?', 'notes/index-200.xml');

$notes = Recurly_NoteList::get('abcdef1234567890', $this->client);
$notes = Recurly_NoteList::get('abcdef1234567890', array(), $this->client);
$this->assertInstanceOf('Recurly_NoteList', $notes);
$this->assertEquals($notes->count(), 2);

Expand Down
5 changes: 3 additions & 2 deletions Tests/Recurly/Pager_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ protected function getNodeName() {
return 'mocks';
}

public function _loadFrom($uri, $params = null) {
parent::_loadFrom($uri, $params);
// Overridden to make it public.
public function _loadFrom($uri) {
parent::_loadFrom($uri);
}
}
Recurly_Resource::$class_map['mocks'] = 'Mock_Pager';
Expand Down
4 changes: 2 additions & 2 deletions lib/recurly/addon_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

class Recurly_AddonList extends Recurly_Pager
{
public static function get($planCode, $client = null)
public static function get($planCode, $params = null, $client = null)
{
$uri = Recurly_Client::PATH_PLANS . '/' . rawurlencode($planCode) . Recurly_Client::PATH_ADDONS;
$uri = self::_uriWithParams(Recurly_Client::PATH_PLANS . '/' . rawurlencode($planCode) . Recurly_Client::PATH_ADDONS, $params);
return new self($uri, $client);
}

Expand Down
9 changes: 3 additions & 6 deletions lib/recurly/note_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

class Recurly_NoteList extends Recurly_Pager
{
public static function get($accountCode, $client = null) {
return Recurly_Base::_get(Recurly_NoteList::uriForNotes($accountCode), $client);
}

protected static function uriForNotes($accountCode) {
return Recurly_Client::PATH_ACCOUNTS . '/' . rawurlencode($accountCode) . Recurly_Client::PATH_NOTES;
public static function get($accountCode, $params = null, $client = null) {
$uri = self::_uriWithParams(Recurly_Client::PATH_ACCOUNTS . '/' . rawurlencode($accountCode) . Recurly_Client::PATH_NOTES, $params);
return new self($uri, $client);
}

protected function getNodeName() {
Expand Down
5 changes: 2 additions & 3 deletions lib/recurly/pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ public function valid() {
/**
* Load another page of results into this pager.
*/
protected function _loadFrom($uri, $params = null) {
protected function _loadFrom($uri) {
if (empty($uri)) {
return;
}

$uri = Recurly_Base::_uriWithParams($uri, $params);
$response = $this->_client->request(Recurly_Client::GET, $uri);
$response->assertValidResponse();

Expand All @@ -101,9 +100,9 @@ protected function _loadFrom($uri, $params = null) {
}

protected function _afterParseResponse($response, $uri) {
$this->_href = $uri;
$this->_loadRecordCount($response);
$this->_loadLinks($response);
$this->_href = isset($this->_links['start']) ? $this->_links['start'] : $uri;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a bug where we were rewinding to the second page rather than the first.

}

protected static function _setState($params, $state) {
Expand Down