Esempio n. 1
0
        private static EventsTimeline GetMatchTimeline(long gameId, string region, int participantId)
        {
            var pathBuilder = new UrlPathBuilder();
            var timeline    = new EventsTimeline();

            using (var client = new HttpClient())
            {
                try
                {
                    client.DefaultRequestHeaders.Add("X-Riot-Token", ConfigWrapper.ApiKey);
                    var response = client.GetAsync(new Uri(pathBuilder.GetMatchTimelineUrl(gameId, region)));
                    response.Wait();

                    if (response.Result.IsSuccessStatusCode)
                    {
                        var readData = response.Result.Content.ReadAsStringAsync();
                        readData.Wait();

                        var jsonObject = JObject.Parse(readData.Result);
                        foreach (var frame in jsonObject["frames"])
                        {
                            var events    = frame.Children <JProperty>().FirstOrDefault(x => x.Name == "events");
                            var timestamp = frame.Children <JProperty>().FirstOrDefault(x => x.Name == "timestamp");

                            if (events == null || timestamp == null)
                            {
                                return(null);
                            }

                            var intervalTimestamp = timestamp.Value.ToObject <long>();
                            var matchEvents       = events.Value.ToObject <List <MatchEvent> >();

                            var eventsInsideTimestampWindow = new List <MatchEvent>();
                            foreach (var e in matchEvents)
                            {
                                if (e.Type == "ITEM_PURCHASED" && e.ParticipantId == participantId)
                                {
                                    e.ItemUrl = pathBuilder.GetItemIcon(e.ItemId);
                                    eventsInsideTimestampWindow.Add(e);
                                }
                                if (e.Type == "SKILL_LEVEL_UP" && e.ParticipantId == participantId)
                                {
                                    timeline.SkillEvents.Add(e);
                                }
                            }
                            timeline.ItemPurchaseEventsByTimestamp.Add(intervalTimestamp, eventsInsideTimestampWindow);
                        }
                    }
                    return(timeline);
                }
                catch (Exception) { return(null); }
            }
        }
Esempio n. 2
0
        private static Inventory GetItems(Participant participant)
        {
            var pathBuilder = new UrlPathBuilder();

            return(new Inventory()
            {
                Item0Url = pathBuilder.GetItemIcon(participant.Stats.Item0),
                Item1Url = pathBuilder.GetItemIcon(participant.Stats.Item1),
                Item2Url = pathBuilder.GetItemIcon(participant.Stats.Item2),
                Item3Url = pathBuilder.GetItemIcon(participant.Stats.Item3),
                Item4Url = pathBuilder.GetItemIcon(participant.Stats.Item4),
                Item5Url = pathBuilder.GetItemIcon(participant.Stats.Item5),
                Item6Url = pathBuilder.GetItemIcon(participant.Stats.Item6),
            });
        }