public YahooTeamPoints CreateYahooTeamPointsModel()
        {
            _h.StartMethod();
            YahooTeamPoints yTP = new YahooTeamPoints();

            // TEAMID --> A number between 0 and the total number of teams in the league with each number in between representing one of the teams (i.e., each team has its own unique team id number)
            const int teamId = 1;

            string uriTeamBase = endPoints.TeamSeasonStatsEndPoint(_theGameConfig.LeagueKey, teamId).EndPointUri;

            JObject teamStatsJson = _yahooApiRequestController.GenerateYahooResourceJObject(uriTeamBase);

            JToken teamPointsPath = teamStatsJson["fantasy_content"]["team"]["team_points"];
            // var teamPointsPath         = o["fantasy_content"]["team"]["team_points"];
            string teamPointsCoverageType = yTP.CoverageType = teamPointsPath["coverage_type"].ToString();

            if (string.Equals(teamPointsCoverageType, "season", StringComparison.Ordinal))
            {
                yTP.WeekOrYear = (int?)teamPointsPath["season"];
            }

            if (string.Equals(teamPointsCoverageType, "week", StringComparison.Ordinal))
            {
                yTP.WeekOrYear = (int?)teamPointsPath["week"];
            }

            yTP.Total = (int?)teamPointsPath["total"];

            return(yTP);
        }
        // PRIMARY METHODS offers 3 options to instantiate a new yahoo stats model
        // OPTION 1 - endpoint parameters defined within the method
        // OPTION 2 - endpoint parameters passed as parameters to method
        // OPTION 3 - endpoint parameters are appended to the Url


        // OPTION 1: endpoint parameters defined within the method
        // STATUS [ June 9, 2019 ] : this works
        /// <summary>
        ///     Create new instance of YahooTeamStats Model
        ///     Show full season stats for one team
        /// </summary>
        /// <remarks>
        ///     This is the least helpful option of the method
        ///     Within Option 1, the 'teamId' is defined within the method itself
        ///     To change the team Id you're searching for, change the 'teamId' variable;
        ///     Includes: H/AB, R, HR, RBI, SB, BB, IP, W, SV, H, ERA, WHIP
        ///     Relies on 'PopulateTeamStatsProperties()' to populate model properties
        /// </remarks>
        /// <example>
        ///     https://127.0.0.1:5001/api/yahoo/teamstats
        /// </example>
        /// <returns>
        ///     New YahooTeamStatsModel
        /// </returns>
        public YahooTeamStatsList CreateYahooTeamStatsModel()
        {
            // _h.Spotlight("executing create yahoo team stats method option 1");
            const int teamId      = 1;
            string    leagueKey   = _yahooApiRequestController.GetTheGameIsTheGameLeagueKey();
            string    uriTeamBase = endPoints.TeamSeasonStatsEndPoint(leagueKey, teamId).EndPointUri;

            JObject teamStatsJson = _yahooApiRequestController.GenerateYahooResourceJObject(uriTeamBase);

            YahooTeamStatsList tS = PopulateTeamStatsProperties(teamStatsJson);

            _helpers.Dig(tS);
            return(tS);
        }
