|
@@ -0,0 +1,45 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\ApiSDK;
|
|
|
+
|
|
|
+class PhyreApiSDK
|
|
|
+{
|
|
|
+ public $ip;
|
|
|
+ public $port;
|
|
|
+ public $password;
|
|
|
+ public $username;
|
|
|
+
|
|
|
+ public function __construct($ip, $port, $password, $username)
|
|
|
+ {
|
|
|
+ $this->ip = $ip;
|
|
|
+ $this->port = $port;
|
|
|
+ $this->password = $password;
|
|
|
+ $this->username = $username;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function healthCheck()
|
|
|
+ {
|
|
|
+ $response = $this->sendRequest('health', [], 'GET');
|
|
|
+
|
|
|
+ return $response;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function sendRequest($resource, $params, $requestType)
|
|
|
+ {
|
|
|
+ $url = 'http://' . $this->ip . ':' . $this->port . '/api/' . $resource;
|
|
|
+
|
|
|
+ $ch = curl_init($url);
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $requestType);
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
|
|
|
+// curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
|
+// 'Content-Type: application/x-www-form-urlencoded',
|
|
|
+// 'Authorization: Basic '.base64_encode($this->username.':'.$this->password)
|
|
|
+// ));
|
|
|
+ $response = curl_exec($ch);
|
|
|
+ curl_close($ch);
|
|
|
+
|
|
|
+ return $response;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|