Fixes and cleanups
This commit is contained in:
@ -8,14 +8,14 @@ use function Safe\json_decode;
|
||||
|
||||
class Ipify
|
||||
{
|
||||
public function __construct(protected ClientInterface $client, protected LoggerInterface $logger) {}
|
||||
public function __construct(protected ClientInterface $client, protected string $uri, protected LoggerInterface $logger) {}
|
||||
|
||||
public function get(): string
|
||||
{
|
||||
$this->logger->debug('Getting IP');
|
||||
$response = $this->client->get('?format=json');
|
||||
if (round($response->getCode() / 100, 0) !== 2) {
|
||||
throw new Exception("Could not connect to '{$this->client->base_uri}'");
|
||||
if (round($response->getStatusCode() / 100, 0) != 2) {
|
||||
throw new Exception("Could not connect to '{$this->uri}'");
|
||||
}
|
||||
$body = $response->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
|
Reference in New Issue
Block a user