Exemplo n.º 3
0
        // 1 : DJB
        // 2 : DSch
        // 3 : CSt
        // 4 : SpMc
        // 5 : PJB
        // 6 : JB
        // 7 : Pants
        // 8 : JCuz
        // 9 : DBra
        // 10: MC

        #region YAHOO MANAGER - PRIMARY METHODS ------------------------------------------------------------


        // STATUS [ June 8, 2019 ] : this works
        /// <summary>
        ///     Instantiate new instance of a yahoo manager
        ///     The manager data in the requested json is found nested under league standings
        /// </summary>
        /// <param name="managerId">
        ///     A number 0 - X; Where X is the total number of teams in the league;
        ///     Basically every manager has their own single number Id;
        ///     Select the Id of the Manager you would want to view
        /// </param>
        /// <example>
        ///     var yahooManager = CreateYahooManagerModel(1);
        /// </example>
        /// <returns>
        ///     A new YahooManager
        /// </returns>
        public YahooManager CreateYahooManagerModel(int managerId)
        {
            // _h.StartMethod();
            string leagueKey = _yahooApiRequestController.GetTheGameIsTheGameLeagueKey();
            // Console.WriteLine($"MANAGER CONTROLLER > leagueKey: {leagueKey}");

            // Create the uri that will be used to generate the appropriate json
            // Use Lg. Standings endpoint because mgr. details are nested in league standings json
            var uriLeagueStandings = _endPoints.LeagueStandingsEndPoint(leagueKey).EndPointUri;

            JObject leagueStandings = _yahooApiRequestController.GenerateYahooResourceJObject(uriLeagueStandings);

            YahooManager yM = new YahooManager
            {
                // these pull from the yahoo response (xml or json) to set each item
                ManagerId = _endPoints.TeamItem(leagueStandings, managerId, "ManagerId"),
                NickName  = _endPoints.TeamItem(leagueStandings, managerId, "Nickname"),
                Guid      = _endPoints.TeamItem(leagueStandings, managerId, "Guid"),
            };

            // Only the commish of the league will have  the "IsCommissioner" field
            try { yM.IsCommissioner = _endPoints.TeamItem(leagueStandings, managerId, "IsCommissioner"); }
            catch (Exception ex) { Console.WriteLine("ERROR IN: YahooManagerController.CreateYahooManagerModel() --> user not the commish"); }


            // "IsCurrentLogin" will only return data of current user is fetching their league's data
            try { yM.IsCurrentLogin = _endPoints.TeamItem(leagueStandings, managerId, "IsCurrentLogin"); }
            catch (Exception ex)
            { Console.WriteLine("ERROR IN: YahooManagerController.CreateYahooManagerModel() --> user not looged in "); }


            // Yahoo managers can hide their email; if hidden, you'll get an error
            try { yM.Email = _endPoints.TeamItem(leagueStandings, managerId, "Email"); }
            catch (Exception ex)
            { Console.WriteLine("ERROR IN: YahooManagerController.CreateYahooManagerModel() --> User has no email"); }

            yM.ImageUrl = _endPoints.TeamItem(leagueStandings, managerId, "ImageUrl");
            // PrintYahooManagerDetails(yM);
            return(yM);
        }
        // TO-DO: add XML summary comments
        // Step 1
        public void CreateYahooLeagueScoreboard()
        {
            _h.StartMethod();

            // retrieve the league key from user secrets / yahoo league config
            string leagueKey = _yahooApiRequestController.GetTheGameIsTheGameLeagueKey();

            string uriLeagueScoreboard = endPoints.LeagueSeasonScoreboardEndPoint(leagueKey).EndPointUri;

            JObject leagueScoreboard = _yahooApiRequestController.GenerateYahooResourceJObject(uriLeagueScoreboard);

            _h.PrintJObjectItems(leagueScoreboard);
        }
        public YahooTeamStanding CreateYahooTeamStandingModel()
        {
            _h.StartMethod();

            // retrieve the league key from user secrets / yahoo league config
            string leagueKey = _theGameConfig.LeagueKey;

            Console.WriteLine($"leagueKey: {leagueKey}");

            // create the uri that will be used to generate the appropriate json; in this case, it's the League Standings endpoint (view YahooApiEndPoints.cs)
            var uriLeagueStandings = endPoints.LeagueStandingsEndPoint(leagueKey).EndPointUri;

            Console.WriteLine($"uriLeagueStandings: {uriLeagueStandings}");

            JObject   leagueStandings = _yahooApiRequestController.GenerateYahooResourceJObject(uriLeagueStandings);
            const int teamsInLeague   = 10;

            YahooTeamStanding yS = new YahooTeamStanding();

            for (var teamId = 0; teamId <= teamsInLeague - 1; teamId++)
            {
                yS.Rank                     = endPoints.TeamItem(leagueStandings, 0, "Rank");
                yS.PlayoffSeed              = endPoints.TeamItem(leagueStandings, 0, "PlayoffSeed");
                yS.GamesBack                = endPoints.TeamItem(leagueStandings, 0, "GamesBack");
                yS.OutcomeTotals.Wins       = endPoints.TeamItem(leagueStandings, 0, "Wins");
                yS.OutcomeTotals.Losses     = endPoints.TeamItem(leagueStandings, 0, "Losses");
                yS.OutcomeTotals.Ties       = endPoints.TeamItem(leagueStandings, 0, "Ties");
                yS.OutcomeTotals.Percentage = endPoints.TeamItem(leagueStandings, 0, "WinningPercentage");

                Console.WriteLine($"TEAM STANDINGS FOR TEAM ID {teamId}");
                Console.WriteLine(yS);
                Console.WriteLine();
            }
            // int X = 0;

            // var leagueStandingsTeamsTeamX = leagueStandings["fantasy_content"]["league"]["standings"]["teams"]["team"][X];

            // Console.WriteLine(leagueStandingsTeamsTeamX["team_stats"].GetType());

            return(yS);
        }