public async Task <LambdaProxyResponse> ExecuteFunction(ApiGatewayProxyRequest request, ILambdaContext context)
        {
            var requestBody = FunctionBody.GenerateFromRepspnse(request);
            var ser         = new JsonSerializer();
            var htmlWeb     = new HtmlWeb();

            var document = htmlWeb.Load(requestBody.url);

            var ogImage     = GetMetaValue(document, "og:image");
            var title       = GetTitle(document);
            var description = GetMetaValue(document, "description");

            var coffeeData = new CoffeeData {
                Title       = title,
                Description = description,
                OGImage     = ogImage,
            };

            var memStream = new MemoryStream();

            ser.Serialize(coffeeData, memStream);
            var body = memStream.ToString();

            memStream.Flush();

            context?.Logger.LogLine(body);

            return(await Task.FromResult <LambdaProxyResponse>(
                       new LambdaProxyResponse {
                statusCode = HttpStatusCode.Created,
                body = body,
            }));
        }
Пример #2
0
        protected override async Task <LambdaProxyResponse> ExecutionFunction(ApiGatewayProxyRequest request)
        {
            if (!request.PathParameters.ContainsKey("id"))
            {
                return(new LambdaProxyResponse
                {
                    statusCode = HttpStatusCode.BadRequest,
                    body = "No coffee ID defined in path parameter.",
                });
            }

            var id        = request.PathParameters["id"];
            var dbContext = new CoffeeContext(_context);

            return(!await dbContext.RemoveCoffee(id)
        ? new LambdaProxyResponse
            {
                statusCode = HttpStatusCode.InternalServerError,
                body = "There was a problem processing the request.",
            }

        : new LambdaProxyResponse
            {
                statusCode = HttpStatusCode.OK,
            });
        }
Пример #3
0
        public async Task <string> FunctionHandler(ApiGatewayProxyRequest input, ILambdaContext context)
        {
            var slackhookuri = "https://hooks.slack.com/services/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";
            var client       = new SlackClient(new Uri(slackhookuri));

            var response = await client.SendMessageAsync("A spill has been reported!  If you were the brewer, please go help cleanup!");


            if (response.StatusCode == HttpStatusCode.OK)
            {
                return(string.Format("Message successfully sent"));
            }
            else
            {
                return(string.Format("Failed to send message"));
            }

            //  var message = new SlackMessage {
            //  Text = "<!channel>: There has been a spill at the coffee machine!!",
            //  IconUrl = new Uri("https://static1.squarespace.com/static/50a96108e4b0a8a5e3e2c959/5673222c9cadb60e5542d97e/5673223705f8e24f350ec97c/1450385982313/spilledcoffee_insta.jpg?format=1000w"),
            //};

            //var response = await new SlackClient("https://hooks.slack.com/services/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").PostAsync(message);

            //context.Logger.LogLine(response.ErrorException.ToString());

            //return (response.StatusCode == HttpStatusCode.OK).ToString();
        }
Пример #4
0
        protected override async Task <LambdaProxyResponse> ExecutionFunction(ApiGatewayProxyRequest request)
        {
            var dbContext = new CoffeeContext(_context);
            var coffee    = await dbContext.GetCurrentCoffee();

            return(new LambdaProxyResponse
            {
                statusCode = HttpStatusCode.OK,
                body = SerializerUtil.Serialize(coffee),
            });
        }
Пример #5
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task <LambdaProxyResponse> FunctionHandler(ApiGatewayProxyRequest request, ILambdaContext context)
        {
            if (!String.IsNullOrEmpty(request.Path))
            {
                context.Logger.LogLine(request.Path);
            }



            return(await Task.Run(() => new LambdaProxyResponse
            {
                body = "Pass",
                statusCode = HttpStatusCode.Accepted
            }));
        }
Пример #6
0
 public static FunctionBody GenerateFromRequest(ApiGatewayProxyRequest request, ILambdaContext context)
 {
     if (request.IsSlackRequest())
     {
         var slackRequest = new SlackRequest(request.Body);
         var decodedText  = WebUtility.UrlDecode(slackRequest.Text);
         slackRequest.Text = decodedText.TrimStart('<').TrimEnd('>');
         context.Logger.LogLine(SerializerUtil.Serialize(slackRequest));
         return(new FunctionBody
         {
             url = slackRequest.Text,
         });
     }
     else
     {
         return(SerializerUtil.Deserialize <FunctionBody>(request.Body));
     }
 }
Пример #7
0
        protected override async Task <LambdaProxyResponse> ExecutionFunction(
            ApiGatewayProxyRequest request)
        {
            _context.Logger.LogLine(request.Body);
            var requestBody = FunctionBody.GenerateFromRequest(request, _context);
            var htmlWeb     = new HtmlWeb();
            var url         = requestBody.url;

            var document = htmlWeb.Load(url);

            var ogImage     = GetMetaValue(document, "og:image");
            var title       = GetTitle(document);
            var description = GetMetaValue(document, "description");

            var coffeeData = new CoffeeData
            {
                Title       = title,
                Description = description,
                OGImage     = ogImage ?? "",
            };

            var body = UtilityLibrary.Serialize(coffeeData);

            _context?.Logger.LogLine(body);

            var dbContext = new CoffeeContext(_context);

            var id      = GenerateIDFromURL(url);
            var success = await dbContext.AddCoffee(id, title, description, ogImage);

            return(success
        ? new LambdaProxyResponse {
                statusCode = HttpStatusCode.Created
            }
        : new LambdaProxyResponse
            {
                statusCode = HttpStatusCode.InternalServerError
            });
        }
Пример #8
0
 public Task <LambdaProxyResponse> ExecuteFunction(ApiGatewayProxyRequest request, ILambdaContext context)
 {
     throw new System.NotImplementedException();
 }
 public static FunctionBody GenerateFromRepspnse(
     ApiGatewayProxyRequest request
     )
 {
     return(SerializerUtil.Deserialize <FunctionBody>(request.Body));
 }