public async Task <IEnumerable <Data.Models.Standing> > RetrieveAll()
        {
            var client = _httpClientFactory.CreateClient();

            client.BaseAddress = new Uri("http://api.football-data.org");
            client.DefaultRequestHeaders.Add("X-Auth-Token", _apiToken);

            var result       = new List <Data.Models.Standing>();
            var competitions = await _competitionProvider.RetrieveAll();

            foreach (var competition in competitions)
            {
                string url      = $"/v2/competitions/{competition.OpenFootyId}/standings";
                var    response = await client.GetStringAsync(url);

                _throttler.Wait();

                var webResult = JsonConvert.DeserializeObject <StandingResponse>(response);
                var mapped    = await _mapper.MapAsync(webResult);

                foreach (var map in mapped)
                {
                    map.SourceCompetitionId = competition.OpenFootyId;
                    map.CompetitionId       = competition.Id;
                }
                result.AddRange(mapped);
            }

            return(result);
        }
        public async Task <IEnumerable <MatchOdds> > RetrieveAll()
        {
            var tasks = new List <Task <IEnumerable <Market> > >();

            using (var countryRequest = BetfairRequest.GetCountries(_authenticator))
            {
                var countries = await countryRequest.Submit <List <Country> >(_httpClient);

                if (countries == null)
                {
                    Console.WriteLine($"[ERROR] Unable to get countries");
                    return(Enumerable.Empty <MatchOdds>());
                }

                Console.WriteLine($"Retrieving data for {countries.Count} countries...");
                int i = 0;
                foreach (var country in countries)
                {
                    Console.WriteLine($"Retrieving odds for {country.CountryCode} [{++i} of {countries.Count}]...");
                    var scopedCountry = country;
                    tasks.Add(scopedCountry.SoccerOdds(_httpClient, _authenticator));
                    _throttler.Wait();
                }
            }

            var odds = Task.WhenAll(tasks).Result.SelectMany(x => x).ToList();

            return(odds.Select(MatchOdds.From));
        }
Esempio n. 3
0
        public String GetString(String url)
        {
            if (Throttle != null)
            {
                Throttle.Wait();
            }
            var request = System.Net.WebRequest.Create(url);

            if (Modifier != null)
            {
                Modifier(request);
            }

            using (var response = request.GetResponse())
                using (StreamReader responseStream = new StreamReader(response.GetResponseStream()))
                {
                    return(responseStream.ReadToEnd());
                }
        }