コード例 #1
0
        public ActionResult GetEvents()
        {
            MeetupEventsModel model = new MeetupEventsModel {
                Items = new MeetupItem[0]
            };

            try {
                string configPath = Server.MapPath("~/config/MeetupUmbracoGroups.txt");
                if (!System.IO.File.Exists(configPath))
                {
                    LogHelper.Debug <MeetupsController>("Config file was not found: " + configPath);
                    return(PartialView("~/Views/Partials/Home/Meetups.cshtml", model));
                }

                // Get the alias (urlname) of each group from the config file
                string[] aliases = System.IO.File.ReadAllLines(configPath).Where(x => x.Trim() != "").Distinct().ToArray();

                model.Items =
                    ApplicationContext.ApplicationCache.RuntimeCache.GetCacheItem <MeetupItem[]>("UmbracoSearchedMeetups",
                                                                                                 () => {
                    // Initialize a new service instance (we don't specify an API key since we're accessing public data)
                    MeetupService service = new MeetupService();

                    List <MeetupItem> items = new List <MeetupItem>();

                    foreach (string alias in aliases)
                    {
                        try {
                            // Get information about the group
                            MeetupGroup group = service.Groups.GetGroup(alias).Body;

                            if (group.JObject.HasValue("next_event"))
                            {
                                string nextEventId = group.JObject.GetString("next_event.id");

                                // Make the call to the Meetup.com API to get upcoming events
                                MeetupGetEventsResponse res = service.Events.GetEvents(alias);

                                // Get the next event(s)
                                MeetupEvent nextEvent = res.Body.FirstOrDefault(x => x.Id == nextEventId);

                                // Append the first event of the group
                                if (nextEvent != null)
                                {
                                    items.Add(new MeetupItem(group, nextEvent));
                                }
                            }
                        } catch (Exception ex) {
                            LogHelper.Error <MeetupsController>("Could not get events from meetup.com for group with alias: " + alias, ex);
                        }
                    }

                    return(items.OrderBy(x => x.Event.Time).ToArray());
                }, TimeSpan.FromMinutes(30));
            } catch (Exception ex) {
                LogHelper.Error <MeetupsController>("Could not get events from meetup.com", ex);
            }

            return(PartialView("~/Views/Partials/Home/Meetups.cshtml", model));
        }
コード例 #2
0
 /// <summary>
 /// Gets a list of events of the group matching the specified <paramref name="options"/>.
 /// </summary>
 /// <param name="options">The options for the request to the API.</param>
 /// <returns>An instance of <see cref="MeetupGetEventsResponse"/> representing the response.</returns>
 public MeetupGetEventsResponse GetEvents(MeetupGetEventsOptions options)
 {
     return(MeetupGetEventsResponse.ParseResponse(Raw.GetEvents(options)));
 }
コード例 #3
0
 /// <summary>
 /// Gets a list of events of the group with the specified <paramref name="urlname"/>.
 /// </summary>
 /// <param name="urlname">The URL name/slug of the group.</param>
 /// <returns>An instance of <see cref="MeetupGetEventsResponse"/> representing the response.</returns>
 public MeetupGetEventsResponse GetEvents(string urlname)
 {
     return(MeetupGetEventsResponse.ParseResponse(Raw.GetEvents(urlname)));
 }
コード例 #4
0
        public void UpdateMeetupStats()
        {
            var configPath = HostingEnvironment.MapPath("~/config/MeetupUmbracoGroups.txt");
            // Get the alias (urlname) of each group from the config file
            var aliases = File.ReadAllLines(configPath).Where(x => x.Trim() != "").Distinct().ToArray();

            var counterPath = HostingEnvironment.MapPath("~/App_Data/TEMP/MeetupStatisticsCounter.txt");
            var counter     = 0;

            if (File.Exists(counterPath))
            {
                var savedCounter = File.ReadAllLines(counterPath).First();
                int.TryParse(savedCounter, out counter);
            }

            var newCounter = aliases.Length <= counter ? 0 : counter + 1;

            File.WriteAllText(counterPath, newCounter.ToString(), Encoding.UTF8);

            var client   = new MeetupClient();
            var response = client.DoHttpGetRequest(string.Format("https://api.meetup.com/{0}/events?page=1000&status=past", aliases[counter]));
            var events   = MeetupGetEventsResponse.ParseResponse(response).Body;

            var meetupCache     = new List <MeetupCacheItem>();
            var meetupCacheFile = HostingEnvironment.MapPath("~/App_Data/TEMP/MeetupStatisticsCache.json");

            if (File.Exists(meetupCacheFile))
            {
                var json = File.ReadAllText(meetupCacheFile);
                using (var stringReader = new StringReader(json))
                    using (var jsonTextReader = new JsonTextReader(stringReader))
                    {
                        var jsonSerializer = new JsonSerializer();
                        meetupCache = jsonSerializer.Deserialize <List <MeetupCacheItem> >(jsonTextReader);
                    }
            }

            foreach (var meetupEvent in events)
            {
                if (meetupCache.Any(x => x.Id == meetupEvent.Id))
                {
                    continue;
                }

                var meetupCacheItem = new MeetupCacheItem
                {
                    Time        = meetupEvent.Time,
                    Created     = meetupEvent.Created,
                    Description = meetupEvent.Description,
                    HasVenue    = meetupEvent.HasVenue,
                    Id          = meetupEvent.Id,
                    Link        = meetupEvent.Link,
                    Name        = meetupEvent.Name,
                    Updated     = meetupEvent.Updated,
                    Visibility  = meetupEvent.Visibility
                };
                meetupCache.Add(meetupCacheItem);
            }

            var rawJson = JsonConvert.SerializeObject(meetupCache, Formatting.Indented);

            File.WriteAllText(meetupCacheFile, rawJson, Encoding.UTF8);
        }