Пример #1
0
 public static string GetCollectionName(int week, int season, SeasonType seasonType)
 {
     return $"s_{season}_w_{week.ToString("D2")}_{seasonType.GetAbbreviation()}";
 }
Пример #2
0
        private async Task<List<Game>> GetGames(int season, SeasonType seasonType)
        {
            var games = new List<Game>();

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", _apiKey);

                var requestUri = $"https://api.fantasydata.net/nfl/v2/json/Schedules/{season}{seasonType.GetAbbreviation(true)}";

                var response = await client.GetAsync(requestUri);

                if (response.IsSuccessStatusCode)
                {
                    var body = await response.Content.ReadAsStringAsync();

                    if (body.Length > 0)
                    {
                        games = DeserializeGames(body);
                    }
                }
            }

            return games;
        }