{"action":"created","comment":{"url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/pulls/comments/39389491","id":39389491,"diff_hunk":"@@ -0,0 +1,174 @@\n+<?php\n+set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/..'));\n+\n+class Proxy {\n+    /** @var bool */\n+    private $_haveExtensionCurl = false;\n+    /** @var bool */\n+    private $_haveExtensionHttp = false;\n+    /** @var string */\n+    private $_endpointUrl;\n+    /** @var string[] */\n+    private $_headers;\n+    /** @var string */\n+    private $_body;\n+    /** @var float|null */\n+    private $_timeoutSeconds = null;\n+\n+    public function __construct() {\n+        $this->_haveExtensionCurl = extension_loaded('curl');\n+        $this->_haveExtensionHttp = extension_loaded('http');\n+\n+        if (!$this->_haveExtensionCurl && !$this->_haveExtensionHttp) {\n+            throw new RuntimeException('One of these PHP extensions is required: \"http\" (AKA pecl_http) or \"curl\".');\n+        }\n+    }\n+\n+    /** @return string */\n+    public function getEndpointUrl() {\n+        return $this->_endpointUrl;\n+    }\n+\n+    /**\n+     * @param string $endpointUrl\n+     * @return $this\n+     */\n+    public function setEndpointUrl($endpointUrl) {\n+        $this->_endpointUrl = $endpointUrl;\n+        return $this;\n+    }\n+\n+    /** @return string[] */\n+    public function getHeaders() {\n+        return $this->_headers;\n+    }\n+\n+    /**\n+     * @param string[] $headers\n+     * @return $this\n+     */\n+    public function setHeaders($headers) {\n+        if (!is_array($headers)) {\n+            $headers = [$headers];\n+        }\n+\n+        $this->_headers = $headers;\n+        return $this;\n+    }\n+\n+    /** @return string */\n+    public function getBody() {\n+        return $this->_body;\n+    }\n+\n+    /**\n+     * @param string $body\n+     * @return $this\n+     */\n+    public function setBody($body) {\n+        $this->_body = $body;\n+        return $this;\n+    }\n+\n+    /** @return float|null */\n+    public function getTimeoutSeconds() {\n+        return $this->_timeoutSeconds;\n+    }\n+\n+    /**\n+     * @param float|null $timeoutSeconds\n+     * @return $this\n+     */\n+    public function setTimeoutSeconds($timeoutSeconds) {\n+        if ($timeoutSeconds != null) {\n+            $this->_timeoutSeconds = floatval($timeoutSeconds);\n+        } else {\n+            $this->_timeoutSeconds = null;\n+        }\n+        return $this;\n+    }\n+\n+    /**\n+     * @return bool\n+     */\n+    public function send() {\n+        $status = false;\n+        $responseCode = null;\n+        $responseText = null;\n+\n+        $headers = $this->getHeaders();\n+\n+        // Remove \"Host\" header; it will be generated by client\n+        if (array_key_exists('Host', $headers)) {\n+            unset($headers['Host']);\n+        }\n+\n+        if ($this->_haveExtensionHttp) {\n+            $request = (new http\\Client\\Request(\n+                'POST',\n+                $this->getEndpointUrl(),\n+                $headers,\n+                (new http\\Message())\n+                    ->getBody()\n+                    ->append($this->getBody())\n+            ));\n+\n+            $timeoutSeconds = $this->getTimeoutSeconds();\n+            if ($timeoutSeconds != null) {\n+                $request->setOptions([\n+                    'timeout' => $timeoutSeconds\n+                ]);\n+            }\n+\n+            $response = (new http\\Client)\n+                ->enqueue($request)\n+                ->send()\n+                ->getResponse($request);\n+\n+            $responseCode = $response->getResponseCode();\n+            $responseText = $responseCode;\n+        } elseif (extension_loaded('curl')) {\n+            $client = curl_init($this->getEndpointUrl());\n+\n+            $headerStrings = [];\n+            foreach ($headers as $headerKey => $headerValue) {\n+                $headerStrings[] = $headerKey . ': ' . $headerValue;\n+            }\n+\n+            $curlOptions = [\n+                CURLOPT_POST => true,\n+                CURLOPT_NOSIGNAL => true, // required for timeouts to work properly\n+                CURLOPT_HTTPHEADER => $headerStrings,\n+                CURLOPT_USERAGENT => 'Caliper (PHP curl extension)',\n+                CURLOPT_HEADER => true, // required to return response text\n+                CURLOPT_RETURNTRANSFER => true, // required to return response text\n+                CURLOPT_POSTFIELDS => $this->getBody(),\n+            ];\n+\n+            $timeoutSeconds = $this->getTimeoutSeconds();\n+            if ($timeoutSeconds != null) {\n+                $curlOptions[CURLOPT_TIMEOUT_MS] = intval($timeoutSeconds * 1000);\n+            }\n+\n+            curl_setopt_array($client, $curlOptions);\n+\n+            $responseText = curl_exec($client);\n+            $responseInfo = curl_getinfo($client);\n+            curl_close($client);\n+\n+            if ($responseText) {\n+                $responseCode = $responseInfo['http_code'];\n+            } else {\n+                $responseCode = null;\n+            }\n+        }\n+\n+        if ($responseCode != 200) {\n+            throw new RuntimeException('Failure: HTTP error: ' . $responseText);","path":"lib/Viadutoo/Proxy.php","position":167,"original_position":167,"commit_id":"cb6ecaf3910474eb112eb7016f1f6c0d5fa95a80","original_commit_id":"cb6ecaf3910474eb112eb7016f1f6c0d5fa95a80","user":{"login":"lsloan","id":20786,"avatar_url":"https://avatars.githubusercontent.com/u/20786?v=3","gravatar_id":"","url":"https://api.github.com/users/lsloan","html_url":"https://github.com/lsloan","followers_url":"https://api.github.com/users/lsloan/followers","following_url":"https://api.github.com/users/lsloan/following{/other_user}","gists_url":"https://api.github.com/users/lsloan/gists{/gist_id}","starred_url":"https://api.github.com/users/lsloan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lsloan/subscriptions","organizations_url":"https://api.github.com/users/lsloan/orgs","repos_url":"https://api.github.com/users/lsloan/repos","events_url":"https://api.github.com/users/lsloan/events{/privacy}","received_events_url":"https://api.github.com/users/lsloan/received_events","type":"User","site_admin":false},"body":"As I'm working on the DB part now, I've coded the sample application to test the results from this method.  If it fails, then it calls the DB storage method.  I'll have this method call the storage method directly, but I'll make it an option (set on by default).  It's a good idea to let the application have an option of doing something with the data before storing it.","created_at":"2015-09-14T12:54:43Z","updated_at":"2015-09-14T12:54:43Z","html_url":"https://github.com/tl-its-umich-edu/viadutoo/pull/1#discussion_r39389491","pull_request_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/pulls/comments/39389491"},"html":{"href":"https://github.com/tl-its-umich-edu/viadutoo/pull/1#discussion_r39389491"},"pull_request":{"href":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/pulls/1","id":44599992,"html_url":"https://github.com/tl-its-umich-edu/viadutoo/pull/1","diff_url":"https://github.com/tl-its-umich-edu/viadutoo/pull/1.diff","patch_url":"https://github.com/tl-its-umich-edu/viadutoo/pull/1.patch","issue_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/issues/1","number":1,"state":"open","locked":false,"title":"TLCALIPER-13 - Viadutoo: implement caching proxy endpoint for events","user":{"login":"lsloan","id":20786,"avatar_url":"https://avatars.githubusercontent.com/u/20786?v=3","gravatar_id":"","url":"https://api.github.com/users/lsloan","html_url":"https://github.com/lsloan","followers_url":"https://api.github.com/users/lsloan/followers","following_url":"https://api.github.com/users/lsloan/following{/other_user}","gists_url":"https://api.github.com/users/lsloan/gists{/gist_id}","starred_url":"https://api.github.com/users/lsloan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lsloan/subscriptions","organizations_url":"https://api.github.com/users/lsloan/orgs","repos_url":"https://api.github.com/users/lsloan/repos","events_url":"https://api.github.com/users/lsloan/events{/privacy}","received_events_url":"https://api.github.com/users/lsloan/received_events","type":"User","site_admin":false},"body":"TLCALIPER-13 - Viadutoo: implement caching proxy endpoint for events\r\n\r\nImplemented basic proxy functionality.  Another issue will cover the DB storage of event data if the remote endpoint doesn't accept the data.\r\n\r\nReviewers: @bkirschn @arwhyte @zqian \r\nReview due date: 2015-09-11 12:00","created_at":"2015-09-09T21:02:08Z","updated_at":"2015-09-14T12:54:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7a073c050065b45ab70032217912ec27cf762fcd","assignee":{"login":"lsloan","id":20786,"avatar_url":"https://avatars.githubusercontent.com/u/20786?v=3","gravatar_id":"","url":"https://api.github.com/users/lsloan","html_url":"https://github.com/lsloan","followers_url":"https://api.github.com/users/lsloan/followers","following_url":"https://api.github.com/users/lsloan/following{/other_user}","gists_url":"https://api.github.com/users/lsloan/gists{/gist_id}","starred_url":"https://api.github.com/users/lsloan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lsloan/subscriptions","organizations_url":"https://api.github.com/users/lsloan/orgs","repos_url":"https://api.github.com/users/lsloan/repos","events_url":"https://api.github.com/users/lsloan/events{/privacy}","received_events_url":"https://api.github.com/users/lsloan/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/pulls/1/commits","review_comments_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/pulls/1/comments","review_comment_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/issues/1/comments","statuses_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/statuses/cb6ecaf3910474eb112eb7016f1f6c0d5fa95a80","head":{"label":"lsloan:TLCALIPER-13","ref":"TLCALIPER-13","sha":"cb6ecaf3910474eb112eb7016f1f6c0d5fa95a80","user":{"login":"lsloan","id":20786,"avatar_url":"https://avatars.githubusercontent.com/u/20786?v=3","gravatar_id":"","url":"https://api.github.com/users/lsloan","html_url":"https://github.com/lsloan","followers_url":"https://api.github.com/users/lsloan/followers","following_url":"https://api.github.com/users/lsloan/following{/other_user}","gists_url":"https://api.github.com/users/lsloan/gists{/gist_id}","starred_url":"https://api.github.com/users/lsloan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lsloan/subscriptions","organizations_url":"https://api.github.com/users/lsloan/orgs","repos_url":"https://api.github.com/users/lsloan/repos","events_url":"https://api.github.com/users/lsloan/events{/privacy}","received_events_url":"https://api.github.com/users/lsloan/received_events","type":"User","site_admin":false},"repo":{"id":42198311,"name":"viadutoo","full_name":"lsloan/viadutoo","owner":{"login":"lsloan","id":20786,"avatar_url":"https://avatars.githubusercontent.com/u/20786?v=3","gravatar_id":"","url":"https://api.github.com/users/lsloan","html_url":"https://github.com/lsloan","followers_url":"https://api.github.com/users/lsloan/followers","following_url":"https://api.github.com/users/lsloan/following{/other_user}","gists_url":"https://api.github.com/users/lsloan/gists{/gist_id}","starred_url":"https://api.github.com/users/lsloan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lsloan/subscriptions","organizations_url":"https://api.github.com/users/lsloan/orgs","repos_url":"https://api.github.com/users/lsloan/repos","events_url":"https://api.github.com/users/lsloan/events{/privacy}","received_events_url":"https://api.github.com/users/lsloan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lsloan/viadutoo","description":"A caching proxy endpoint for Caliper","fork":true,"url":"https://api.github.com/repos/lsloan/viadutoo","forks_url":"https://api.github.com/repos/lsloan/viadutoo/forks","keys_url":"https://api.github.com/repos/lsloan/viadutoo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lsloan/viadutoo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lsloan/viadutoo/teams","hooks_url":"https://api.github.com/repos/lsloan/viadutoo/hooks","issue_events_url":"https://api.github.com/repos/lsloan/viadutoo/issues/events{/number}","events_url":"https://api.github.com/repos/lsloan/viadutoo/events","assignees_url":"https://api.github.com/repos/lsloan/viadutoo/assignees{/user}","branches_url":"https://api.github.com/repos/lsloan/viadutoo/branches{/branch}","tags_url":"https://api.github.com/repos/lsloan/viadutoo/tags","blobs_url":"https://api.github.com/repos/lsloan/viadutoo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lsloan/viadutoo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lsloan/viadutoo/git/refs{/sha}","trees_url":"https://api.github.com/repos/lsloan/viadutoo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lsloan/viadutoo/statuses/{sha}","languages_url":"https://api.github.com/repos/lsloan/viadutoo/languages","stargazers_url":"https://api.github.com/repos/lsloan/viadutoo/stargazers","contributors_url":"https://api.github.com/repos/lsloan/viadutoo/contributors","subscribers_url":"https://api.github.com/repos/lsloan/viadutoo/subscribers","subscription_url":"https://api.github.com/repos/lsloan/viadutoo/subscription","commits_url":"https://api.github.com/repos/lsloan/viadutoo/commits{/sha}","git_commits_url":"https://api.github.com/repos/lsloan/viadutoo/git/commits{/sha}","comments_url":"https://api.github.com/repos/lsloan/viadutoo/comments{/number}","issue_comment_url":"https://api.github.com/repos/lsloan/viadutoo/issues/comments{/number}","contents_url":"https://api.github.com/repos/lsloan/viadutoo/contents/{+path}","compare_url":"https://api.github.com/repos/lsloan/viadutoo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lsloan/viadutoo/merges","archive_url":"https://api.github.com/repos/lsloan/viadutoo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lsloan/viadutoo/downloads","issues_url":"https://api.github.com/repos/lsloan/viadutoo/issues{/number}","pulls_url":"https://api.github.com/repos/lsloan/viadutoo/pulls{/number}","milestones_url":"https://api.github.com/repos/lsloan/viadutoo/milestones{/number}","notifications_url":"https://api.github.com/repos/lsloan/viadutoo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lsloan/viadutoo/labels{/name}","releases_url":"https://api.github.com/repos/lsloan/viadutoo/releases{/id}","created_at":"2015-09-09T18:56:04Z","updated_at":"2015-09-01T20:21:23Z","pushed_at":"2015-09-11T20:20:38Z","git_url":"git://github.com/lsloan/viadutoo.git","ssh_url":"git@github.com:lsloan/viadutoo.git","clone_url":"https://github.com/lsloan/viadutoo.git","svn_url":"https://github.com/lsloan/viadutoo","homepage":null,"size":76,"stargazers_count":0,"watchers_count":0,"language":null,"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":"tl-its-umich-edu:master","ref":"master","sha":"c8856e3f25569b110c8f9b9516e3559b96be2af5","user":{"login":"tl-its-umich-edu","id":8292960,"avatar_url":"https://avatars.githubusercontent.com/u/8292960?v=3","gravatar_id":"","url":"https://api.github.com/users/tl-its-umich-edu","html_url":"https://github.com/tl-its-umich-edu","followers_url":"https://api.github.com/users/tl-its-umich-edu/followers","following_url":"https://api.github.com/users/tl-its-umich-edu/following{/other_user}","gists_url":"https://api.github.com/users/tl-its-umich-edu/gists{/gist_id}","starred_url":"https://api.github.com/users/tl-its-umich-edu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tl-its-umich-edu/subscriptions","organizations_url":"https://api.github.com/users/tl-its-umich-edu/orgs","repos_url":"https://api.github.com/users/tl-its-umich-edu/repos","events_url":"https://api.github.com/users/tl-its-umich-edu/events{/privacy}","received_events_url":"https://api.github.com/users/tl-its-umich-edu/received_events","type":"Organization","site_admin":false},"repo":{"id":41117666,"name":"viadutoo","full_name":"tl-its-umich-edu/viadutoo","owner":{"login":"tl-its-umich-edu","id":8292960,"avatar_url":"https://avatars.githubusercontent.com/u/8292960?v=3","gravatar_id":"","url":"https://api.github.com/users/tl-its-umich-edu","html_url":"https://github.com/tl-its-umich-edu","followers_url":"https://api.github.com/users/tl-its-umich-edu/followers","following_url":"https://api.github.com/users/tl-its-umich-edu/following{/other_user}","gists_url":"https://api.github.com/users/tl-its-umich-edu/gists{/gist_id}","starred_url":"https://api.github.com/users/tl-its-umich-edu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tl-its-umich-edu/subscriptions","organizations_url":"https://api.github.com/users/tl-its-umich-edu/orgs","repos_url":"https://api.github.com/users/tl-its-umich-edu/repos","events_url":"https://api.github.com/users/tl-its-umich-edu/events{/privacy}","received_events_url":"https://api.github.com/users/tl-its-umich-edu/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tl-its-umich-edu/viadutoo","description":"A caching proxy endpoint for Caliper","fork":false,"url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo","forks_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/forks","keys_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/teams","hooks_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/hooks","issue_events_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/issues/events{/number}","events_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/events","assignees_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/assignees{/user}","branches_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/branches{/branch}","tags_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/tags","blobs_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/git/refs{/sha}","trees_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/statuses/{sha}","languages_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/languages","stargazers_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/stargazers","contributors_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/contributors","subscribers_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/subscribers","subscription_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/subscription","commits_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/commits{/sha}","git_commits_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/git/commits{/sha}","comments_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/comments{/number}","issue_comment_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/issues/comments{/number}","contents_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/contents/{+path}","compare_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/merges","archive_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/downloads","issues_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/issues{/number}","pulls_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/pulls{/number}","milestones_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/milestones{/number}","notifications_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/labels{/name}","releases_url":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/releases{/id}","created_at":"2015-08-20T20:34:49Z","updated_at":"2015-09-01T20:21:23Z","pushed_at":"2015-09-11T15:45:30Z","git_url":"git://github.com/tl-its-umich-edu/viadutoo.git","ssh_url":"git@github.com:tl-its-umich-edu/viadutoo.git","clone_url":"https://github.com/tl-its-umich-edu/viadutoo.git","svn_url":"https://github.com/tl-its-umich-edu/viadutoo","homepage":null,"size":84,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/pulls/1"},"html":{"href":"https://github.com/tl-its-umich-edu/viadutoo/pull/1"},"issue":{"href":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/issues/1"},"comments":{"href":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/tl-its-umich-edu/viadutoo/statuses/cb6ecaf3910474eb112eb7016f1f6c0d5fa95a80"}}}}