@@ -33,6 +33,11 @@ class RestClient
3333 */
3434 protected $ url = null ;
3535 /**
36+ * headers are http headers which will be added on every request
37+ * @var array
38+ */
39+ private $ headers = [];
40+ /**
3641 * request executes a request to the SinusBot API
3742 *
3843 * @param string $path /api/v1/<path>
@@ -46,11 +51,11 @@ protected function request($path, $method = "GET", $payload = null, $encoded = f
4651 $ ch = curl_init ();
4752 curl_setopt_array ($ ch , [
4853 CURLOPT_URL => $ this ->url .'/api/v1 ' .$ path ,
49- CURLOPT_HTTPHEADER => [
54+ CURLOPT_HTTPHEADER => array_merge ( [
5055 "Accept: application/json, text/plain, */* " ,
5156 "Content-Type: application/json " ,
5257 "Authorization: Bearer " .$ this ->token
53- ],
58+ ], $ this -> headers ),
5459 CURLOPT_CUSTOMREQUEST => $ method ,
5560 CURLOPT_RETURNTRANSFER => true ,
5661 CURLOPT_SSL_VERIFYHOST => false ,
@@ -76,6 +81,18 @@ protected function request($path, $method = "GET", $payload = null, $encoded = f
7681
7782
7883 /**
84+ * addHeader adds a header to every http request
85+ *
86+ * @param string $key http header key
87+ * @param string $value http header value
88+ */
89+ public function addHeader ($ key , $ value )
90+ {
91+ array_push ($ this ->headers , [
92+ $ key => $ value ,
93+ ]);
94+ }
95+ /**
7996 * getError returns the string representive to the given http status code
8097 *
8198 * @param integer $code http status code
0 commit comments