Example #1
0
 /**
  * @covers \App\Http\Controllers\SteamGameController
  * @covers \App\SteamGame
  */
 public function test_parsing_json_and_storing_a_game_and_stats()
 {
     $game = json_decode($this->gameJson);
     $SteamGame = App\SteamGame::firstOrNew(['id' => $game->appid]);
     $SteamAPIGame = new App\Http\Controllers\Integration\SteamAPI\SteamAPIGame();
     $SteamAPIGame->parseAndSaveSteamGame($SteamGame, $game);
     $this->seeInDatabase('steam_games', ['name' => 'Creeper World 3: Arc Eternal']);
     $steamGameDescriptionJson = json_decode($this->steamGameDescriptionJson);
     $SteamAPIGameDescription = new App\Http\Controllers\Integration\SteamAPI\SteamAPIGameDescription(new App\SteamGame());
     $SteamAPIGameDescription->updateSteamGameWithNewDescription($SteamGame, $steamGameDescriptionJson);
     $this->seeInDatabase('steam_games', ['website' => 'http://knucklecracker.com']);
     $SteamGameSchemaFromAPI = json_decode($this->steamSchemaJson);
     $SteamAPIGameSchema = new App\Http\Controllers\Integration\SteamAPI\SteamAPIGameSchema(new App\SteamGame());
     $SteamAPIGameSchema->parseAndSaveAchievementSchema($SteamGame->id, $SteamGameSchemaFromAPI->achievements);
     $this->seeInDatabase('steam_game_achievements', ['steam_game_id' => '280220', 'display_name' => 'Training Wheels']);
     $SteamAPIGameSchema->parseAndSaveStatSchema($SteamGame->id, $SteamGameSchemaFromAPI->stats);
     $this->seeInDatabase('steam_game_stats', ['steam_game_id' => '280220', 'display_name' => 'Inhibitors destroyed in Tormented Space']);
     $this->visit('/')->click('Steam')->see('Steam Games')->seePageIs('/game/steam');
     $this->visit('/game/steam/280220')->see('Creeper World 3: Arc Eternal')->seePageIs('/game/steam/280220');
     $SteamGames = \App\SteamGame::ListGames()->get();
     $this->assertEquals('Creeper World 3: Arc Eternal', $SteamGames[0]['attributes']['name']);
     $SteamGame = \App\SteamGame::find($game->appid)->stats->first();
     $this->assertEquals('testStat1', $SteamGame['attributes']['name']);
     $SteamGame = \App\SteamGame::find($game->appid)->achievements->first();
     $this->assertEquals('ACH_0', $SteamGame['attributes']['name']);
 }
 /**
  * Display the specified resource.
  *
  * @param int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $SteamGame = SteamGame::find($id);
     $CompletedAchievements = $SteamGame->achievements->filter(function ($item, $key) {
         return $item['value'] == 1;
     });
     $NotCompletedAchievements = $SteamGame->achievements->filter(function ($item, $key) {
         return $item['value'] == 0;
     });
     return view('pages.SteamGame', ['SteamGame' => $SteamGame, 'CompletedAchievements' => $CompletedAchievements, 'NotCompletedAchievements' => $NotCompletedAchievements]);
 }
 /**
  * @param SteamGame $SteamGame
  * @param null      $GameDescriptionJson
  *
  * @return bool|void
  */
 public function updateSteamGameWithNewDescription(SteamGame $SteamGame, $GameDescriptionJson = null)
 {
     if (empty($GameDescriptionJson)) {
         return;
     }
     if (!empty($GameDescriptionJson->is_free)) {
         $SteamGame->is_free = $GameDescriptionJson->is_free;
     }
     if (!empty($GameDescriptionJson->about_the_game)) {
         $SteamGame->about_the_game = $GameDescriptionJson->about_the_game;
     }
     if (!empty($GameDescriptionJson->header_image)) {
         $SteamGame->image_header = $GameDescriptionJson->header_image;
     }
     if (!empty($GameDescriptionJson->legal_notice)) {
         $SteamGame->legal_notice = $GameDescriptionJson->legal_notice;
     }
     if (!empty($GameDescriptionJson->metacritic->score)) {
         $SteamGame->meta_critic_score = $GameDescriptionJson->metacritic->score;
     }
     if (!empty($GameDescriptionJson->metacritic->url)) {
         $SteamGame->meta_critic_url = $GameDescriptionJson->metacritic->url;
     }
     if (!empty($GameDescriptionJson->website)) {
         $SteamGame->website = $GameDescriptionJson->website;
     }
     if (!empty($GameDescriptionJson->screenshots[0]->path_thumbnail)) {
         $SteamGame->screenshot_path_thumbnail = $GameDescriptionJson->screenshots[0]->path_thumbnail;
     }
     if (!empty($GameDescriptionJson->screenshots[0]->path_full)) {
         $SteamGame->screenshot_path_full = $GameDescriptionJson->screenshots[0]->path_full;
     }
     if (!empty($GameDescriptionJson->movies)) {
         $lastMovie = end($GameDescriptionJson->movies);
         if (!empty($lastMovie->thumbnail)) {
             $SteamGame->movie_thumbnail = $lastMovie->thumbnail;
         }
         if (!empty($lastMovie->webm->max)) {
             $SteamGame->movie_full_url = $lastMovie->webm->max;
         }
         if (!empty($lastMovie->name)) {
             $SteamGame->movie_name = $lastMovie->name;
         }
     }
     if (!empty($GameDescriptionJson->background)) {
         $SteamGame->image_background = $GameDescriptionJson->background;
     }
     $SteamGame->description_updated_at = date('Y-m-d H:i:s');
     return $SteamGame->save();
 }
Example #4
0
 private function parseAndSaveOnlyOwnedGames()
 {
     $SteamOwnedGamesFromAPI = $this->getOwnedGames();
     foreach ($SteamOwnedGamesFromAPI as $game) {
         if (empty($game)) {
             continue;
         }
         $SteamGame = SteamGame::firstOrNew(['id' => $game->appid]);
         $this->parseAndSaveSteamGame($SteamGame, $game);
     }
 }
 /**
  * @param $GameId
  *
  * @return mixed
  */
 private function setGameTimestampForSchema($GameId)
 {
     $SteamGame = SteamGame::find($GameId);
     $SteamGame->schema_updated_at = date('Y-m-d H:i:s');
     return $SteamGame->save();
 }
 /**
  * @param $GameId
  *
  * @return mixed
  */
 private function setGameTimestampForAchievement($GameId)
 {
     $SteamGame = SteamGame::find($GameId);
     $SteamGame->player_stats_updated_at = date('Y-m-d H:i:s');
     return $SteamGame->save();
 }