Exemple #1
0
        public async Task <bool> CheckMenuChanged()
        {
            try
            {
                CafetApiResponse resp = await Api.FetchMenu();

                IDatabase db      = _redis.GetDatabase(0, new object());
                string    lasturl = await db.StringGetAsync(LastFetchKey);

                await db.StringSetAsync(LastFetchKey, resp.FetchURL);

                if (lasturl == null || lasturl == resp.FetchURL)
                {
                    return(false);
                }

                await Notify(resp);

                return(true);
            }
            catch (HttpRequestException ex)
            {
                System.Console.WriteLine("Could not fetch menu:");
                System.Console.WriteLine(ex);
                return(false);
            }
        }
Exemple #2
0
        public static async Task <CafetApiResponse> FetchMenu()
        {
            var resp = await _client.GetAsync(_host);

            resp.EnsureSuccessStatusCode();

            CafetApiResponse caf = JsonConvert.DeserializeObject <CafetApiResponse>(await resp.Content.ReadAsStringAsync());

            return(caf);
        }
Exemple #3
0
        private async Task Notify(CafetApiResponse resp)
        {
            ISubscriber sub = _redis.GetSubscriber();

            RedisNotification notif = new RedisNotification()
            {
                Text = "El menú de esta semana ya está disponible! Utiliza el comando /menu para mirar el de hoy.",
                Link = resp.FetchURL,
            };

            await sub.PublishAsync(NotificationChannel, JsonConvert.SerializeObject(notif));
        }