public string Get() { try { AWSDynamoDBConnector.DynamoConnection dynamoConnection = new AWSDynamoDBConnector.DynamoConnection( accessKey: Startup.Configuration.GetSection("DynamoDBConnector:accessKey").Value, secretKey: Startup.Configuration.GetSection("DynamoDBConnector:secretKey").Value, tableName: Startup.Configuration.GetSection("DynamoDBConnector:tableName").Value); var soupsOrderedByDate = dynamoConnection.GetSoupsFromPastDays(3); if (soupsOrderedByDate == null || soupsOrderedByDate.Count == 0) { return("unable to find any soups in the past 72h"); } var LatestSoupUpdate = soupsOrderedByDate.LastOrDefault(); var soupLastUpdated = soupsOrderedByDate.FirstOrDefault(arg => arg.GetSoupsHash() == LatestSoupUpdate.GetSoupsHash()); // Move Special soup to end of list List <String> Soups = LatestSoupUpdate.Soups; var specialLoc = Soups.FirstOrDefault(arg => arg.Contains(SoupCrawler.SpecialSoupTitle)); if (specialLoc != null && Soups.Remove(specialLoc)) { Soups.Insert(Soups.Count, specialLoc); } TimeSpan lastPollTimespan = DateTime.UtcNow - LatestSoupUpdate.UpdTimeStamp; TimeSpan soupChange = DateTime.UtcNow - soupLastUpdated.UpdTimeStamp; return(string.Format("Last polled {0}\nLast soup change was {1}\n\n{2}", lastPollTimespan.FormatSlackTime(), soupChange.FormatSlackTime(), String.Join("\n", Soups))); } catch (Exception e) { return("Exception while retreiving DB update: " + e); } }
/// <summary> /// A Lambda function to respond to HTTP Get methods from API Gateway /// </summary> /// <param name="request"></param> /// <returns>The list of blogs</returns> public APIGatewayProxyResponse Get(APIGatewayProxyRequest request, ILambdaContext context) { context.Logger.LogLine("Get Request at " + DateTime.UtcNow.ToString() + "\n"); int statusCode = (int)HttpStatusCode.OK; try { AWSDynamoDBConnector.DynamoConnection dynamoConnection = new AWSDynamoDBConnector.DynamoConnection( accessKey: ConfigurationManager.AppSettings.DynamoDBConnector.accessKey.Value, secretKey: ConfigurationManager.AppSettings.DynamoDBConnector.secretKey.Value, tableName: ConfigurationManager.AppSettings.DynamoDBConnector.tableName.Value); SoupCrawler crawler = new SoupCrawler(); var soups = crawler.GetTodaysSoups(); dynamoConnection.AddSoups(soups); context.Logger.LogLine("Successfully received " + soups.Count + " soups \n"); } catch (Exception e) { context.Logger.LogLine("Failted to parse/update data with Exception: " + e + "\n"); statusCode = (int)HttpStatusCode.InternalServerError; } var response = new APIGatewayProxyResponse { StatusCode = statusCode, Body = "", Headers = new Dictionary <string, string> { { "Content-Type", "text/plain" } } }; return(response); }