| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- 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<Uri> CreateClockifyReport(ClockifyReport clockifyReport)
- {
- HttpResponseMessage httpResponseMessage = await client
- .PostAsJsonAsync("api/clockifyreport", clockifyReport);
-
- httpResponseMessage.EnsureSuccessStatusCode();
-
- return httpResponseMessage.Headers.Location;
- }
-
- public static async Task<ClockifyReport> GetClockifyReportAsync(string path)
- {
- ClockifyReport clockifyReport = null;
- HttpResponseMessage httpResponseMessage= await client.GetAsync(path);
-
- if (httpResponseMessage.IsSuccessStatusCode)
- {
- clockifyReport = await httpResponseMessage.Content.ReadAsAsync<ClockifyReport>();
- }
-
- return clockifyReport;
- }
- }
- }
|