Beta version
This commit is too large to list all changes.
This commit is contained in:
42
app/CustomFacades/IP.php
Normal file
42
app/CustomFacades/IP.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\CustomFacades;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class IP
|
||||
{
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
|
||||
if (empty($IP))
|
||||
{
|
||||
throw new LogicException(__METHOD__ . 'is missing parameter IP!');
|
||||
}
|
||||
|
||||
$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'), [
|
||||
'apiKey' => config('general.keys.ipapi.apikey'),
|
||||
'ip' => $IP
|
||||
])->body();
|
||||
}));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user