Skip to content

Commit 15aed3f

Browse files
authored
Update for SinusBot 0.10.X
#editSettings Function: Method updated from PATCH to POST #Header updated, Content-type and Timeout (default is 8000ms) added
1 parent 94b4ed3 commit 15aed3f

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

sinusbot.class.php

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
33
* file : sinusbot.class.php
4-
* version : 0.2
5-
* last modified : 27. Juli 2015
4+
* version : 0.3
5+
* last modified : 11. October 2017
66
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
77
* author : Manuel Hettche
88
* copyright : (C) 2015 TS3index.com
@@ -30,6 +30,7 @@
3030
class SinusBot {
3131
public $wiURL = NULL;
3232
public $wiToken = NULL;
33+
public $wiTimeout = NULL;
3334
public $apiURL = NULL;
3435
public $botUUID = NULL;
3536
public $instanceUUID = NULL;
@@ -1518,7 +1519,7 @@ public function getSettings($instanceUUID = NULL) {
15181519
*/
15191520
public function editSettings($data, $instanceUUID = NULL) {
15201521
if ($instanceUUID == NULL) $instanceUUID = $this->instanceUUID;
1521-
return $this->request('/bot/i/'.$instanceUUID.'/settings', 'PATCH', json_encode($data));
1522+
return $this->request('/bot/i/'.$instanceUUID.'/settings', 'POST', json_encode($data));
15221523
}
15231524

15241525

@@ -1906,13 +1907,37 @@ public function isRunning($instanceUUID = NULL) {
19061907
* @param string $botUUID 4852efdc-9705-4706-e469-cfvf77favf33
19071908
* @return void
19081909
*/
1909-
function __construct($wiURL = 'http://127.0.0.1:8087', $botUUID = NULL) {
1910+
function __construct($wiURL = 'http://127.0.0.1:8087', $botUUID = NULL, $wiTimeout = 8000) {
19101911
$this->wiURL = $wiURL;
19111912
$this->apiURL = $this->wiURL.'/api/v1';
1913+
$this->wiTimeout = $wiTimeout;
19121914
$this->botUUID = ($botUUID == NULL) ? $this->getDefaultBot() : $botUUID;
19131915
}
19141916

19151917

1918+
/**
1919+
* __destruct
1920+
*
1921+
* @access private
1922+
* @return void
1923+
*/
1924+
function __destruct() {
1925+
}
1926+
1927+
1928+
/**
1929+
* __call
1930+
*
1931+
* @access private
1932+
* @param string $name method name
1933+
* @param array $args method arguments
1934+
* @return void
1935+
*/
1936+
function __call($name, $args) {
1937+
return 'Method '.$name.' doesn\'t exist';
1938+
}
1939+
1940+
19161941
/**
19171942
* request
19181943
*
@@ -1926,11 +1951,20 @@ private function request($path, $method = "GET", $fields = NULL) {
19261951
$ch = curl_init();
19271952
curl_setopt_array($ch, array(
19281953
CURLOPT_URL => $this->apiURL.$path,
1954+
CURLOPT_HTTPHEADER => array(
1955+
"Accept:application/json, text/plain, */*",
1956+
"Accept-Encoding:gzip, deflate",
1957+
"Content-Type:application/json",
1958+
"Authorization: Bearer ".$this->wiToken
1959+
),
19291960
CURLOPT_CUSTOMREQUEST => $method,
1930-
CURLOPT_RETURNTRANSFER => TRUE,
1931-
CURLOPT_HTTPHEADER => array('Authorization: Bearer '.$this->wiToken)
1961+
CURLOPT_RETURNTRANSFER => true,
1962+
CURLOPT_SSL_VERIFYHOST => false,
1963+
CURLOPT_SSL_VERIFYPEER => false,
1964+
CURLOPT_TIMEOUT_MS => $this->wiTimeout
19321965
));
19331966
if ($fields != NULL) curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
1967+
if ($fields != NULL) curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
19341968
$data = curl_exec($ch);
19351969

19361970
if ($data === false) {

0 commit comments

Comments
 (0)