commit 300abd43f21e02aa39da32221274dddafcbae1f1
parent fb8238beeabca6470143ab3acbae78519ccaaccf
Author: Gerco van Woudenbergh <[email protected]>
Date: Wed, 28 Jun 2023 15:18:48 +0200
api connection
Diffstat:
2 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/Controller/api/api.php b/Controller/api/api.php
@@ -1,7 +1,8 @@
<?php
$test = function(&$vars){
- $token = '3jvl7yb5sRr80s6lTdeOyxV9VTQZkCPRp7bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk';
- $url = 'http://86.92.67.21/data/';
+ $token = '3jvl/yb?sRr80s6lTdeOyxV9VTQZkCPRp/bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk';
+ $url = 'http://86.92.67.21/api/windchill';
$connect = new Model\Connect($url, $token);
- var_dump($connect-connect());
+ $connect->connect();
+ var_dump($connect->get_response());
};
\ No newline at end of file
diff --git a/Model/Connect.php b/Model/Connect.php
@@ -1,8 +1,11 @@
<?php
namespace Model{
class Connect{
+
protected string $url;
protected string $token;
+ protected string $json;
+
function __construct($url, $token){
$this->url = $url;
$this->token = $token;
@@ -15,8 +18,7 @@ namespace Model{
}
$headers = array(
- 'Authorization: Bearer ' . $this->token, // Your token value
- 'Content-Type: application/json', // Example of setting the content type header
+ "X-Token: $this->token", // Your token value
);
curl_setopt($ch, CURLOPT_URL, $this->url);
@@ -30,12 +32,14 @@ namespace Model{
}
curl_close($ch);
-
- response($response);
- return $response;
+
+ $this->json = $response;
}
- private function response($response){
-
+ function response(){
+ return json_decode($this->json);
+ }
+ function get_response():string{
+ return $this->json;
}
}
}
\ No newline at end of file