// Constructor with featureFlag denotes that not all data on the team downward is being populated (think "Team Light") public Team(string teamID, int featureFlag) { NHLTeamID = Convert.ToInt32(teamID); // Create API call URL by appending the team ID to the URL string teamLink = NHLAPIServiceURLs.teams + teamID; var json = DataAccessLayer.ExecuteAPICall(teamLink); var specificTeam = json.SelectToken("teams[0]").ToObject <JObject>(); // Populate the raw JSON to a property teamJson = specificTeam; if (specificTeam.ContainsKey("teamName")) { TeamName = json.SelectToken("teams[0].teamName").ToString(); } if (specificTeam.ContainsKey("abbreviation")) { TeamAbbreviation = json.SelectToken("teams[0].abbreviation").ToString(); } if (specificTeam.ContainsKey("locationName")) { TeamCity = json.SelectToken("teams[0].locationName").ToString(); } if (specificTeam.ContainsKey("firstYearOfPlay")) { FirstYearOfPlay = json.SelectToken("teams[0].firstYearOfPlay").ToString(); } if (specificTeam.ContainsKey("conference")) { //Division - need to implement division class teamConference = new Conference(Convert.ToInt32(json.SelectToken("teams[0].conference.id"))); } if (specificTeam.ContainsKey("division")) { teamDivision = new Division(Convert.ToInt32(json.SelectToken("teams[0].division.id"))); } // Not all venues have an ID in the API (like Maple Leafs Scotiabank Arena), so need to check var venueJson = json.SelectToken("teams[0].venue").ToObject <JObject>(); if (venueJson.ContainsKey("id")) { TeamVenue = new Venue(json.SelectToken("teams[0].venue.id").ToString()); } webSite = json.SelectToken("teams[0].officialSiteUrl").ToString(); }
public static List <Team> GetAllTeams() { var json = DataAccessLayer.ExecuteAPICall(NHLAPIServiceURLs.teams); var teamArray = JArray.Parse(json.SelectToken("teams").ToString()); List <Team> listOfTeams = new List <Team>(); Team tempTeam; foreach (var aTeam in teamArray) { tempTeam = new Team(aTeam.SelectToken("id").ToString()); listOfTeams.Add(tempTeam); } return(listOfTeams); }
public static List <Conference> GetAllConferences() { var json = DataAccessLayer.ExecuteAPICall(NHLAPIServiceURLs.conferences); var conferenceArray = JArray.Parse(json.SelectToken("conferences").ToString()); List <Conference> listOfConferences = new List <Conference>(); Conference tempConference; foreach (var aConference in conferenceArray) { tempConference = new Conference(Convert.ToInt32(aConference.SelectToken("id"))); listOfConferences.Add(tempConference); } return(listOfConferences); }
public static List <Division> GetAllDivisions() { var json = DataAccessLayer.ExecuteAPICall(NHLAPIServiceURLs.divisions); var divisionArray = JArray.Parse(json.SelectToken("divisions").ToString()); List <Division> listOfDivisions = new List <Division>(); Division tempDivision; foreach (var aDivision in divisionArray) { tempDivision = new Division(Convert.ToInt32(aDivision.SelectToken("id"))); listOfDivisions.Add(tempDivision); } return(listOfDivisions); }
public Division(int theDivisionId) { if (theDivisionId == 0) { divisionId = theDivisionId; divisionName = "No Division"; shortName = "NoDiv"; abbreviation = "ND"; active = "N/A"; conference = new Conference(0); } else { divisionId = theDivisionId; string divisionLink = NHLAPIServiceURLs.divisions + divisionId.ToString(); var json = DataAccessLayer.ExecuteAPICall(divisionLink); // Populate the raw JSON to a property divisionJson = json; var keyCheckJson = json.SelectToken("divisions[0]").ToObject <JObject>();; divisionName = json.SelectToken("divisions[0].name").ToString(); //------------------ if (keyCheckJson.ContainsKey("nameShort")) { shortName = json.SelectToken("divisions[0].nameShort").ToString(); } if (keyCheckJson.ContainsKey("abbreviation")) { abbreviation = json.SelectToken("divisions[0].abbreviation").ToString(); } if (keyCheckJson.ContainsKey("conference")) { Conference theConference = new Conference(Convert.ToInt32(json.SelectToken("divisions[0].conference.id"))); conference = theConference; } if (keyCheckJson.ContainsKey("active")) { active = json.SelectToken("divisions[0].active").ToString(); } } }
public Venue(string theVenueID) { // Populate the venueID property venueID = theVenueID; // Get the URL for the API call to a specific Venue string venueLink = NHLAPIServiceURLs.venues + theVenueID; // Execute the API call var json = DataAccessLayer.ExecuteAPICall(venueLink); // Populate the raw JSON to a property venueJson = json; // Populate the rest of the Venue class properties venueName = json.SelectToken("venues[0].name").ToString(); }
public Conference(int theConferenceID) { if (theConferenceID == 0) { conferenceID = theConferenceID; conferenceName = "No Conference"; conferenceAbbreviation = "NC"; shortName = "NoConf"; active = "N/A"; } else { string conferenceLink = NHLAPIServiceURLs.conferences + theConferenceID.ToString(); var json = DataAccessLayer.ExecuteAPICall(conferenceLink); // Populate the JSON feed into a property conferenceJson = json; conferenceID = theConferenceID; JObject detailsJson = new JObject(); detailsJson = json.SelectToken("conferences[0]").ToObject <JObject>(); if (detailsJson.ContainsKey("name") == true) { conferenceName = json.SelectToken("conferences[0].name").ToString(); } if (detailsJson.ContainsKey("abbreviation") == true) { conferenceAbbreviation = json.SelectToken("conferences[0].abbreviation").ToString(); } if (detailsJson.ContainsKey("shortName") == true) { shortName = json.SelectToken("conferences[0].shortName").ToString(); } if (detailsJson.ContainsKey("active") == true) { active = json.SelectToken("conferences[0].active").ToString(); } } }
// Constructor with featureFlag denotes that not all data on the game downward is being populated (think "Game Light") public Game(string theGameID, int featureFlag) { // Populate the gameID property gameID = theGameID; // Get the URL for the API call to a specific Game string theGame = NHLAPIServiceURLs.specificGame; // Replace placeholder value ("###") in the placeholder URL with the requested GameID. gameLink = theGame.Replace("###", theGameID); // Execute the API call var json = DataAccessLayer.ExecuteAPICall(gameLink); // Populate the raw JSON into the gameJson property gameJson = json; // Populate the rest of the Game class properties gameType = json.SelectToken("gameData.game.type").ToString(); season = json.SelectToken("gameData.game.season").ToString(); gameDate = json.SelectToken("gameData.datetime.dateTime").ToString(); abstractGameState = json.SelectToken("gameData.status.abstractGameState").ToString(); codedGameState = json.SelectToken("gameData.status.codedGameState").ToString(); detailedState = json.SelectToken("gameData.status.detailedState").ToString(); statusCode = json.SelectToken("gameData.status.statusCode").ToString(); homeTeam = new Team(json.SelectToken("gameData.teams.home.id").ToString(), featureFlag); awayTeam = new Team(json.SelectToken("gameData.teams.away.id").ToString(), featureFlag); JObject venueObject = JObject.Parse(json.SelectToken("gameData.teams.home.venue").ToString()); if (venueObject.ContainsKey("id")) { gameVenue = new Venue(json.SelectToken("gameData.teams.home.venue.id").ToString()); } //Populate the Box Score if (json.ContainsKey("liveData.boxscore")) { gameBoxScore = new BoxScore(json.SelectToken("gameData.teams.home.id").ToString(), json.SelectToken("gameData.teams.away.id").ToString(), json.SelectToken("liveData.boxscore").ToObject <JObject>(), featureFlag); } }
public static List <string> GetListOfGameIDs(string scheduleDate) { string gameDateScheduleURL = NHLAPIServiceURLs.todaysGames + "?date=" + scheduleDate; var json = DataAccessLayer.ExecuteAPICall(gameDateScheduleURL); List <string> listOfGameIDs = new List <string>(); var scheduleArray = JArray.Parse(json.SelectToken("dates").ToString()); if (scheduleArray.Count > 0) { foreach (var game in scheduleArray[0]["games"]) { listOfGameIDs.Add(game["gamePk"].ToString()); } } return(listOfGameIDs); }
} //Storage of the raw JSON feed // Important URLs: https://statsapi.web.nhl.com/api/v1/schedule?date=2018-11-21 // Default constructor: shows today's schedule public Schedule() { string gameDateScheduleURL = NHLAPIServiceURLs.todaysGames; var json = DataAccessLayer.ExecuteAPICall(gameDateScheduleURL); totalItems = json["totalItems"].ToString(); totalEvents = json["totalEvents"].ToString(); totalGames = json["totalGames"].ToString(); totalMatches = json["totalMatches"].ToString(); List <Game> scheduledGames = new List <Game>(); var scheduleArray = JArray.Parse(json.SelectToken("dates").ToString()); foreach (var game in scheduleArray[0]["games"]) { Game aGame = new Game(game["gamePk"].ToString()); scheduledGames.Add(aGame); } games = scheduledGames; }
public Player(int thePlayerID) { playerID = thePlayerID; // Create API call URL by appending the Player ID to the URL string playerLink = NHLAPIServiceURLs.specificplayer + thePlayerID.ToString(); var json = DataAccessLayer.ExecuteAPICall(playerLink); if (json.ContainsKey("people")) { JObject playerData = JObject.Parse(json.SelectToken("people")[0].ToString()); // Populate the raw JSON to a property playerJson = playerData; if (playerData.ContainsKey("firstName") == true) { firstName = json.SelectToken("people[0].firstName").ToString(); } else { firstName = "UNKNOWN"; } if (playerData.ContainsKey("lastName") == true) { lastName = json.SelectToken("people[0].lastName").ToString(); } else { lastName = "PLAYER"; } if (playerData.ContainsKey("primaryNumber") == true) { primaryNumber = Convert.ToInt32(json.SelectToken("people[0].primaryNumber")); } if (playerData.ContainsKey("birthDate") == true) { birthDate = json.SelectToken("people[0].birthDate").ToString(); } else { birthDate = "1800-01-01"; } if (playerData.ContainsKey("currentAge") == true) { currentAge = Convert.ToInt32(json.SelectToken("people[0].currentAge")); } if (playerData.ContainsKey("birthCity") == true) { birthCity = json.SelectToken("people[0].birthCity").ToString(); } if (playerData.ContainsKey("birthStateProvince") == true) { birthStateProvince = json.SelectToken("people[0].birthStateProvince").ToString(); } if (playerData.ContainsKey("birthCountry") == true) { birthCountry = json.SelectToken("people[0].birthCountry").ToString(); } if (playerData.ContainsKey("nationality") == true) { nationality = json.SelectToken("people[0].nationality").ToString(); } if (playerData.ContainsKey("height") == true) { height = Convert.ToInt32(json.SelectToken("people[0].height").ToString().Split(new char[] { '\'' })[0]) * 12 + Convert.ToInt32(json.SelectToken("people[0].height").ToString().Split(new char[] { '\'' })[1].Split(new char[] { '\"' })[0]); } if (playerData.ContainsKey("weight") == true) { weight = Convert.ToInt32(json.SelectToken("people[0].weight")); } if (playerData.ContainsKey("active") == true) { active = json.SelectToken("people[0].active").ToString(); } else { active = "False"; } if (playerData.ContainsKey("alternateCaptain") == true) { alternateCaptain = json.SelectToken("people[0].alternateCaptain").ToString(); } else { alternateCaptain = "False"; } if (playerData.ContainsKey("captain") == true) { captain = json.SelectToken("people[0].captain").ToString(); } else { captain = "False"; } if (playerData.ContainsKey("rookie") == true) { rookie = json.SelectToken("people[0].rookie").ToString(); } else { rookie = "UNKOWN"; } if (playerData.ContainsKey("shootsCatches") == true) { shootsCatches = json.SelectToken("people[0].shootsCatches").ToString(); } else { shootsCatches = "UNKNOWN"; } if (playerData.ContainsKey("rosterStatus") == true) { rosterStatus = json.SelectToken("people[0].rosterStatus").ToString(); } else { rosterStatus = "UNKNOWN"; } if (playerData.ContainsKey("currentTeam") == true) { currentTeamID = Convert.ToInt32(json.SelectToken("people[0].currentTeam.id")); } if (playerData.ContainsKey("primaryPosition") == true) { primaryPositionCode = json.SelectToken("people[0].primaryPosition.code").ToString(); primaryPositionName = json.SelectToken("people[0].primaryPosition.name").ToString(); primaryPositionType = json.SelectToken("people[0].primaryPosition.type").ToString(); primaryPositionAbbr = json.SelectToken("people[0].primaryPosition.abbreviation").ToString(); } } }
public GameContent(string theGameID) { // Populate the gameID property gameID = theGameID; // Get the URL for the API call to a specific Game string theGame = NHLAPIServiceURLs.specificGameContent.Replace("###", theGameID); // Execute the API call var json = DataAccessLayer.ExecuteAPICall(theGame); // Make sure the JSON returned is not a "NotFound" HTTP message if (json.ContainsKey("message") == false) { // Populate the raw JSON feed to a property gameContentJson = json; // Collect the Game Preview Data var gameContentArray = JArray.Parse(json.SelectToken("editorial.preview.items").ToString()); JObject gCJson = new JObject(json.SelectToken("editorial").ToObject <JObject>()); JObject imageData; JObject previewJson = new JObject(); if (gCJson.ContainsKey("preview") && gameContentArray.Count > 0) { previewJson = JObject.Parse(gCJson.SelectToken("preview.items[0]").ToString()); if (previewJson.ContainsKey("seoTitle") == true) { previewTitle = gameContentArray[0].SelectToken("seoTitle").ToString(); } if (previewJson.ContainsKey("headline") == true) { previewHeadline = gameContentArray[0].SelectToken("headline").ToString(); } if (previewJson.ContainsKey("subhead") == true) { previewSubHead = gameContentArray[0].SelectToken("subhead").ToString(); } if (previewJson.ContainsKey("seoDescription") == true) { previewSeoDescription = gameContentArray[0].SelectToken("seoDescription").ToString(); } if (previewJson.ContainsKey("url") == true) { previewUrl = "http://www.nhl.com" + gameContentArray[0].SelectToken("url").ToString(); } //var imageJson = JObject.Parse(gameContentArray[0].ToString()); var imageJson = JObject.Parse(json.ToString()); if (imageJson.ContainsKey("editorial")) { var imageJson2 = JObject.Parse(imageJson.SelectToken("editorial").ToString()); if (imageJson2.ContainsKey("preview")) { var imageJson3 = JObject.Parse(imageJson2.SelectToken("preview").ToString()); if (imageJson3.ContainsKey("items")) { if (imageJson3.ContainsKey("image")) { //var cutsJson = JObject.Parse(imageJson2.SelectToken("image.cuts").ToString()); //if (cutsJson.ContainsKey("cuts")) //{ //imageData = JObject.Parse(gameContentArray[0].SelectToken("media.image.cuts").ToString()); imageData = JObject.Parse(imageJson2.SelectToken("cuts").ToString()); if (imageData.ContainsKey("2568x1444")) { previewMediaPhoto2568x1444 = imageData.SelectToken("2568x1444.src").ToString(); } if (imageData.ContainsKey("2208x1242")) { previewMediaPhoto2208x1242 = imageData.SelectToken("2208x1242.src").ToString(); } if (imageData.ContainsKey("2048x1152")) { previewMediaPhoto2048x1152 = imageData.SelectToken("2048x1152.src").ToString(); } if (imageData.ContainsKey("1704x960")) { previewMediaPhoto1704x960 = imageData.SelectToken("1704x960.src").ToString(); } if (imageData.ContainsKey("1536x864")) { previewMediaPhoto1536x864 = imageData.SelectToken("1536x864.src").ToString(); } if (imageData.ContainsKey("1284x722")) { previewMediaPhoto1284x722 = imageData.SelectToken("1284x722.src").ToString(); } if (imageData.ContainsKey("1136x640")) { previewMediaPhoto1136x640 = imageData.SelectToken("1136x640.src").ToString(); } if (imageData.ContainsKey("1024x576")) { previewMediaPhoto1024x576 = imageData.SelectToken("1024x576.src").ToString(); } if (imageData.ContainsKey("960x540")) { previewMediaPhoto960x540 = imageData.SelectToken("960x540.src").ToString(); } if (imageData.ContainsKey("768x432")) { previewMediaPhoto768x432 = imageData.SelectToken("768x432.src").ToString(); } if (imageData.ContainsKey("640x360")) { previewMediaPhoto640x360 = imageData.SelectToken("640x360.src").ToString(); } if (imageData.ContainsKey("568x320")) { previewMediaPhoto568x320 = imageData.SelectToken("568x320.src").ToString(); } if (imageData.ContainsKey("372x210")) { previewMediaPhoto372x210 = imageData.SelectToken("372x210.src").ToString(); } if (imageData.ContainsKey("320x180")) { previewMediaPhoto320x180 = imageData.SelectToken("320x180.src").ToString(); } if (imageData.ContainsKey("248x140")) { previewMediaPhoto248x140 = imageData.SelectToken("248x140.src").ToString(); } if (imageData.ContainsKey("124x70")) { previewMediaPhoto124x70 = imageData.SelectToken("124x70.src").ToString(); } } } } } } gameContentArray = JArray.Parse(json.SelectToken("editorial.recap.items").ToString()); //Collect the Game Recap data. if (gCJson.ContainsKey("recap") && gameContentArray.Count > 0) { previewJson = gCJson.SelectToken("recap.items[0]").ToObject <JObject>(); if (previewJson.ContainsKey("seoTitle") == true) { recapTitle = gameContentArray[0].SelectToken("seoTitle").ToString(); } if (previewJson.ContainsKey("headline") == true) { recapHeadline = gameContentArray[0].SelectToken("headline").ToString(); } if (previewJson.ContainsKey("subhead") == true) { recapSubHead = gameContentArray[0].SelectToken("subhead").ToString(); } if (previewJson.ContainsKey("seoDescription") == true) { recapSeoDescription = gameContentArray[0].SelectToken("seoDescription").ToString(); } if (previewJson.ContainsKey("url") == true) { recapUrl = "http://www.nhl.com" + gameContentArray[0].SelectToken("url").ToString(); } //var imageJson = JObject.Parse(gameContentArray[0].ToString()); var imageJson = JObject.Parse(json.SelectToken("highlights").ToString()); if (imageJson.ContainsKey("scoreboard")) { var imageJson2 = JObject.Parse(imageJson.SelectToken("scoreboard").ToString()); if (imageJson2.ContainsKey("items")) { //JArray itemsArray = imageJson.SelectToken("items").ToObject<JArray>(); //var theItems = imageJson2.SelectToken("items").ToString(); if (imageJson2.SelectToken("items").ToObject <JArray>().Count > 0) { var imageJson3 = JObject.Parse(imageJson2.SelectToken("items[0]").ToString()); if (imageJson3.ContainsKey("image")) { var imageJson4 = JObject.Parse(imageJson3.SelectToken("image").ToString()); //if (imageJson4.ContainsKey("cuts")) //{ // imageJson5 = JObject.Parse(imageJson4.SelectToken("cuts").ToString()); //var cutsJson = JObject.Parse(imageJson2.SelectToken("image.cuts").ToString()); //if (cutsJson.ContainsKey("cuts")) //{ //imageData = JObject.Parse(gameContentArray[0].SelectToken("gameCenter.image.cuts").ToString()); imageData = JObject.Parse(imageJson4.SelectToken("cuts").ToString()); if (imageData.ContainsKey("2568x1444")) { recapMediaPhoto2568x1444 = imageData.SelectToken("2568x1444.src").ToString(); } if (imageData.ContainsKey("2208x1242")) { recapMediaPhoto2208x1242 = imageData.SelectToken("2208x1242.src").ToString(); } if (imageData.ContainsKey("2048x1152")) { recapMediaPhoto2048x1152 = imageData.SelectToken("2048x1152.src").ToString(); } if (imageData.ContainsKey("1704x960")) { recapMediaPhoto1704x960 = imageData.SelectToken("1704x960.src").ToString(); } if (imageData.ContainsKey("1536x864")) { recapMediaPhoto1536x864 = imageData.SelectToken("1536x864.src").ToString(); } if (imageData.ContainsKey("1284x722")) { recapMediaPhoto1284x722 = imageData.SelectToken("1284x722.src").ToString(); } if (imageData.ContainsKey("1136x640")) { recapMediaPhoto1136x640 = imageData.SelectToken("1136x640.src").ToString(); } if (imageData.ContainsKey("1024x576")) { recapMediaPhoto1024x576 = imageData.SelectToken("1024x576.src").ToString(); } if (imageData.ContainsKey("960x540")) { recapMediaPhoto960x540 = imageData.SelectToken("960x540.src").ToString(); } if (imageData.ContainsKey("768x432")) { recapMediaPhoto768x432 = imageData.SelectToken("768x432.src").ToString(); } if (imageData.ContainsKey("640x360")) { recapMediaPhoto640x360 = imageData.SelectToken("640x360.src").ToString(); } if (imageData.ContainsKey("568x320")) { recapMediaPhoto568x320 = imageData.SelectToken("568x320.src").ToString(); } if (imageData.ContainsKey("372x210")) { recapMediaPhoto372x210 = imageData.SelectToken("372x210.src").ToString(); } if (imageData.ContainsKey("320x180")) { recapMediaPhoto320x180 = imageData.SelectToken("320x180.src").ToString(); } if (imageData.ContainsKey("248x140")) { recapMediaPhoto248x140 = imageData.SelectToken("248x140.src").ToString(); } if (imageData.ContainsKey("124x70")) { recapMediaPhoto124x70 = imageData.SelectToken("124x70.src").ToString(); } //recapPlaybackFLASH_192K_320X180 = gameContentArray[0].SelectToken("tokendata.").ToString(); // Need to add: Recap Flash Videos, Line Score 17111 (see line 15882: liveData.linescore), Boxscore (see line 15992: liveData.boxscore), Decisions (see line 17810: liveData.decisions //} } } } } } } }
// NOTE: Parameter format for date is YYYY-MM-DD public Schedule(string gameDate) { string gameDateScheduleURL = NHLAPIServiceURLs.todaysGames + "?date=" + gameDate; var json = DataAccessLayer.ExecuteAPICall(gameDateScheduleURL); // Populate the raw JSON feed to the scheduleJson property. scheduleJson = json; if (json.ContainsKey("totalItems")) { totalItems = json["totalItems"].ToString(); } else { totalItems = "0"; } if (json.ContainsKey("totalEvents")) { totalEvents = json["totalEvents"].ToString(); } else { totalEvents = "0"; } if (json.ContainsKey("totalGames")) { totalGames = json["totalGames"].ToString(); } else { totalGames = "0"; } if (json.ContainsKey("totalMatches")) { totalMatches = json["totalMatches"].ToString(); } else { totalMatches = "0"; } scheduleDate = gameDate; List <Game> scheduledGames = new List <Game>(); var scheduleArray = JArray.Parse(json.SelectToken("dates").ToString()); // If the day has schedule games, add them to the object. if (scheduleArray.Count > 0) { foreach (var game in scheduleArray[0]["games"]) { Game aGame = new Game(game["gamePk"].ToString()); scheduledGames.Add(aGame); if (season == "" || season == null) { season = aGame.season; } } games = scheduledGames; } }
// Constructor for Game class from a specific Game ID public Game(string theGameID) { // Populate the gameID property gameID = theGameID; // Get the URL for the API call to a specific Game string theGame = NHLAPIServiceURLs.specificGame; // Replace placeholder value ("###") in the placeholder URL with the requested GameID. gameLink = theGame.Replace("###", theGameID); // Execute the API call var json = DataAccessLayer.ExecuteAPICall(gameLink); // Populate the raw JSON into the gameJson property gameJson = json; // Populate the rest of the Game class properties gameType = json.SelectToken("gameData.game.type").ToString(); season = json.SelectToken("gameData.game.season").ToString(); gameDate = json.SelectToken("gameData.datetime.dateTime").ToString(); abstractGameState = json.SelectToken("gameData.status.abstractGameState").ToString(); codedGameState = json.SelectToken("gameData.status.codedGameState").ToString(); detailedState = json.SelectToken("gameData.status.detailedState").ToString(); statusCode = json.SelectToken("gameData.status.statusCode").ToString(); homeTeam = new Team(json.SelectToken("gameData.teams.home.id").ToString()); awayTeam = new Team(json.SelectToken("gameData.teams.away.id").ToString()); JObject venueJson = JObject.Parse(json.SelectToken("gameData.teams.home").ToString()); if (venueJson.ContainsKey("venue")) { JObject venueObject = JObject.Parse(json.SelectToken("gameData.teams.home.venue").ToString()); if (venueObject.ContainsKey("id")) { gameVenue = new Venue(json.SelectToken("gameData.teams.home.venue.id").ToString()); } } // If the Abstract Game State is "Live" or "Final", populate the in-game data. if (abstractGameState != "Preview") { var periodInfo = JArray.Parse(json.SelectToken("liveData.linescore.periods").ToString()); Period tempPeriod; periodData = new List <Period>(); // If there is period data, populate the list of periods. if (periodInfo.Count > 0) { foreach (var period in periodInfo) { tempPeriod = new Period(gameID, (JObject)period, homeTeam.NHLTeamID.ToString(), awayTeam.NHLTeamID.ToString()); periodData.Add(tempPeriod); } } //Populate the Box Score if it exists if (!(json.SelectToken("liveData.boxscore") is null)) { gameBoxScore = new BoxScore(json.SelectToken("gameData.teams.home.id").ToString(), json.SelectToken("gameData.teams.away.id").ToString(), json.SelectToken("liveData.boxscore").ToObject <JObject>()); } // Populating the players // Create a JSON //var playerJson = JObject.Parse(json.SelectToken("gameData.players").ToString()); //IList<JToken> results = playerJson.Children().ToList(); IList <JToken> results = JObject.Parse(json.SelectToken("gameData.players").ToString()).Children().ToList(); // Create a placeholder List<Player> for populating the game roster List <Player> playerList = new List <Player>(); // Add each player to the List<Player> placeholder if (results.Children().Count() > 0) { foreach (JToken result in results.Children()) { playerList.Add(new Player(Convert.ToInt32(result["id"]))); } } // Populate gameParticipants property with List<Player> placeholder. if (playerList.Count > 0) { gameParticipants = playerList; } var gameEventsJson = JArray.Parse(json.SelectToken("liveData.plays.allPlays").ToString()); GameEvent aGameEvent = new GameEvent(); gameEvents = new List <GameEvent>(); if (gameEventsJson.Count > 0) { foreach (var item in gameEventsJson) { aGameEvent = new GameEvent(item); gameEvents.Add(aGameEvent); } } } gameContent = new GameContent(theGameID); }
// METHOD: GetCurrentStandings // Inputs: None // Outputs: A list of teams in the leage ranked by first to last // API URL: https://statsapi.web.nhl.com/api/v1/standings/byLeague public static List <TeamRecord> GetCurrentStandings(string season) { JObject leagueJson; // Set up API call string (including season if the season parameter is not empty. string standingsAPICall; if (season != "") { standingsAPICall = NHLAPIServiceURLs.leagueStandings + NHLAPIServiceURLs.leagueStandings_season_extension + season; } else { standingsAPICall = NHLAPIServiceURLs.leagueStandings; } // Initialize the list of teams to return List <TeamRecord> teamList = new List <TeamRecord>(); /*var client = new System.Net.Http.HttpClient(); * * var response = client.GetAsync(standingsAPICall).Result; * var retResp = new HttpResponseMessage(); * var stringResult = response.Content.ReadAsStringAsync().Result; * var json = JObject.Parse(stringResult);*/ // Get Current League Standings from NHL API var json = DataAccessLayer.ExecuteAPICall(standingsAPICall); // Populate the raw JSON to a property leagueJson = json; TeamRecord newTeam = new TeamRecord(); IList <JToken> results = json["records"][0]["teamRecords"].Children().ToList(); JObject keyTest; string seasonYear; string seasonMonth; string seasonDay; DateTime dtString; foreach (JToken result in results) { keyTest = result.ToObject <JObject>(); // Put the values in the results list into a new Team object. newTeam.NHLTeamID = Convert.ToInt32(result["team"]["id"]); newTeam.TeamName = result["team"]["name"].ToString(); newTeam.Wins = Convert.ToInt32(result["leagueRecord"]["wins"]); newTeam.Losses = Convert.ToInt32(result["leagueRecord"]["losses"]); newTeam.OvertimeLosses = Convert.ToInt32(result["leagueRecord"]["ot"]); newTeam.regulationWins = Convert.ToInt32(result["regulationWins"]); newTeam.GoalsAgainst = Convert.ToInt32(result["goalsAgainst"]); newTeam.GoalsScored = Convert.ToInt32(result["goalsScored"]); newTeam.Points = Convert.ToInt32(result["points"]); newTeam.DivisionRank = Convert.ToInt32(result["divisionRank"]); newTeam.DivisionL10Rank = Convert.ToInt32(result["divisionL10Rank"]); newTeam.DivisionHomeRank = Convert.ToInt32(result["divisionHomeRank"]); newTeam.DivisionRoadRank = Convert.ToInt32(result["divisionRoadRank"]); newTeam.ConferenceRank = Convert.ToInt32(result["conferenceRank"]); newTeam.ConferenceL10Rank = Convert.ToInt32(result["conferenceL10Rank"]); newTeam.ConferenceHomeRank = Convert.ToInt32(result["conferenceHomeRank"]); newTeam.ConferenceRoadRank = Convert.ToInt32(result["conferenceRoadRank"]); newTeam.LeagueRank = Convert.ToInt32(result["leagueRank"]); newTeam.WildcardRank = Convert.ToInt32(result["wildcardRank"]); newTeam.ROW = Convert.ToInt32(result["row"]); newTeam.GamesPlayed = Convert.ToInt32(result["gamesPlayed"]); newTeam.StreakType = result["streak"]["streakType"].ToString(); newTeam.StreakNumber = Convert.ToInt32(result["streak"]["streakNumber"]); newTeam.StreakCode = result["streak"]["streakCode"].ToString(); if (keyTest.ContainsKey("clinchIndicator")) { newTeam.clinchIndicator = result["clinchIndicator"].ToString(); } else { newTeam.clinchIndicator = "N/A"; } newTeam.LastUpdated = result["lastUpdated"].ToString(); dtString = Convert.ToDateTime(newTeam.LastUpdated); if (season != "") { newTeam.season = season; } else { seasonYear = dtString.Year.ToString(); if (dtString.Month < 10) { seasonMonth = "0" + dtString.Month.ToString(); } else { seasonMonth = dtString.Month.ToString(); } if (dtString.Day < 10) { seasonDay = "0" + dtString.Day.ToString(); } else { seasonDay = dtString.Day.ToString(); } newTeam.season = Utilities.GetSeasonFromDate(seasonYear + "-" + seasonMonth + "-" + seasonDay); } // Add the newly-populated newTeam object to the Team List. teamList.Add(newTeam); newTeam = new TeamRecord(); } return(teamList); }