@@ -6,32 +6,25 @@ class VultrAPI
6
6
{
7
7
protected const API_URL = 'https://api.vultr.com/ ' ;//API endpoint (Dont change)
8
8
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 = [];
11
11
protected $ call_data ;
12
12
13
- public function __construct (bool $ json_header = false )
14
- {
15
- if ($ json_header ) {
16
- header ('Content-Type: application/json ' );
17
- }
18
- }
19
-
20
13
public function apiKeyHeader (): array
21
14
{
22
- return array ("Authorization: Bearer " . self ::API_KEY . "" , "Content-Type: application/json " );
15
+ return array ("Authorization: Bearer " . self ::API_KEY , "Content-Type: application/json " );
23
16
}
24
17
25
18
public function doCurl (string $ url , string $ type = 'GET ' , bool $ return_http_code = false , array $ headers = [], array $ post_fields = [])
26
19
{
27
20
$ crl = curl_init (self ::API_URL . $ url );
28
21
curl_setopt ($ crl , CURLOPT_CUSTOMREQUEST , $ type );
29
- if ($ type == 'POST ' ) {
22
+ if ($ type === 'POST ' ) {
30
23
curl_setopt ($ crl , CURLOPT_POST , true );
31
24
if (!empty ($ post_fields )) {
32
25
curl_setopt ($ crl , CURLOPT_POSTFIELDS , json_encode ($ post_fields ));
33
26
}
34
- } elseif ($ type == 'PATCH ' ) {
27
+ } elseif ($ type === 'PATCH ' ) {
35
28
curl_setopt ($ crl , CURLOPT_CUSTOMREQUEST , 'PATCH ' );
36
29
curl_setopt ($ crl , CURLOPT_POSTFIELDS , json_encode ($ post_fields ));
37
30
}
@@ -48,13 +41,11 @@ public function doCurl(string $url, string $type = 'GET', bool $return_http_code
48
41
curl_close ($ crl );
49
42
if ($ return_http_code ) {
50
43
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
- }
57
44
}
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
58
49
}
59
50
60
51
public function setSubid (string $ instance_id ): void
@@ -365,20 +356,20 @@ public function serverCreatePlan(string $plan_id)
365
356
366
357
public function serverCreateType (string $ type = 'OS ' , string $ type_id = '1 ' )
367
358
{
368
- if ($ type == 'OS ' ) {
359
+ if ($ type === 'OS ' ) {
369
360
$ this ->server_create_details = array_merge ($ this ->server_create_details , array (
370
361
"os_id " => $ type_id
371
362
));
372
- } elseif ($ type == 'SNAPSHOT ' ) {
363
+ } elseif ($ type === 'SNAPSHOT ' ) {
373
364
$ this ->server_create_details = array_merge ($ this ->server_create_details , array (
374
365
"snapshot_id " => $ type_id
375
366
));
376
- } elseif ($ type == 'ISO ' ) {
367
+ } elseif ($ type === 'ISO ' ) {
377
368
$ this ->server_create_details = array_merge ($ this ->server_create_details , array (
378
369
"os_id " => 159 ,
379
370
"iso_id " => $ type_id
380
371
));
381
- } elseif ($ type == 'APP ' ) {
372
+ } elseif ($ type === 'APP ' ) {
382
373
$ this ->server_create_details = array_merge ($ this ->server_create_details , array (
383
374
"os_id " => 186 ,
384
375
"app_id " => $ type_id
0 commit comments