// PRIMARY METHOD: OPTION 1 // STATUS [ June 9, 2019 ] : this works /// <summary> /// Create instance of yahoo team model; save it to the database /// </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 teamBase = CreateYahooTeamResourceInstance(7); /// </example> public YahooTeamResource CreateYahooTeamResourceInstance(int managerId) { // _h.StartMethod(); YahooTeamResource tB = new YahooTeamResource(); string leagueKey = _yahooApiRequestController.GetTheGameIsTheGameLeagueKey(); var uriTeamBase = endPoints.TeamResourceEndPoint(leagueKey, managerId).EndPointUri; // Console.WriteLine($"MANAGER CONTROLLER > leagueKey: {leagueKey}"); Console.WriteLine($"uriTeamBase: {uriTeamBase}"); // for each team in the league, dig through their team json, find the required items to create the new YahooTeamBase and set those items JObject resourceJson = _yahooApiRequestController.GenerateYahooResourceJObject(uriTeamBase); PopulateInitialTeamResourceInstanceProperties(tB, resourceJson); // Managers is nested under 'teamBasePath' var managerPath = resourceJson["fantasy_content"]["team"]["managers"]["manager"]; // The type under 'manager' will indicate if the team has one manager or co-managers // Type for one manager = "Newtonsoft.Json.Linq.JObject" // Type for co-managers = "Newtonsoft.Json.Linq.JArray" var managerPathChildrenType = managerPath.GetType().ToString(); const string jObjectType = "Newtonsoft.Json.Linq.JObject"; const string jArrayType = "Newtonsoft.Json.Linq.JArray"; // One manager path if (string.Equals(managerPathChildrenType, jObjectType, StringComparison.Ordinal)) { PopulateTeamResourceInstanceWithOneManager(tB, managerPath); } // Co-manager path List <YahooManager> teamManagersList = new List <YahooManager>(); tB.TeamManagersList = new List <YahooManager>(); if (string.Equals(managerPathChildrenType, jArrayType, StringComparison.Ordinal)) { PopulateTeamBaseWithCoManagers(tB, managerPath, teamManagersList); } _h.Dig(tB); // _h.CompleteMethod(); return(tB); }
private YahooPlayersCollection CreatePlayersCollectionInstance(string uriPlayersCollection) { JObject collectionJObject = _yahooApiRequestController.GenerateYahooResourceJObject(uriPlayersCollection); // _h.Dig(collectionJObject); JToken yahooPlayersCollectionToken = collectionJObject["fantasy_content"]["league"]; string playersCollectionString = yahooPlayersCollectionToken.ToString(); YahooPlayersCollection playersCollection = YahooPlayersCollection.FromJson(playersCollectionString); // PrintPlayerNameAndTeamName(playersCollectionString); return(playersCollection); }
// STATUS [ June 10, 2019 ] : this works /// <summary> /// Instantiate new instance of yahoo player resource /// </summary> /// <param name="yahooPlayerId"> /// The Mlb players yahoo player id /// Typically four or five numbers but fed to method as a string /// E.g., "8967" instead of 8967 /// </param> /// <remarks> /// If you do not know the yahoo id, try the 'GetYahooPlayersIdFromPlayerName()' method to get it /// </remarks> /// <example> /// var yahooPlayerResourceModel = CreateYahooPlayerResourceInstances("8967"); /// </example> public YahooPlayerResource CreateYahooPlayerResourceInstances(string yahooPlayerId) { // string leagueKey = _yahooApiRequestController.GetTheGameIsTheGameLeagueKey(); // Console.WriteLine($"YAHOO RESOURCE CONTROLLER > leagueKey: {leagueKey}"); const string keyPrefix = "mlb.p."; string playerKey = $"{keyPrefix}{yahooPlayerId}"; // e.g., https://fantasysports.yahooapis.com/fantasy/v2/player/mlb.p.8967 var uriPlayer = _endPoints.PlayerBaseEndPoint(playerKey).EndPointUri; JObject playerJObject = _yahooApiRequestController.GenerateYahooResourceJObject(uriPlayer); JToken playerResource = playerJObject["fantasy_content"]["player"]; string playerResourceString = playerResource.ToString(); YahooPlayerResource yPlayerResource = JsonConvert.DeserializeObject <YahooPlayerResource>(playerResourceString); _helpers.Dig(yPlayerResource); return(yPlayerResource); }