예제 #1
0
        public async Task <TokenInfoModel> GetTokenInfo(string userToken)
        {
            if (string.IsNullOrEmpty(userToken))
            {
                throw new ArgumentNullException(nameof(userToken));
            }

            var path            = $"debug_token";
            var queryParameters = new Dictionary <string, string> {
                ["input_token"] = userToken
            };
            var data = await RequestService.GetAsync(path, queryParameters, appendToken : true);

            var jObject = JObject.Parse(data)["data"];

            var issuedAt  = (int?)jObject["issued_at"];
            var tokenInfo = new TokenInfoModel
            {
                TokenPortion = $"{userToken.Substring(0, 10)}...",
                RequestedUtc = issuedAt.HasValue ? DotnetExtensions.FromEpochTime(issuedAt.Value) : default(DateTime?),
                ExpiresUtc   = DotnetExtensions.FromEpochTime((int)jObject["expires_at"]),
            };

            return(tokenInfo);
        }
예제 #2
0
        public async Task <Participation> GetEventAttendeesById(long eventId)
        {
            var queryParameters = new Dictionary <string, string> {
                ["limit"] = "100000"
            };
            var goingPath         = $"/{eventId}/attending";
            var interestedPath    = $"/{eventId}/interested";
            var goingTask         = RequestService.GetAsync(goingPath, queryParameters);
            var interestedTask    = RequestService.GetAsync(interestedPath, queryParameters);
            var goingData         = await goingTask;
            var interestedData    = await interestedTask;
            var goingJObject      = JObject.Parse(goingData);
            var interestedJObject = JObject.Parse(interestedData);

            var attendingList  = ParseAttendeeData(goingJObject).ToList();
            var interestedList = ParseAttendeeData(interestedJObject).ToList();

            return(new Participation
            {
                Attending = attendingList,
                Interested = interestedList,
                AttendingCount = attendingList.Count,
                InterestedCount = interestedList.Count
            });

            IEnumerable <Attendee> ParseAttendeeData(JObject jData)
            {
                return(jData["data"].Select(d => new Attendee
                {
                    Name = (string)d["name"],
                    Id = (string)d["id"],
                    RSVPStatus = (string)d["rsvp_status"]
                }));
            }
        }
예제 #3
0
        public async Task <VenueModel> GetEventsByVenue(string venueName)
        {
            var path = $"/{venueName}/events";
            var data = await RequestService.GetAsync(path);

            var jObject = JObject.Parse(data);
            var venue   = new VenueModel
            {
                Name   = venueName,
                Events = jObject["data"].Select(e =>
                {
                    var hasEnd  = DateTime.TryParse((string)e["end_time"], out DateTime x);
                    var endTime = hasEnd ? x as DateTime? : null;
                    return(new EventModel
                    {
                        Id = (string)e["id"],
                        Name = (string)e["name"],
                        Location = (string)e.SelectToken("place.name"),
                        Description = (string)e["description"],
                        StartTime = (DateTime)e["start_time"],
                        EndTime = endTime,
                        VenueName = venueName
                    });
                })
                         .Where(e => e.EndTime >= DateTime.Now).OrderBy(e => e.StartTime).ToList()
            };

            return(venue);
        }
예제 #4
0
        public async Task <Participation> GetEventAttendeeCountsById(string eventId)
        {
            var interestedPath  = $"{eventId}";
            var queryParameters = new Dictionary <string, string> {
                ["fields"] = "attending_count,declined_count,interested_count,maybe_count,noreply_count"
            };

            var interestedData = await RequestService.GetAsync(interestedPath, queryParameters);

            var interestedJObject = JObject.Parse(interestedData);

            return(new Participation
            {
                AttendingCount = (int)interestedJObject["attending_count"],
                InterestedCount = (int)interestedJObject["interested_count"]
            });
        }