From 8ad20b03d8a68dc0057a00dc215a4acc215d4715 Mon Sep 17 00:00:00 2001 From: Rob Relyea Date: Wed, 19 Jun 2024 13:43:34 -0700 Subject: [PATCH] add getquotes --- ...ure-static-web-apps-gray-mud-05da7791e.yml | 2 +- api.multifol.io/GetQuotes.cs | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 api.multifol.io/GetQuotes.cs diff --git a/.github/workflows/azure-static-web-apps-gray-mud-05da7791e.yml b/.github/workflows/azure-static-web-apps-gray-mud-05da7791e.yml index 69e5b08..0a1cc8a 100644 --- a/.github/workflows/azure-static-web-apps-gray-mud-05da7791e.yml +++ b/.github/workflows/azure-static-web-apps-gray-mud-05da7791e.yml @@ -29,7 +29,7 @@ jobs: ###### Repository/Build Configurations - These values can be configured to match your app requirements. ###### # For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig app_location: "/" # App source code path - api_location: "./api" # Api source code path - optional + api_location: "./api.multifol.io" # Api source code path - optional output_location: "wwwroot" # Built app content directory - optional ###### End of Repository/Build Configurations ###### diff --git a/api.multifol.io/GetQuotes.cs b/api.multifol.io/GetQuotes.cs new file mode 100644 index 0000000..e08cec4 --- /dev/null +++ b/api.multifol.io/GetQuotes.cs @@ -0,0 +1,42 @@ +using System; +using System.IO; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Azure.WebJobs; +using Microsoft.Azure.WebJobs.Extensions.Http; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using System.Net.Http; + +namespace api +{ + public static class GetQuotes + { + [FunctionName("GetQuotes")] + public static async Task Run( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, + ILogger log) + { + log.LogInformation("GetQuotes processed a request."); + + string ticker = req.Query["ticker"]; + string apikey = req.Query["apikey"]; + + string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); + dynamic data = JsonConvert.DeserializeObject(requestBody); + ticker = ticker ?? data?.ticker; + apikey = apikey ?? data?.apikey; + + string url = $"https://eodhd.com/api/real-time/{ticker}?fmt=json&api_token={apikey}"; + var httpClient = new HttpClient(); + try { + var quoteDataJson = await httpClient.GetStringAsync(url); + return new OkObjectResult(quoteDataJson); + } + catch (Exception ex) { + return new BadRequestObjectResult(ex.GetType().Name + ": " + ex.Message); + } + } + } +}