Ejemplo n.º 1
0
        private static async Task Main()
        {
            var config = new ConfigBuilder(".").Build();

            var parser  = new MercuryApiParser("https://mercury-parser.azurewebsites.net/api/MercuryParser?url=");
            var article = await parser.ParseAsync("https://earth.stanford.edu/news/how-much-does-air-pollution-cost-us#gs.9a641g");

            var apiKey = "";
            var sender = new SendgridSender(apiKey, "*****@*****.**");
            await sender.SendEmailWithHtmlAttachmentAsync("*****@*****.**", "elo", article.Content);
        }
Ejemplo n.º 2
0
        public static async Task <IActionResult> RunAsync(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            ILogger log,
            ExecutionContext context)
        {
            var _config      = new ConfigBuilder(context.FunctionAppDirectory).Build();
            var _emailSender = new SendgridSender(_config.SendgridApiKey, _config.MailgunHostEmail);
            var _client      = new PocketClient(_config.PocketConsumerKey, callbackUri: _config.PocketRedirectUri);

            string          requestBody = new StreamReader(req.Body).ReadToEnd();
            RegisterRequest request     = JsonConvert.DeserializeObject <RegisterRequest>(requestBody);

            if (!IsValidEmail(request.KindleEmail))
            {
                log.LogError($"Not valid email: {request.KindleEmail}.");
                return(new BadRequestObjectResult("email provided is not valid"));
            }

            PocketUser pocketUser = new PocketUser();

            try
            {
                pocketUser = await _client.GetUser(request.RequestCode);
            }
            catch (PocketException pocketException)
            {
                log.LogError($"Something went wrong: {pocketException.Message}.");
                return(new BadRequestObjectResult(pocketException.Message));
            }

            IUserService userService = UserService.BuildUserService(_config.StorageConnectionString);
            await userService.AddUserAsync(new User
            {
                AccessCode         = pocketUser.Code,
                PocketUsername     = pocketUser.Username,
                KindleEmail        = request.KindleEmail,
                LastProcessingDate = DateTime.UtcNow,
                Token = Guid.NewGuid().ToString()
            });

            await SendWelcomeEmail(_emailSender, request.KindleEmail);

            log.LogInformation($"Successfully registered user: {request.KindleEmail}.");

            return(new OkObjectResult("Registration successful"));
        }