Skip to content

add paging functions for accounts list view #40

Closed
kevinburke opened this Issue Feb 1, 2012 · 9 comments

3 participants

@kevinburke

No description provided.

@kevinburke kevinburke was assigned Feb 1, 2012
@kevinburke

reported by thomas wilsher

@caseysoftware

Any hints on what this could/should look like?

@kevinburke

Hmm. I was looking at this with Thomas and we couldn't figure out how to page through account views. This appears to work though:

$client = new Services_Twilio('AC123', '123');
$accountList = $client->accounts->getIterator(0, 50, array());
foreach($accountList as $account) {
    print $account->sid;
}

However I'm not sure if the library supports getting the total number of accounts, or how you would be expected to page through a list of all of your accounts (if you wanted to do such a thing). For example how do I know how many records to page through? How do I know when I'm done paging?

@caseysoftware

We get all the data back from the List Resource, so this one becomes "so now how do we navigate it?" In this snapshot:
https://www.twilio.com/docs/api/rest/account#list-get-example-1 here are the values:

page="0"
numpages="1"
pagesize="50"
total="1"
start="0"
end="1"
uri="/2010-04-01/Accounts"
firstpageuri="/2010-04-01/Accounts?Page=0&PageSize=50"
previouspageuri=""
nextpageuri=""
lastpageuri="/2010-04-01/Accounts?Page=0&PageSize=50"

@kevinburke

Right, but note that most of those of those are dependent on the parameters you pass to the list resource - so if you pass a different page size, most of the values will change.

We could do:

$client->accounts->total gets the total,

and then the getIterator should define num_pages, page, start, end, and page_size. I'm not sure that it makes sense to implement the rest of the methods.

@luciferous

If I'm understanding correctly, you want to page through all of the resources in a list resource, you can iterate over the ListResource:

$client = new Services_Twilio('AC123', '123');
foreach($client->accounts as $account) {
    print $account->sid;
}
@caseysoftware

If you use getIterator now, it gets the first page, iterates from 0 to $pagesize and then gets the next page automatically. There doesn't seem to be a way to explicitly tell it to "get the next page" or "stay on this page." While not a huge problem, it may not give the intended results.

Example:

$accountList = $client->accounts->getIterator(0, 50, array());
foreach($client->accounts as $account) {
print $account->sid;
}

and

$accountList = $client->accounts->getIterator(0, 10, array());
foreach($client->accounts as $account) {
print $account->sid;
}

give the same results but the second makes 5 requests while the first makes one.

@luciferous

Why not use getPage instead? getIterator is lower level, specifically for implementing the IteratorAggregate interface, it's used explicitly to iterate over all the instances in the list.

@kevinburke

going to close this as a non-issue - note that you can now call

count($client->account->calls)

and get the total number of calls.

@kevinburke kevinburke closed this Nov 26, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.