Skip to content

Commit

Permalink
add getquotes
Browse files Browse the repository at this point in the history
  • Loading branch information
rrelyea committed Jun 19, 2024
1 parent 63f1107 commit 8ad20b0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ######

Expand Down
42 changes: 42 additions & 0 deletions api.multifol.io/GetQuotes.cs
Original file line number Diff line number Diff line change
@@ -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<IActionResult> 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);
}
}
}
}

0 comments on commit 8ad20b0

Please sign in to comment.