using BlackRockReportFunction.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Net; using System.Net.Http; using System.Net.Http.Headers; using GemBox.Spreadsheet; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http; using Microsoft.Build.Tasks.Deployment.Bootstrapper; namespace BlackRockReportFunction.Bussines { public class ClockifyReports { public static string? clockifyApiKey = Environment.GetEnvironmentVariable("ClockifyApiKey"); static HttpClient client = new HttpClient(); public static async Task InitializeClockifyIntegration() { client.DefaultRequestHeaders.Add("X-API-Key", clockifyApiKey); client.BaseAddress = new Uri("https://reports.api.clockify.me/v1"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept .Add(new MediaTypeWithQualityHeaderValue("application/json")); } public static async Task CreateClockifyReport(ClockifyReport clockifyReport) { HttpResponseMessage httpResponseMessage = await client .PostAsJsonAsync("api/clockifyreport", clockifyReport); httpResponseMessage.EnsureSuccessStatusCode(); return httpResponseMessage.Headers.Location; } public static async Task GetClockifyReportAsync(string path) { ClockifyReport clockifyReport = null; HttpResponseMessage httpResponseMessage= await client.GetAsync(path); if (httpResponseMessage.IsSuccessStatusCode) { clockifyReport = await httpResponseMessage.Content.ReadAsAsync(); } return clockifyReport; } } }