5
5
use DateTime ;
6
6
use DateTimeZone ;
7
7
use Illuminate \Console \Command ;
8
+ use Illuminate \Support \Facades \Http ;
8
9
9
10
class StoreApiStatus extends Command
10
11
{
@@ -29,7 +30,7 @@ public function handle()
29
30
{
30
31
31
32
// Get test result from json file
32
- $ data = file_get_contents (base_path ('../ result.json ' ));
33
+ $ data = file_get_contents (base_path ('result.json ' ));
33
34
34
35
$ data = json_decode ($ data , true );
35
36
@@ -58,19 +59,29 @@ public function handle()
58
59
$ date = new DateTime ("now " , new DateTimeZone ('Africa/Lagos ' ));
59
60
$ last_checked = $ date ->format ('Y-m-d h:i A ' );
60
61
61
- // Update the api status record
62
- \ App \ Models \ApiStatus:: updateOrCreate ([ ' api_group ' => $ item [ ' name ' ]], [
62
+
63
+ $ data = [
63
64
'api_group ' => $ item ['name ' ],
64
65
'method ' => $ item ['request ' ]['method ' ],
65
66
'status ' => $ status ,
66
67
'response_time ' => $ response_time ,
67
68
'last_checked ' => $ last_checked ,
68
- 'details ' => $ this ->getDetails ($ execution ),
69
- ]);
69
+ 'details ' => $ this ->getDetails ($ execution )
70
+ ];
71
+
72
+ $ url = "https://staging.api-php.boilerplate.hng.tech/api/v1/api-status " ;
73
+
74
+ $ response = Http::post ($ url , $ data );
75
+
76
+ if ($ response ->failed ()) {
77
+
78
+ return $ this ->info ('Failed to send API status data: ' . $ response ->body ());
79
+ }
80
+
70
81
}
71
82
}
72
83
73
- $ this ->info ('Api status stored successfully' );
84
+ $ this ->info ('API status data stored successfully: ' . $ response -> body () );
74
85
}
75
86
76
87
0 commit comments