// May 22, 2019 status: this works // https://appac.github.io/mlb-data-api-docs/#player-data-player-teams-get // _pT.GetTeamsForPlayerSingleSeason("2017","493316"); // MlbDataEndPoint newEndPoint = _endPoints.PlayerTeamsEndPoint("2017","493316"); // http://lookup-service-prod.mlb.com/json/named.player_teams.bam?season='2014'&player_id='493316' // JToken allTeamValues = jObject["player_teams"]["queryResults"]["row"]; public List <PlayerTeam> GetTeamsForPlayerSingleSeason(string year, string playerId) { MlbDataEndPoint newEndPoint = _endPoints.PlayerTeamsEndPoint(year, playerId); PostmanRequest postmanRequest = _postman.CreatePostmanRequest(newEndPoint, "PlayerTeams"); PostmanResponse postmanResponse = _postman.GetPostmanResponse(postmanRequest); IRestResponse response = postmanResponse.Response; // jObject: player_teams > copyRight, queryResults > created, totalSize, row JObject jObject = _apI.CreateModelJObject(response); // totalSize --> the size of "row" which is equal to number of teams (e.g., a totalSize of 2 means there are two teams shown for the player in the "row" json header) int totalSize = Convert.ToInt32(jObject["player_teams"]["queryResults"]["totalSize"], CultureInfo.CurrentCulture); // returns all keys & values for all teams the player played for JToken allTeamValuesJToken = _apI.CreateModelJToken(jObject, "PlayerTeam"); List <PlayerTeam> ptList = new List <PlayerTeam>(); for (var teamIndex = 0; teamIndex <= totalSize - 1; teamIndex++) { PlayerTeam pTeam = new PlayerTeam(); PlayerTeam pTeamInstance = _apI.CreateInstanceOfModel(allTeamValuesJToken[teamIndex], pTeam, "PlayerTeam") as PlayerTeam; ptList.Add(pTeamInstance); } return(ptList); }
// STATUS: this works // STEP 1 /// <summary> /// Get the current seasons pitching leaders; Endpoint parameters passed as parameters to method /// </summary> /// <remarks> /// Parameters for 'PitchingLeadersEndPoint' (i.e. numberToReturn, year, sortColumn) are passed as parameters to the method /// See: 'LeadingPitcher' model for options that you can sort by for this method /// </remarks> /// <param name="numberToReturn"> /// The number of pitchers to return in the results (e.g. 50 would show you the top 50 leaders) /// </param> /// <param name="year"> /// The year that you want to retrieve the leaders for (e.g. 2018 gets you leaders for 2018 mlb season) /// </param> /// <param name="sortColumn"> /// This is the stat you want to retrieve the leaders for (e.g., Era, Wins, etc) /// </param> /// <returns> /// A list of instantiated 'LeadingPitching' for 'numberToReturn' number of pitchers /// </returns> public PitchingLeaders CreatePitchingLeadersModel(int numberToReturn, string year, string sortColumn) { // retrieve the 'PitchingLeaders' end point // * param 1: number of pitchers to include in search // * param 2: season that you want to query // * param 3: stat that you would like to sort by MlbDataEndPoint newEndPoint = _endPoints.PitchingLeadersEndPoint(numberToReturn, year, sortColumn); PostmanRequest postmanRequest = _postman.CreatePostmanRequest(newEndPoint, "PitchingLeaders"); PostmanResponse postmanResponse = _postman.GetPostmanResponse(postmanRequest); IRestResponse response = postmanResponse.Response; JObject leadersJObject = _apiInfrastructure.CreateModelJObject(response); JToken leadersJToken = _apiInfrastructure.CreateModelJToken(leadersJObject, "PitchingLeaders"); // * Returns object with many 'LeadingPitcher' instances // * The number returned depends on first parameter passed when retrieving the 'PitchingLeadersEndPoint' (see above) PitchingLeaders newPitchingLeadersInstance = new PitchingLeaders(); _apiInfrastructure.CreateInstanceOfModel( leadersJToken, newPitchingLeadersInstance, "PitchingLeaders" ); LeadingPitcher newLeadingPitcherInstance = new LeadingPitcher(); _apiInfrastructure.CreateMultipleInstancesOfModelByLooping( leadersJToken, newLeadingPitcherInstance, "LeadingPitcher" ); return(newPitchingLeadersInstance); }
// /json/named.sport_pitching_tm.bam?league_list_id='mlb'&game_type={game_type}&season={season}&player_id={player_id} // http://lookup-service-prod.mlb.com/json/named.sport_hitting_tm.bam?league_list_id='mlb'&game_type='R'&season='2017'&player_id='592789' public HitterSeasonStats CreateHitterSeasonStatsInstance(string year, int playerId) { MlbDataEndPoint newEndPoint = _endPoints.HitterSeasonEndPoint("R", year, playerId.ToString(CultureInfo.InvariantCulture)); PostmanRequest postmanRequest = _postman.CreatePostmanRequest(newEndPoint, "HitterSeasonStats"); PostmanResponse postmanResponse = _postman.GetPostmanResponse(postmanRequest); IRestResponse response = postmanResponse.Response; var jObject = _apiInfrastructure.CreateModelJObject(response); var jToken = _apiInfrastructure.CreateModelJToken(jObject, "HitterSeasonStats"); var hitter = _apiInfrastructure.CreateInstanceOfModel(jToken, _hSS, "HitterSeasonStats") as HitterSeasonStats; return(hitter); }
public IActionResult ViewPlayerInfo(int playerId) { // this gets you Cespedes // int playerIdPlaceHolder = 493316; Console.WriteLine($"GETTING INFO FOR PLAYER ID: {playerId}"); IRestResponse response = GetProjectedHittingStatsPostmanResponse(playerId); JObject playerJObject = _apiInfrastructure.CreateModelJObject(response); JToken playerJToken = _apiInfrastructure.CreateModelJToken(playerJObject, "ProjectedHittingStats"); ProjectedHittingStats newInstance = new ProjectedHittingStats(); _apiInfrastructure.CreateInstanceOfModel(playerJToken, newInstance, "ProjectedHittingStats"); return(Content($"{playerJToken}")); }
// https://appac.github.io/mlb-data-api-docs/#player-data-player-info-get /// <summary> /// View instantiated player model with player's info /// </summary> /// <param name="playerId">todo: describe playerId parameter on CreatePlayerInfoInstance</param> /// <returns> /// A view of a playerinfo model /// </returns> public PlayerInfo CreatePlayerInfoInstance(int playerId) { _helpers.StartMethod(); Console.WriteLine($"GETTING INFO FOR PLAYER ID: {playerId}"); IRestResponse response = GetPlayerInfoPostmanResponse(playerId); JObject playerJObject = _apiInfrastructure.CreateModelJObject(response); JToken playerJToken = _apiInfrastructure.CreateModelJToken(playerJObject, "PlayerInfo"); int jTokenChildrenCount = playerJToken.Count <object>(); Console.WriteLine($"jTokenChildrenCount: {jTokenChildrenCount}"); PlayerInfo newPlayerInfoInstance = new PlayerInfo(); newPlayerInfoInstance = _apiInfrastructure.CreateInstanceOfModel(playerJToken, newPlayerInfoInstance, "PlayerInfo") as PlayerInfo; _helpers.Dig(newPlayerInfoInstance); return(newPlayerInfoInstance); }
// STATUS [ July 15, 2019 ] : this works // STEP 1 /// <summary> /// Get the current seasons hitting leaders; Endpoint parameters passed as parameters to method /// </summary> /// <remarks> /// Parameters for 'HittingLeadersEndPoint' (i.e. numberToReturn, year, sortColumn) are passed as parameters to the method /// See: https://appac.github.io/mlb-data-api-docs/#reports-hitting-leaders-get /// </remarks> /// <param name="numberToReturn"> /// The number of hitters to return in the results (e.g. 50 would show you the top 50 leaders) /// </param> /// <param name="year"> /// The year that you want to retrieve the leaders for (e.g. 2018 gets you leaders for 2018 mlb season) /// </param> /// <param name="sortColumn"> /// This is the stat you want to retrieve the leaders for (e.g., Hr, Rbi etc) /// See: View 'LeadingHitter' model for options that you can sort by for this method /// </param> /// <example> /// var hittingLeaders = CreateHittingLeadersModel(5, "2019", "hr"); /// </example> /// <returns> /// A list of instantiated 'LeadingHitter' for 'numberToReturn' number of hitters /// </returns> public List <LeadingHitter> CreateHittingLeadersModel(int numberToReturn, string year, string sortColumn) { var newEndPoint = _endPoints.HittingLeadersEndPoint(numberToReturn, year, sortColumn); C.WriteLine(newEndPoint); var postmanRequest = _postman.CreatePostmanRequest(newEndPoint, "HittingLeaders"); var postmanResponse = _postman.GetPostmanResponse(postmanRequest); IRestResponse response = postmanResponse.Response; JObject leadersJObject = _apiInfrastructure.CreateModelJObject(response); JToken leadersJToken = _apiInfrastructure.CreateModelJToken(leadersJObject, "HittingLeaders"); int jTokenChildrenCount = leadersJToken.Count <object>(); C.WriteLine($"jTokenChildrenCount: {jTokenChildrenCount}"); List <LeadingHitter> listOfPlayers = new List <LeadingHitter>(); LeadingHitter newLeadingHitterInstance = new LeadingHitter(); for (var counter = 0; counter < jTokenChildrenCount; counter++) { newLeadingHitterInstance = _apiInfrastructure.CreateInstanceOfModel ( leadersJToken[counter], newLeadingHitterInstance, "LeadingHitter" ) as LeadingHitter; listOfPlayers.Add(newLeadingHitterInstance); } foreach (var player in listOfPlayers) { C.WriteLine(player.NameLastCommaFirst); } return(listOfPlayers); }
// STATUS [ July 15, 2019 ] : this works /// <summary> /// View instantiated PlayerSearch object /// </summary> /// <param name="playerLastName">todo: describe playerLastName parameter on ViewPlayerSearchModel</param> /// <remarks> /// See: https://appac.github.io/mlb-data-api-docs/#player-data-player-search-get /// </remarks> /// <returns> /// Instantiated PlayerSearch /// </returns> public List <PlayerSearch> ViewPlayerSearchModel(string playerLastName) { IRestResponse response = GetPlayerSearchModelPostmanResponse(playerLastName); JObject playerJObject = _apiInfrastructure.CreateModelJObject(response); JToken playerJToken = _apiInfrastructure.CreateModelJToken(playerJObject, "PlayerSearch"); int jTokenChildrenCount = playerJToken.Count <object>(); List <PlayerSearch> listOfPlayers = new List <PlayerSearch>(); PlayerSearch newPlayerSearchInstance = new PlayerSearch(); for (var counter = 0; counter < jTokenChildrenCount; counter++) { PlayerSearch playerSearchInstance = _apiInfrastructure.CreateInstanceOfModel ( playerJToken[counter], newPlayerSearchInstance, "PlayerSearch" ) as PlayerSearch; listOfPlayers.Add(playerSearchInstance); } return(listOfPlayers); }