Permalink
Browse files

Remove filters from paging with next_page_uri

The next_page_uri includes filters, so you don't need to continue adding them
to subsequent API requests. If the next_page_uri is being used, just pass an
empty array for the filters.

Also add a test for the correct behavior in this case, based on the real API
response.
  • Loading branch information...
1 parent ab26255 commit f40f3314aabf9960617f6f454066f46e82b0eb9a Kevin Burke committed Jul 23, 2012
Showing with 37 additions and 2 deletions.
  1. +1 −1 Services/Twilio/ListResource.php
  2. +36 −1 tests/TwilioTest.php
@@ -107,7 +107,7 @@ public function getPage(
) {
$list_name = $this->getResourceName();
if ($deep_paging_uri !== null) {
- $page = $this->client->retrieveData($deep_paging_uri, $filters, true);
+ $page = $this->client->retrieveData($deep_paging_uri, array(), true);
} else {
$page = $this->client->retrieveData($this->uri, array(
'Page' => $page,
View
@@ -379,7 +379,42 @@ function testDeepPagingUsesAfterSid() {
}
function testIteratorWithFiltersPagesCorrectly() {
+ $http = m::mock(new Services_Twilio_TinyHttp);
+ $recordingsBase = '/2010-04-01/Accounts/AC123/Recordings.json';
+ $firstPageUri = $recordingsBase . '?Page=0&PageSize=1&DateCreated%3E=2011-01-01';
+ $secondPageUri = $recordingsBase . '?DateCreated%3E=2011-01-01&Page=1&PageSize=1';
+ $thirdPageUri = $recordingsBase . '?DateCreated%3E=2011-01-01&Page=2&PageSize=1';
+ $http->shouldReceive('get')->once()
+ ->with($firstPageUri)
+ ->andReturn(array(200, array('Content-Type' => 'application/json'),
+ json_encode(array(
+ 'next_page_uri' => $secondPageUri,
+ 'recordings' => array(array(
+ 'sid' => 'RE123',
+ 'duration' => 7,
+ ))
+ ))
+ ));
+ $http->shouldReceive('get')->once()
+ ->with($secondPageUri)
+ ->andReturn(array(200, array('Content-Type' => 'application/json'),
+ json_encode(array(
+ 'next_page_uri' => $thirdPageUri,
+ 'recordings' => array(array(
+ 'sid' => 'RE123',
+ 'duration' => 7,
+ ))
+ ))
+ ));
+ $http->shouldReceive('get')->once()
+ ->with($thirdPageUri)
+ ->andReturn(array(400, array('Content-Type' => 'application/json'),
+ '{"status":400,"message":"foo", "code": "20006"}'
+ ));
+ $client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
+ foreach ($client->account->recordings->getIterator(0, 1, array('DateCreated>' => '2011-01-01')) as $recording) {
+ $this->assertSame($recording->duration, 7);
+ }
}
-
}

0 comments on commit f40f331

Please sign in to comment.