@@ -6,32 +6,25 @@ class VultrAPI
66{
77 protected const API_URL = 'https://api.vultr.com/ ' ;//API endpoint (Dont change)
88 protected const API_KEY = 'XYZ-ABC-123 ' ;//Put your Vultr API key here
9- protected $ instance_id ;//Service id set with: setSubid()
10- protected $ server_create_details = [];
9+ protected int $ instance_id ;//Service id set with: setSubid()
10+ protected array $ server_create_details = [];
1111 protected $ call_data ;
1212
13- public function __construct (bool $ json_header = false )
14- {
15- if ($ json_header ) {
16- header ('Content-Type: application/json ' );
17- }
18- }
19-
2013 public function apiKeyHeader (): array
2114 {
22- return array ("Authorization: Bearer " . self ::API_KEY . "" , "Content-Type: application/json " );
15+ return array ("Authorization: Bearer " . self ::API_KEY , "Content-Type: application/json " );
2316 }
2417
2518 public function doCurl (string $ url , string $ type = 'GET ' , bool $ return_http_code = false , array $ headers = [], array $ post_fields = [])
2619 {
2720 $ crl = curl_init (self ::API_URL . $ url );
2821 curl_setopt ($ crl , CURLOPT_CUSTOMREQUEST , $ type );
29- if ($ type == 'POST ' ) {
22+ if ($ type === 'POST ' ) {
3023 curl_setopt ($ crl , CURLOPT_POST , true );
3124 if (!empty ($ post_fields )) {
3225 curl_setopt ($ crl , CURLOPT_POSTFIELDS , json_encode ($ post_fields ));
3326 }
34- } elseif ($ type == 'PATCH ' ) {
27+ } elseif ($ type === 'PATCH ' ) {
3528 curl_setopt ($ crl , CURLOPT_CUSTOMREQUEST , 'PATCH ' );
3629 curl_setopt ($ crl , CURLOPT_POSTFIELDS , json_encode ($ post_fields ));
3730 }
@@ -48,13 +41,11 @@ public function doCurl(string $url, string $type = 'GET', bool $return_http_code
4841 curl_close ($ crl );
4942 if ($ return_http_code ) {
5043 return $ http_response_code ;
51- } else {
52- if ($ http_response_code == 200 || $ http_response_code == 201 || $ http_response_code == 202 ) {
53- return $ this ->call_data = $ call_response ;//Return data
54- } else {
55- return $ this ->call_data = array ('http_response_code ' => $ http_response_code );//Call failed
56- }
5744 }
45+ if ($ http_response_code === 200 || $ http_response_code === 201 || $ http_response_code === 202 ) {
46+ return $ this ->call_data = $ call_response ;//Return data
47+ }
48+ return $ this ->call_data = array ('http_response_code ' => $ http_response_code );//Call failed
5849 }
5950
6051 public function setSubid (string $ instance_id ): void
@@ -365,20 +356,20 @@ public function serverCreatePlan(string $plan_id)
365356
366357 public function serverCreateType (string $ type = 'OS ' , string $ type_id = '1 ' )
367358 {
368- if ($ type == 'OS ' ) {
359+ if ($ type === 'OS ' ) {
369360 $ this ->server_create_details = array_merge ($ this ->server_create_details , array (
370361 "os_id " => $ type_id
371362 ));
372- } elseif ($ type == 'SNAPSHOT ' ) {
363+ } elseif ($ type === 'SNAPSHOT ' ) {
373364 $ this ->server_create_details = array_merge ($ this ->server_create_details , array (
374365 "snapshot_id " => $ type_id
375366 ));
376- } elseif ($ type == 'ISO ' ) {
367+ } elseif ($ type === 'ISO ' ) {
377368 $ this ->server_create_details = array_merge ($ this ->server_create_details , array (
378369 "os_id " => 159 ,
379370 "iso_id " => $ type_id
380371 ));
381- } elseif ($ type == 'APP ' ) {
372+ } elseif ($ type === 'APP ' ) {
382373 $ this ->server_create_details = array_merge ($ this ->server_create_details , array (
383374 "os_id " => 186 ,
384375 "app_id " => $ type_id
0 commit comments