{"action":"created","comment":{"url":"https://api.github.com/repos/ably/ably-php/pulls/comments/27580085","id":27580085,"diff_hunk":"@@ -0,0 +1,100 @@\n+<?php\n+\n+class PaginatedResource extends ArrayObject {\n+\n+    private $ably;\n+    private $domain;\n+    private $path;\n+    private $paginationHeaders = false;\n+\n+    /*\n+     * Constructor\n+     */\n+    public function __construct( AblyRest $ably, $domain, $path, $params = array() ) {\n+        parent::__construct();\n+\n+        $this->ably = $ably;\n+        $this->domain = $domain;\n+        $this->path = $path;\n+\n+        $withHeaders = true;\n+        $response = $this->ably->get( $domain, $path, $this->ably->auth_headers(), $params, $withHeaders );\n+\n+        if (isset($response['body'])) {\n+            $this->exchangeArray( $response['body'] );\n+            $this->parseHeaders( $response['headers'] );\n+        }\n+    }\n+\n+\n+    /*\n+     * Public methods\n+     */\n+    public function isPaginated() {\n+        return is_array($this->paginationHeaders) && !empty($this->paginationHeaders);\n+    }\n+\n+    public function isFirstPage() {\n+        if (!$this->isPaginated() ) {\n+            return true;\n+        }\n+        \n+        if ( isset($this->paginationHeaders['first']) && isset($this->paginationHeaders['current'])\n+            && $this->paginationHeaders['first'] == $this->paginationHeaders['current'] ) {\n+            return true;\n+        }\n+\n+        return false;\n+    }\n+\n+    public function isLastPage() {\n+        if (!$this->isPaginated() || !isset($this->paginationHeaders['next']) ) {\n+            return true;\n+        } else {\n+            return false;\n+        }\n+    }\n+\n+    public function getFirstPage() {\n+        if ($this->isPaginated() && !empty($this->paginationHeaders['first'])) {\n+            return new PaginatedResource( $this->ably, $this->domain, $this->paginationHeaders['first'], array());\n+        } else {\n+            return null;\n+        }\n+    }\n+\n+    public function getNextPage() {\n+        if ($this->isPaginated() && !empty($this->paginationHeaders['next'])) {\n+            return new PaginatedResource( $this->ably, $this->domain, $this->paginationHeaders['next'], array());\n+        } else {\n+            return null;\n+        }\n+    }\n+\n+\n+    /*\n+     * Private methods\n+     */\n+\n+    private function parseHeaders($headers) {\n+\n+        $path = preg_replace('/\\/[^\\/]*$/', '/', $this->path);\n+\n+        preg_match_all('/Link: *\\<([^\\>]*)\\>; *rel=\"([^\"]*)\"/', $headers, $matches, PREG_SET_ORDER);\n+\n+        if (!$matches) return;\n+\n+        $this->paginationHeaders = array();\n+\n+        foreach ($matches as $m) {\n+            $link = $m[1];\n+            $rel =  $m[2];\n+\n+            if (substr($link, 0, 2) != './') {\n+                throw new Exception(\"Only relative URLs supported in pagination\", 1);","path":"lib/ably/PaginatedResource.php","position":94,"original_position":94,"commit_id":"414f8b88c9f6927665f1cde89bb5c91e808324d9","original_commit_id":"414f8b88c9f6927665f1cde89bb5c91e808324d9","user":{"login":"kouno","id":209665,"avatar_url":"https://avatars.githubusercontent.com/u/209665?v=3","gravatar_id":"","url":"https://api.github.com/users/kouno","html_url":"https://github.com/kouno","followers_url":"https://api.github.com/users/kouno/followers","following_url":"https://api.github.com/users/kouno/following{/other_user}","gists_url":"https://api.github.com/users/kouno/gists{/gist_id}","starred_url":"https://api.github.com/users/kouno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kouno/subscriptions","organizations_url":"https://api.github.com/users/kouno/orgs","repos_url":"https://api.github.com/users/kouno/repos","events_url":"https://api.github.com/users/kouno/events{/privacy}","received_events_url":"https://api.github.com/users/kouno/received_events","type":"User","site_admin":false},"body":"Also you should probably create our own exception too while you are at it :).","created_at":"2015-04-01T15:29:08Z","updated_at":"2015-04-01T15:29:08Z","html_url":"https://github.com/ably/ably-php/pull/2#discussion_r27580085","pull_request_url":"https://api.github.com/repos/ably/ably-php/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/ably/ably-php/pulls/comments/27580085"},"html":{"href":"https://github.com/ably/ably-php/pull/2#discussion_r27580085"},"pull_request":{"href":"https://api.github.com/repos/ably/ably-php/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/ably/ably-php/pulls/2","id":32416078,"html_url":"https://github.com/ably/ably-php/pull/2","diff_url":"https://github.com/ably/ably-php/pull/2.diff","patch_url":"https://github.com/ably/ably-php/pull/2.patch","issue_url":"https://api.github.com/repos/ably/ably-php/issues/2","number":2,"state":"open","locked":false,"title":"Presence tests and channel pagination","user":{"login":"bladeSk","id":4263742,"avatar_url":"https://avatars.githubusercontent.com/u/4263742?v=3","gravatar_id":"","url":"https://api.github.com/users/bladeSk","html_url":"https://github.com/bladeSk","followers_url":"https://api.github.com/users/bladeSk/followers","following_url":"https://api.github.com/users/bladeSk/following{/other_user}","gists_url":"https://api.github.com/users/bladeSk/gists{/gist_id}","starred_url":"https://api.github.com/users/bladeSk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bladeSk/subscriptions","organizations_url":"https://api.github.com/users/bladeSk/orgs","repos_url":"https://api.github.com/users/bladeSk/repos","events_url":"https://api.github.com/users/bladeSk/events{/privacy}","received_events_url":"https://api.github.com/users/bladeSk/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-04-01T12:57:38Z","updated_at":"2015-04-01T15:29:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3e60f063ec82ad79df4ba0fe15ad27f6e145034a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ably/ably-php/pulls/2/commits","review_comments_url":"https://api.github.com/repos/ably/ably-php/pulls/2/comments","review_comment_url":"https://api.github.com/repos/ably/ably-php/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ably/ably-php/issues/2/comments","statuses_url":"https://api.github.com/repos/ably/ably-php/statuses/414f8b88c9f6927665f1cde89bb5c91e808324d9","head":{"label":"bladeSk:master","ref":"master","sha":"414f8b88c9f6927665f1cde89bb5c91e808324d9","user":{"login":"bladeSk","id":4263742,"avatar_url":"https://avatars.githubusercontent.com/u/4263742?v=3","gravatar_id":"","url":"https://api.github.com/users/bladeSk","html_url":"https://github.com/bladeSk","followers_url":"https://api.github.com/users/bladeSk/followers","following_url":"https://api.github.com/users/bladeSk/following{/other_user}","gists_url":"https://api.github.com/users/bladeSk/gists{/gist_id}","starred_url":"https://api.github.com/users/bladeSk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bladeSk/subscriptions","organizations_url":"https://api.github.com/users/bladeSk/orgs","repos_url":"https://api.github.com/users/bladeSk/repos","events_url":"https://api.github.com/users/bladeSk/events{/privacy}","received_events_url":"https://api.github.com/users/bladeSk/received_events","type":"User","site_admin":false},"repo":{"id":33172870,"name":"ably-php","full_name":"bladeSk/ably-php","owner":{"login":"bladeSk","id":4263742,"avatar_url":"https://avatars.githubusercontent.com/u/4263742?v=3","gravatar_id":"","url":"https://api.github.com/users/bladeSk","html_url":"https://github.com/bladeSk","followers_url":"https://api.github.com/users/bladeSk/followers","following_url":"https://api.github.com/users/bladeSk/following{/other_user}","gists_url":"https://api.github.com/users/bladeSk/gists{/gist_id}","starred_url":"https://api.github.com/users/bladeSk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bladeSk/subscriptions","organizations_url":"https://api.github.com/users/bladeSk/orgs","repos_url":"https://api.github.com/users/bladeSk/repos","events_url":"https://api.github.com/users/bladeSk/events{/privacy}","received_events_url":"https://api.github.com/users/bladeSk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bladeSk/ably-php","description":"Ably real-time messaging. REST client library for PHP","fork":true,"url":"https://api.github.com/repos/bladeSk/ably-php","forks_url":"https://api.github.com/repos/bladeSk/ably-php/forks","keys_url":"https://api.github.com/repos/bladeSk/ably-php/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bladeSk/ably-php/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bladeSk/ably-php/teams","hooks_url":"https://api.github.com/repos/bladeSk/ably-php/hooks","issue_events_url":"https://api.github.com/repos/bladeSk/ably-php/issues/events{/number}","events_url":"https://api.github.com/repos/bladeSk/ably-php/events","assignees_url":"https://api.github.com/repos/bladeSk/ably-php/assignees{/user}","branches_url":"https://api.github.com/repos/bladeSk/ably-php/branches{/branch}","tags_url":"https://api.github.com/repos/bladeSk/ably-php/tags","blobs_url":"https://api.github.com/repos/bladeSk/ably-php/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bladeSk/ably-php/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bladeSk/ably-php/git/refs{/sha}","trees_url":"https://api.github.com/repos/bladeSk/ably-php/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bladeSk/ably-php/statuses/{sha}","languages_url":"https://api.github.com/repos/bladeSk/ably-php/languages","stargazers_url":"https://api.github.com/repos/bladeSk/ably-php/stargazers","contributors_url":"https://api.github.com/repos/bladeSk/ably-php/contributors","subscribers_url":"https://api.github.com/repos/bladeSk/ably-php/subscribers","subscription_url":"https://api.github.com/repos/bladeSk/ably-php/subscription","commits_url":"https://api.github.com/repos/bladeSk/ably-php/commits{/sha}","git_commits_url":"https://api.github.com/repos/bladeSk/ably-php/git/commits{/sha}","comments_url":"https://api.github.com/repos/bladeSk/ably-php/comments{/number}","issue_comment_url":"https://api.github.com/repos/bladeSk/ably-php/issues/comments{/number}","contents_url":"https://api.github.com/repos/bladeSk/ably-php/contents/{+path}","compare_url":"https://api.github.com/repos/bladeSk/ably-php/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bladeSk/ably-php/merges","archive_url":"https://api.github.com/repos/bladeSk/ably-php/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bladeSk/ably-php/downloads","issues_url":"https://api.github.com/repos/bladeSk/ably-php/issues{/number}","pulls_url":"https://api.github.com/repos/bladeSk/ably-php/pulls{/number}","milestones_url":"https://api.github.com/repos/bladeSk/ably-php/milestones{/number}","notifications_url":"https://api.github.com/repos/bladeSk/ably-php/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bladeSk/ably-php/labels{/name}","releases_url":"https://api.github.com/repos/bladeSk/ably-php/releases{/id}","created_at":"2015-03-31T08:04:03Z","updated_at":"2015-04-01T12:52:51Z","pushed_at":"2015-04-01T12:52:51Z","git_url":"git://github.com/bladeSk/ably-php.git","ssh_url":"git@github.com:bladeSk/ably-php.git","clone_url":"https://github.com/bladeSk/ably-php.git","svn_url":"https://github.com/bladeSk/ably-php","homepage":"","size":618,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ably:master","ref":"master","sha":"67a5bcf792d4d988099b6484a3bea621cc7122fc","user":{"login":"ably","id":1859245,"avatar_url":"https://avatars.githubusercontent.com/u/1859245?v=3","gravatar_id":"","url":"https://api.github.com/users/ably","html_url":"https://github.com/ably","followers_url":"https://api.github.com/users/ably/followers","following_url":"https://api.github.com/users/ably/following{/other_user}","gists_url":"https://api.github.com/users/ably/gists{/gist_id}","starred_url":"https://api.github.com/users/ably/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ably/subscriptions","organizations_url":"https://api.github.com/users/ably/orgs","repos_url":"https://api.github.com/users/ably/repos","events_url":"https://api.github.com/users/ably/events{/privacy}","received_events_url":"https://api.github.com/users/ably/received_events","type":"Organization","site_admin":false},"repo":{"id":7289345,"name":"ably-php","full_name":"ably/ably-php","owner":{"login":"ably","id":1859245,"avatar_url":"https://avatars.githubusercontent.com/u/1859245?v=3","gravatar_id":"","url":"https://api.github.com/users/ably","html_url":"https://github.com/ably","followers_url":"https://api.github.com/users/ably/followers","following_url":"https://api.github.com/users/ably/following{/other_user}","gists_url":"https://api.github.com/users/ably/gists{/gist_id}","starred_url":"https://api.github.com/users/ably/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ably/subscriptions","organizations_url":"https://api.github.com/users/ably/orgs","repos_url":"https://api.github.com/users/ably/repos","events_url":"https://api.github.com/users/ably/events{/privacy}","received_events_url":"https://api.github.com/users/ably/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ably/ably-php","description":"Ably real-time messaging. REST client library for PHP","fork":false,"url":"https://api.github.com/repos/ably/ably-php","forks_url":"https://api.github.com/repos/ably/ably-php/forks","keys_url":"https://api.github.com/repos/ably/ably-php/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ably/ably-php/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ably/ably-php/teams","hooks_url":"https://api.github.com/repos/ably/ably-php/hooks","issue_events_url":"https://api.github.com/repos/ably/ably-php/issues/events{/number}","events_url":"https://api.github.com/repos/ably/ably-php/events","assignees_url":"https://api.github.com/repos/ably/ably-php/assignees{/user}","branches_url":"https://api.github.com/repos/ably/ably-php/branches{/branch}","tags_url":"https://api.github.com/repos/ably/ably-php/tags","blobs_url":"https://api.github.com/repos/ably/ably-php/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ably/ably-php/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ably/ably-php/git/refs{/sha}","trees_url":"https://api.github.com/repos/ably/ably-php/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ably/ably-php/statuses/{sha}","languages_url":"https://api.github.com/repos/ably/ably-php/languages","stargazers_url":"https://api.github.com/repos/ably/ably-php/stargazers","contributors_url":"https://api.github.com/repos/ably/ably-php/contributors","subscribers_url":"https://api.github.com/repos/ably/ably-php/subscribers","subscription_url":"https://api.github.com/repos/ably/ably-php/subscription","commits_url":"https://api.github.com/repos/ably/ably-php/commits{/sha}","git_commits_url":"https://api.github.com/repos/ably/ably-php/git/commits{/sha}","comments_url":"https://api.github.com/repos/ably/ably-php/comments{/number}","issue_comment_url":"https://api.github.com/repos/ably/ably-php/issues/comments{/number}","contents_url":"https://api.github.com/repos/ably/ably-php/contents/{+path}","compare_url":"https://api.github.com/repos/ably/ably-php/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ably/ably-php/merges","archive_url":"https://api.github.com/repos/ably/ably-php/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ably/ably-php/downloads","issues_url":"https://api.github.com/repos/ably/ably-php/issues{/number}","pulls_url":"https://api.github.com/repos/ably/ably-php/pulls{/number}","milestones_url":"https://api.github.com/repos/ably/ably-php/milestones{/number}","notifications_url":"https://api.github.com/repos/ably/ably-php/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ably/ably-php/labels{/name}","releases_url":"https://api.github.com/repos/ably/ably-php/releases{/id}","created_at":"2012-12-22T18:59:01Z","updated_at":"2015-03-22T07:51:31Z","pushed_at":"2015-04-01T12:57:38Z","git_url":"git://github.com/ably/ably-php.git","ssh_url":"git@github.com:ably/ably-php.git","clone_url":"https://github.com/ably/ably-php.git","svn_url":"https://github.com/ably/ably-php","homepage":"","size":618,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":2,"forks":3,"open_issues":2,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ably/ably-php/pulls/2"},"html":{"href":"https://github.com/ably/ably-php/pull/2"},"issue":{"href":"https://api.github.com/repos/ably/ably-php/issues/2"},"comments":{"href":"https://api.github.com/repos/ably/ably-php/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/ably/ably-php/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/ably/ably-php/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ably/ably-php/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/ably/ably-php/statuses/414f8b88c9f6927665f1cde89bb5c91e808324d9"}}}}