// 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);
        }
        // May 22, 2019 status: this works
        // https://appac.github.io/mlb-data-api-docs/#player-data-player-teams-get
        // _pT.GetTeamsForPlayerAllSeasons("493316");
        // http://lookup-service-prod.mlb.com/json/named.player_teams.bam?player_id='493316'
        // MlbDataEndPoint newEndPoint = _endPoints.PlayerTeamsEndPoint("493316");
        public List <PlayerTeam> GetTeamsForPlayerAllSeasons(string playerId)
        {
            MlbDataEndPoint newEndPoint     = _endPoints.PlayerTeamsEndPoint(playerId);
            PostmanRequest  postmanRequest  = _postman.CreatePostmanRequest(newEndPoint, "PlayerTeams");
            PostmanResponse postmanResponse = _postman.GetPostmanResponse(postmanRequest);
            IRestResponse   response        = postmanResponse.Response;

            // jObject is all of the json: 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");
            // JToken allTeamValues = jObject["player_teams"]["queryResults"]["row"];

            List <PlayerTeam> ptList = new List <PlayerTeam>();

            for (var teamIndex = 0; teamIndex <= totalSize - 1; teamIndex++)
            {
                PlayerTeam pTeam = new PlayerTeam();

                var pTeamInstance = _apI.CreateInstanceOfModel(allTeamValuesJToken[teamIndex], pTeam, "PlayerTeam") as PlayerTeam;
                ptList.Add(pTeamInstance);
            }
            // Console.WriteLine($"ptList Count: {ptList.Count}");
            return(ptList);
        }
Exemplo n.º 3
0
        // /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);
        }