constantcontact / php-sdk

Constant Contact PHP SDK for v2 API
Other
105 stars 125 forks source link

An iterator for paginated ResultSet #59

Open xpavp03 opened 10 years ago

xpavp03 commented 10 years ago

How cool it would be to write this:

$service = new \Ctct\Services\ListService($apiKey);
$resultSet = $service->getContactsFromList($accessToken, $listId, $params);
$iterator = new \Ctct\Util\ResultSetIterator($resultSet);
foreach ($iterator as $contact) {
  print "First name: " . $contact->first_name . "<br>";
}

The iterator would traverse all items, fetching remaining results via the "next" parameter in the background if needed.

This should work for all ResultSets, not only for sets of Contacts.

What do you think? Should be easy to implement. Do you want me to?

WoogieNoogie commented 9 years ago

This would definitely be an interesting way to handle it. I'd love to see what you come up with if you have the time - we wouldn't be able to work on this on our end in the near future.