protected function updateGame(\Morpheus\SteamGame $game, \GuzzleHttp\Psr7\Response $response) { $body = json_decode($response->getBody()); $result = reset($body); if ($response->getStatusCode() == 200 && isset($result->success) && $result->success === true) { $game->steam_store_data = json_encode($result->data); } elseif ($response->getStatusCode() !== 200) { \Log::warning('Steam Store API call failed', ['status code' => $response->getStatusCode(), 'game' => $game]); } elseif (!isset($result->success)) { \Log::warning('Unexpected Steam Store API response', ['body' => $result, 'game' => $game]); } else { \Log::notice('Game not found in Steam Store database', ['game' => $game]); } $game->steam_store_updated = date('Y-m-d H:i:s'); $game->save(); }
protected function updateGame(\Morpheus\SteamGame $game, \GuzzleHttp\Psr7\Response $response) { $body = json_decode($response->getBody()); if ($response->getStatusCode() == 200 && isset($body->result) && $body->result !== false) { $game->metacritic_name = $body->result->name; $game->metacritic_score = $body->result->score; $game->metacritic_userscore = $body->result->userscore; $game->metacritic_genre = $body->result->genre[0]; $game->metacritic_publisher = $body->result->publisher; $game->metacritic_developer = $body->result->developer; $game->metacritic_rating = $body->result->rating; $game->metacritic_url = $body->result->url; $game->metacritic_rlsdate = $body->result->rlsdate; $game->metacritic_summary = $body->result->summary; } elseif ($response->getStatusCode() !== 200) { \Log::warning('Metacritic API call failed', ['status code' => $response->getStatusCode(), 'game' => $game]); } elseif (!isset($body->result)) { \Log::warning('Unexpected Metacritic API response', ['body' => $body, 'game' => $game]); } else { \Log::notice('Game not found in Metacritic database', ['game' => $game]); } $game->metacritic_updated = date('Y-m-d H:i:s'); $game->save(); }
protected function createOrUpdate(\stdClass $game, \Morpheus\User $user) { #try to retrieve a game $steamGame = \Morpheus\SteamGame::find($game->appid); #if fails, create a new one if ($steamGame === null) { $steamGame = \Morpheus\SteamGame::create(["appid" => $game->appid, 'name' => $game->name, 'img_icon_url' => $game->img_icon_url, 'img_logo_url' => $game->img_logo_url, 'has_community_visible_stats' => isset($game->has_community_visible_stats) ? true : false]); $steamGame->setAttribute($steamGame->getKeyName(), $game->appid); } else { $steamGame->name = $game->name; $steamGame->img_icon_url = $game->img_icon_url; $steamGame->img_logo_url = $game->img_logo_url; $steamGame->has_community_visible_stats = isset($game->has_community_visible_stats) ? true : false; $steamGame->save(); } #sync to user $pivot_data = ["playtime_forever" => $game->playtime_forever, "playtime_2weeks" => isset($game->playtime_2weeks) ? $game->playtime_2weeks : 0]; $steamGame->users()->sync([$user->id => $pivot_data], false); return $steamGame; }