public static async Task <List <League> > GetLeagues(string CountryName)
        {
            List <League> Leagues = new List <League>();

            string URL = BASE_URL + String.Format(GET_LEAGUES_ENDPOINT, CountryName, DateTime.Now.Year.ToString());

            using (HttpClient client = new HttpClient())
            {
                HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, URL);

                foreach (string[] customHeader in CUSTOM_HEADERS)
                {
                    requestMessage.Headers.Add(customHeader[0].ToString(), customHeader[1].ToString());
                }

                var response = await client.SendAsync(requestMessage);

                string jsonString = await response.Content.ReadAsStringAsync();

                APILeague json = JsonConvert.DeserializeObject <APILeague>(jsonString);

                Leagues = json.api.leagues;
            }
            return(Leagues);
        }
Example #2
0
        public IHttpActionResult GetLeague(int id)
        {
            var league = _repository.GetById(id);

            if (league == null)
            {
                return(NotFound());
            }
            var result = new APILeague(league);

            return(Ok(result));
        }