Skip to content

Commit

Permalink
ipapi response structured
Browse files Browse the repository at this point in the history
  • Loading branch information
hafijul233 committed Sep 17, 2024
1 parent a1c70e0 commit 42f0ab4
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/Services/Vendors/GeoIp/IpApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,24 @@ public function __construct(array $config = [])

public function find(string $ip): mixed
{
$response = Http::baseUrl("https://api.ipapi.com/api/")
->contentType('application/json')
->acceptJson()
->get($ip, [
'access_key' => $this->token,
'output' => 'json',
'language' => 'en'
]);

if (!$response->json()) {
throw new \JsonException("Invalid IP API Response.");
}

$response = Http::baseUrl("https://api.ipapi.com/api/")->get($ip, [
'access_key' => $this->token,
'output' => 'json',
'language' => 'en'
]);
if (!$response->json('success')) {
throw new \JsonException("IP API Error: " . $response->json('error.info'));
}

return $response->json();
return $response;
}

/**
Expand Down

0 comments on commit 42f0ab4

Please sign in to comment.