Exemple #1
0
        public static async Task Run([TimerTrigger("0 0 1 * * *")] TimerInfo myTimer, ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a Watch Gmail request.");
            string token = await AuthenticateGoogle.RefreshAccessToken(log);

            GmailAPI api          = new GmailAPI(log, token);
            dynamic  response     = api.Watch();
            string   responseBody = JsonConvert.SerializeObject(response);

            log.LogInformation($"{responseBody}");
        }
Exemple #2
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a Watch Gmail request.");
            string token = await AuthenticateGoogle.RefreshAccessToken(log);

            GmailAPI api          = new GmailAPI(log, token);
            dynamic  response     = api.Watch();
            string   responseBody = JsonConvert.SerializeObject(response);

            return(new OkObjectResult($"{responseBody}"));
        }
Exemple #3
0
        public static Dictionary <string, Status> RingStatus(ILogger log, string token)
        {
            Dictionary <string, string> query = new Dictionary <string, string>
            {
                { "q", $"from:[email protected]" }
            };
            GmailAPI api = new GmailAPI(log, token);

            api.Query = query;

            Dictionary <string, Status> status = new Dictionary <string, Status>();

            status["Alarm"] = AlarmStatus(api, log);

            return(status);
        }
Exemple #4
0
        private static Status AlarmStatus(GmailAPI api, ILogger log)
        {
            string alarmMode   = null;
            string changedTime = null;
            string details     = null;

            List <dynamic> messages = api.ListMessages();

            foreach (dynamic message in messages)
            {
                string  messageID   = message.id;
                dynamic fullMessage = api.GetMessage(messageID);
                dynamic headers     = fullMessage.payload.headers;
                string  subject     = null;
                foreach (dynamic header in headers)
                {
                    if (header.name == "Subject")
                    {
                        subject = header.value;
                        break;
                    }
                }

                ringAlarm.TryGetValue(subject, out alarmMode);
                if (alarmMode != null)
                {
                    //string msg = JsonConvert.SerializeObject(fullMessage);
                    changedTime = Leo.MillisecondsToLocalTimeString(Convert.ToInt64(fullMessage.internalDate));
                    // Extract information from snippet
                    Match match = Regex.Match(Convert.ToString(fullMessage.snippet), @".*?(Ring\sAlarm\sin\s[A-Za-z]+\schanged\sto\s.*?)Still\shave\squestions\?");
                    details = match.Groups[1].Value;
                    break;
                }
            }
            alarmMode = alarmMode ?? "Unknown";
            return(new Status
            {
                Mode = alarmMode,
                Time = changedTime,
                Details = details
            });
        }