|
|
@@ -0,0 +1,35 @@ |
|
|
|
<?php |
|
|
|
|
|
|
|
namespace App\Knockout; |
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Cache; |
|
|
|
|
|
|
|
class UserBan { |
|
|
|
|
|
|
|
private static function requestAll(int $userId): Dataset |
|
|
|
{ |
|
|
|
$data = (new AbstractData)->httpGet(sprintf('/user/%u/bans', $userId)); |
|
|
|
$json = json_decode($data); |
|
|
|
$records = array_map(function($user) { |
|
|
|
return Ban::unwrap($user); |
|
|
|
}, $json); |
|
|
|
return (new Dataset($records)); |
|
|
|
} |
|
|
|
|
|
|
|
public static function updateAll(int $userId): Dataset |
|
|
|
{ |
|
|
|
$key = sprintf('user-bans-%u', $userId); |
|
|
|
$data = self::requestAll($userId); |
|
|
|
Cache::put($key, $data, 300); |
|
|
|
return $data; |
|
|
|
} |
|
|
|
|
|
|
|
public static function all(int $userId): Dataset |
|
|
|
{ |
|
|
|
$key = sprintf('user-bans-%u', $userId); |
|
|
|
return Cache::get($key, function() use($userId) { |
|
|
|
return self::updateAll($userId); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
} |