From bd29c35fe2babeb81bee61ac20090d595518e61d Mon Sep 17 00:00:00 2001
From: Benjamin Ledel <benjamin@schule-plus.com>
Date: Tue, 19 Sep 2023 22:50:44 +0200
Subject: [PATCH] * init

---
 PolarisAnalyticsEngineHelper.php     | 28 +++++++++++++++++++++-------
 PolarisAnalyticsEngineHelperTest.php | 10 +++++++++-
 2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/PolarisAnalyticsEngineHelper.php b/PolarisAnalyticsEngineHelper.php
index f9adcd5..f12eef0 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 ce18dc8..6bff5ba 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
-- 
GitLab