2020-06-26 23:32:33 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\CustomFacades;
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
|
|
|
|
class IP
|
|
|
|
{
|
2020-10-21 00:29:50 +00:00
|
|
|
|
2020-06-26 23:32:33 +00:00
|
|
|
/**
|
|
|
|
* Looks up information on a specified IP address. Caches results automatically.
|
|
|
|
* @param string $IP IP address to lookup
|
|
|
|
* @return object
|
|
|
|
*/
|
|
|
|
public function lookup(string $IP): object
|
|
|
|
{
|
2020-10-21 00:29:50 +00:00
|
|
|
|
|
|
|
$params = [
|
|
|
|
'apiKey' => config('general.keys.ipapi.apikey'),
|
|
|
|
'ip' => $IP
|
|
|
|
];
|
|
|
|
|
|
|
|
// TODO: Maybe unwrap this? Methods are chained here
|
|
|
|
|
|
|
|
return json_decode(Cache::remember($IP, 3600, function() use ($IP)
|
|
|
|
{
|
|
|
|
return Http::get(config('general.urls.ipapi.ipcheck'), [
|
2020-06-26 23:32:33 +00:00
|
|
|
'apiKey' => config('general.keys.ipapi.apikey'),
|
2020-10-21 00:29:50 +00:00
|
|
|
'ip' => $IP
|
|
|
|
])->body();
|
|
|
|
}));
|
2020-06-26 23:32:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
2020-10-21 00:29:50 +00:00
|
|
|
|
2020-06-26 23:32:33 +00:00
|
|
|
}
|