diff --git a/PolarisAnalyticsEngineHelper.php b/PolarisAnalyticsEngineHelper.php index f9adcd5801d1c1dc7ffdabb6a3701c2d78a3961a..f12eef02a25fd2d0da0d0548dae4afaca8c11b39 100644 --- a/PolarisAnalyticsEngineHelper.php +++ b/PolarisAnalyticsEngineHelper.php @@ -49,7 +49,7 @@ class PolarisAnalyticsEngineHelper public function getExistingResult() { - + return $this->getRequest("/api/v1/provider/results"); } public function saveResult($result, $description = null, $context_id = null) @@ -64,16 +64,30 @@ class PolarisAnalyticsEngineHelper { $payload["context_id"] = $context_id; } - - print_r($payload); - return $this->postRequest("/api/v1/provider/store-result",json_encode($payload)); } - function getRequest($url, $data) + function getRequest($url) { - $params = http_build_query($data); - return file_get_contents($this->baseUrl . $url . "?" . $params); + $curlHandle = curl_init($this->baseUrl . $url); + $header = array(); + $header[] = 'Content-Type: application/json'; + $header[] = 'Authorization: Basic ' . $this->analytics_token; + + curl_setopt($curlHandle, CURLOPT_HTTPHEADER, $header); + curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curlHandle, CURLOPT_FAILONERROR, true); + + $curlResponse = curl_exec($curlHandle); + if (curl_errno($curlHandle)) { + $error_msg = curl_error($curlHandle); + } + if (isset($error_msg)) { + print_r($curlResponse); + print_r($error_msg); + } + curl_close($curlHandle); + return json_decode($curlResponse); } function postRequest($url, $data) diff --git a/PolarisAnalyticsEngineHelperTest.php b/PolarisAnalyticsEngineHelperTest.php index ce18dc878fb3ce159d7a0a31d66ac410a7a6df65..6bff5ba4c57bf118449416e57ca796472f763f28 100644 --- a/PolarisAnalyticsEngineHelperTest.php +++ b/PolarisAnalyticsEngineHelperTest.php @@ -26,6 +26,12 @@ class PolarisAnalyticsEngineHelperTest $resultResponse = $this->helper->saveResult($result,"test description",$user); print_r($resultResponse); } + + public function testGetResults() + { + $existing_result = $this->helper->getExistingResult(); + print_r($existing_result); + } } $test = new PolarisAnalyticsEngineHelperTest("0838b91a5d71822ce87bab1de5dd65c52add4865dd2bbcb372604163940285c4"); @@ -33,4 +39,6 @@ $test->testGetStatements(); $test->testSaveResults("user1@polaris.com"); $test->testSaveResults("user2@polaris.com"); -$test->testSaveResults("user3@polaris.com"); \ No newline at end of file +$test->testSaveResults("user3@polaris.com"); + +$test->testGetResults(); \ No newline at end of file