{"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":10,"created_at":"2015-04-10T13:14:44Z","updated_at":"2015-04-13T09:48:15Z","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/92294821","html_url":"https://github.com/ably/ably-js/issues/28#issuecomment-92294821","issue_url":"https://api.github.com/repos/ably/ably-js/issues/28","id":92294821,"user":{"login":"thevixac","id":737799,"avatar_url":"https://avatars.githubusercontent.com/u/737799?v=3","gravatar_id":"","url":"https://api.github.com/users/thevixac","html_url":"https://github.com/thevixac","followers_url":"https://api.github.com/users/thevixac/followers","following_url":"https://api.github.com/users/thevixac/following{/other_user}","gists_url":"https://api.github.com/users/thevixac/gists{/gist_id}","starred_url":"https://api.github.com/users/thevixac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thevixac/subscriptions","organizations_url":"https://api.github.com/users/thevixac/orgs","repos_url":"https://api.github.com/users/thevixac/repos","events_url":"https://api.github.com/users/thevixac/events{/privacy}","received_events_url":"https://api.github.com/users/thevixac/received_events","type":"User","site_admin":false},"created_at":"2015-04-13T09:48:15Z","updated_at":"2015-04-13T09:48:15Z","body":"I think the iOS pagination is what you want. You get a ARTPaginatedResult back, \r\n which is essentially an iterator. You can ask it for the first, current, or next page.\r\nEach time you ask for the next page, you get a new ARTPaginatedResult object. ARTPaginatedResult is used for all paginated queries regardless of payload type.\r\n\r\n    [channel historyWithParams:@{@\"limit\" : @\"2\",\r\n       @\"direction\" : @\"backwards\"} cb:^(ARTStatus status, id<ARTPaginatedResult> result) {\r\n           XCTAssertEqual(status, ARTStatusOk);\r\n           XCTAssertTrue([result hasFirst]);\r\n           XCTAssertTrue([result hasNext]);\r\n           NSArray * page = [result current];\r\n           XCTAssertEqual([page count], 2);\r\n           ARTMessage * firstMessage = [page objectAtIndex:0];\r\n           ARTMessage * secondMessage =[page objectAtIndex:1];\r\n           XCTAssertEqualObjects(@\"testString4\", [firstMessage content]);\r\n           XCTAssertEqualObjects(@\"testString3\", [secondMessage content]);\r\n           [result getNext:^(ARTStatus status, id<ARTPaginatedResult> result2) {\r\n               XCTAssertEqual(status, ARTStatusOk);\r\n               XCTAssertTrue([result2 hasFirst]);\r\n               NSArray * page = [result2 current];\r\n               XCTAssertEqual([page count], 2);\r\n               ARTMessage * firstMessage = [page objectAtIndex:0];\r\n               ARTMessage * secondMessage =[page objectAtIndex:1];\r\n\r\n               XCTAssertEqualObjects(@\"testString2\", [firstMessage content]);\r\n               XCTAssertEqualObjects(@\"testString1\", [secondMessage content]);\r\n\r\n               [result2 getNext:^(ARTStatus status, id<ARTPaginatedResult> result3) {\r\n                          //do something with result3\r\n               }];\r\n           }];\r\n       }];"}}