getGet('q')); if (mb_strlen($q) < 2) { return service('response')->setJSON([]); } return service('response')->setJSON((new GameModel())->suggest($q)); } /** * Game Prices API: lowest price by Steam App ID. * GET /api/prices?appid=1245620 */ public function prices(): \CodeIgniter\HTTP\ResponseInterface { $appid = (int) service('request')->getGet('appid'); if ($appid <= 0) { return service('response')->setStatusCode(400)->setJSON([ 'error' => 'bad_request', 'message' => 'Missing or invalid "appid" query parameter.', ]); } // appid map is in the CrawlCovers command; reuse via a public map. $game = (new GameModel())->findByAppId($appid); if ($game === null) { return service('response')->setStatusCode(404)->setJSON([ 'error' => 'not_found', 'message' => "No game found for Steam App ID {$appid}.", ]); } return service('response')->setJSON([ 'game' => [ 'title' => $game['title'], 'slug' => $game['slug'], 'url' => '/game/' . $game['slug'], 'steam_appid' => $appid, 'regular_price' => (float) $game['base_price'], 'best_official' => [ 'price' => (float) $game['best_official']['price'], 'store' => $game['best_official']['store'], 'cut' => (int) $game['best_official']['cut'], ], 'best_keyshop' => [ 'price' => (float) $game['best_keyshop']['price'], 'store' => $game['best_keyshop']['store'], 'cut' => (int) $game['best_keyshop']['cut'], ], 'all_time_low' => [ 'price' => (float) $game['all_time_low']['price'], 'store' => $game['all_time_low']['store'], 'date' => $game['all_time_low']['date'] instanceof \MongoDB\BSON\UTCDateTime ? $game['all_time_low']['date']->toDateTime()->format('Y-m-d') : null, ], 'active_deals' => (int) $game['active_deals'], 'metacritic' => (int) $game['score'], ], ]); } /** * API documentation page data (regions, endpoints). */ public function docs(): string { $model = new GameModel(); $data = [ 'pageTitle' => 'GG.deals API — Game Deals, Bundles and Prices API', 'stats' => $model->stats(), ]; return view('api', $data); } }