{"action":"created","issue":{"url":"https://api.github.com/repos/ably/ably-js/issues/28","labels_url":"https://api.github.com/repos/ably/ably-js/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/ably/ably-js/issues/28/comments","events_url":"https://api.github.com/repos/ably/ably-js/issues/28/events","html_url":"https://github.com/ably/ably-js/issues/28","id":67592535,"number":28,"title":"PaginatedResource API change ","user":{"login":"mattheworiordan","id":43789,"avatar_url":"https://avatars.githubusercontent.com/u/43789?v=3","gravatar_id":"","url":"https://api.github.com/users/mattheworiordan","html_url":"https://github.com/mattheworiordan","followers_url":"https://api.github.com/users/mattheworiordan/followers","following_url":"https://api.github.com/users/mattheworiordan/following{/other_user}","gists_url":"https://api.github.com/users/mattheworiordan/gists{/gist_id}","starred_url":"https://api.github.com/users/mattheworiordan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattheworiordan/subscriptions","organizations_url":"https://api.github.com/users/mattheworiordan/orgs","repos_url":"https://api.github.com/users/mattheworiordan/repos","events_url":"https://api.github.com/users/mattheworiordan/events{/privacy}","received_events_url":"https://api.github.com/users/mattheworiordan/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ably/ably-js/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-04-10T13:14:44Z","updated_at":"2015-04-10T15:46:45Z","closed_at":null,"body":"Whilst our client APIs are consistent, the `PaginatedResource` API has unfortunately diverged somewhat.  Following some discussions, we have decided to implement the `PaginatedResource` so that it is iterator-like, provides an accessor / method to the items it holds to encourage understanding of the pages of results concept to developers i.e. each next page is a new request for new items, and provides similar synchronous and asynchronous interfaces.\r\n\r\nThe proposed interface demonstrated in code is therefore as follows:\r\n\r\n### Async Javascript\r\n\r\n```javascript\r\nfunction displayPages(currentPage) {\r\n    for (let message in currentPage.items) {\r\n      console.log(message.name);\r\n    }\r\n    if (let next = currentPage.next) {\r\n      next(function(err, nextPage) { displayPages(nextPage); });\r\n    }\r\n}\r\n\r\nchannel.history(function (err, currentPage) {\r\n  currentPage.isFirst(); // true\r\n  currentPage.isLast(); // false\r\n  displayPages(currentPage);\r\n}\r\n```\r\n\r\n### Sync Ruby\r\n\r\n```ruby\r\ncurrent_page = channel.history\r\n\r\ncurrent_page.first? # true\r\ncurrent_page.last? # false\r\ncurrent_page.has_next? # true\r\n\r\ndo \r\n  current_page.items.each { |message| puts message.name }\r\n  current_page = current_page.next\r\nuntil current_page.last?\r\n\r\ncurrent_page.next # => nil\r\n```"},"comment":{"url":"https://api.github.com/repos/ably/ably-js/issues/comments/91597814","html_url":"https://github.com/ably/ably-js/issues/28#issuecomment-91597814","issue_url":"https://api.github.com/repos/ably/ably-js/issues/28","id":91597814,"user":{"login":"paddybyers","id":1137574,"avatar_url":"https://avatars.githubusercontent.com/u/1137574?v=3","gravatar_id":"","url":"https://api.github.com/users/paddybyers","html_url":"https://github.com/paddybyers","followers_url":"https://api.github.com/users/paddybyers/followers","following_url":"https://api.github.com/users/paddybyers/following{/other_user}","gists_url":"https://api.github.com/users/paddybyers/gists{/gist_id}","starred_url":"https://api.github.com/users/paddybyers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paddybyers/subscriptions","organizations_url":"https://api.github.com/users/paddybyers/orgs","repos_url":"https://api.github.com/users/paddybyers/repos","events_url":"https://api.github.com/users/paddybyers/events{/privacy}","received_events_url":"https://api.github.com/users/paddybyers/received_events","type":"User","site_admin":false},"created_at":"2015-04-10T15:46:44Z","updated_at":"2015-04-10T15:46:44Z","body":"> if reference to the current page is needed for the purpose of re-running the iteration later on from particular point\r\n\r\nWhen a query is performed, various of the params are typically unspecified, but are then resolved to specific values when the query is evaluated; eg `start`, `end` times are resolved to specific times. The `current` params for a page contain those resolved param values, so that page of results can be repeatably fetched. That isn't possible just by re-running the original query with the original params."}}