Пример #1
0
 private HttpClient GetClient(LadderRegion region)
 {
     return new HttpClient
     {
         BaseAddress = new Uri(String.Format(@"http://{0}.battle.net/api/sc2/", region.RegionCode()), UriKind.Absolute)
     };
 }
Пример #2
0
        public async Task<IEnumerable<Match>> GetRecentMatchesForPlayer(string profilePath, LadderRegion region)
        {
            var client = GetClient(region);
            var responseMessage = await client.GetAsync(String.Format(@"{0}{1}", profilePath, @"matches").TrimStart('/'));
            if (!responseMessage.IsSuccessStatusCode)
            {
                //TODO: Logging
                return new List<Match>();
            }
            var responseString = await responseMessage.Content.ReadAsStringAsync();
            
            var objects = await JsonConvert.DeserializeObjectAsync<MatchHistory>(responseString);

            return objects.Matches;
        }
Пример #3
0
        public async Task<IEnumerable<LadderMember>> GetGrandmasterMembers(LadderRegion region)
        {
            var client = GetClient(region);
            var response = await client.GetAsync(new Uri("ladder/grandmaster", UriKind.Relative));
            if (!response.IsSuccessStatusCode)
            {
                //TODO: Logging
                return new List<LadderMember>();
            }

            var responseString = await response.Content.ReadAsStringAsync();
            var objects = await JsonConvert.DeserializeObjectAsync<Ladder>(responseString);

            return objects.LadderMembers;
        }
Пример #4
0
        private List<LadderMember> GetGmPlayersWithMatchesForRegion(LadderRegion region = LadderRegion.NorthAmerica)
        {
            var api = new ApiWrapper();

            var ladderMembers = api.GetGrandmasterMembers(region).Result.ToList();

            var count = 0;
            foreach (var ladderMember in ladderMembers)
            {
                Console.WriteLine("Processing: " + ladderMember.Character.DisplayName + " Count: " + count++);
                var matches = api.GetRecentMatchesForPlayer(ladderMember.Character.ProfilePath, region).Result.ToList();
                ladderMember.Matches = matches;
                ladderMember.LadderRegion = region;
            }

            return ladderMembers;
        }