From 0c39b98ce9a9c4cad5193046bc628a8c7bb96847 Mon Sep 17 00:00:00 2001 From: Orestis Moresis Date: Fri, 17 Mar 2023 14:15:01 +0200 Subject: [PATCH] fix wfd data fetching --- src/Controllers/InterfaceController.php | 1 - src/Services/API.php | 1 + src/Services/WfdAPI.php | 19 +++++++++++++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Controllers/InterfaceController.php b/src/Controllers/InterfaceController.php index 205fc66..e60ed8c 100644 --- a/src/Controllers/InterfaceController.php +++ b/src/Controllers/InterfaceController.php @@ -60,7 +60,6 @@ class InterfaceController { $readJSONFile = file_get_contents($url); echo $readJSONFile; - /* header($_SERVER['SERVER_PROTOCOL'].'404 Not Found'); */ break; } } diff --git a/src/Services/API.php b/src/Services/API.php index e506380..37eccb6 100644 --- a/src/Services/API.php +++ b/src/Services/API.php @@ -35,6 +35,7 @@ class API curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($this->curl, CURLOPT_MAXREDIRS, 10); curl_setopt($this->curl, CURLOPT_TIMEOUT, 30); + curl_setopt($this->curl, CURLOPT_VERBOSE, true); if (!empty($this->headers["Authorization"])) { curl_setopt($this->curl, CURLOPT_HTTPHEADER, $this::convert_headers($this->headers)); } diff --git a/src/Services/WfdAPI.php b/src/Services/WfdAPI.php index a841450..a586ff3 100644 --- a/src/Services/WfdAPI.php +++ b/src/Services/WfdAPI.php @@ -55,7 +55,10 @@ class WfdAPI extends API { public function getStationSamples($station_id) { - $endpoint = "/coastal-trans-samples"; + $endpoint = "coastal-trans-samples"; + + $this->headers["Authorization"] = "Bearer {$this->accessToken}"; + $this->headers["Accept"] = "application/json"; $data = array( "coastalTransStationId.equals" => $station_id ); @@ -68,13 +71,21 @@ class WfdAPI extends API { * Fetches data for a specific station according to the sample sampleIds * */ - public function getData($parameter_ids) { + public function getData($parameter_ids, $data_category='all') { + + $this->headers["Authorization"] = "Bearer {$this->accessToken}"; + $this->headers["Accept"] = "application/json"; + $res = []; $data = array( "coastalTransSampleId.in" => implode(",", $parameter_ids) ); - $endpoint = "coastal-trans-abiotics"; - $res = json_decode($this->get($endpoint, $data)); + if ($data_category === 'all') + $endpoints = array("coastal-trans-abiotics","coastal-trans-macrofaunas", "coastal-trans-phytoplanktons", "coastal-trans-angiosperms"); + + foreach ($endpoints as $endpoint) { + array_push($res, json_decode($this->get($endpoint, $data))); + } return $res; }