Black Rock Reporting Azure Function
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ClockifyReports.cs 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using BlackRockReportFunction.Models;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Net;
  8. using System.Net.Http;
  9. using System.Net.Http.Headers;
  10. using GemBox.Spreadsheet;
  11. using Microsoft.AspNetCore.Mvc;
  12. using Microsoft.AspNetCore.Http;
  13. using Microsoft.Build.Tasks.Deployment.Bootstrapper;
  14. namespace BlackRockReportFunction.Bussines
  15. {
  16. public class ClockifyReports
  17. {
  18. public static string? clockifyApiKey = Environment.GetEnvironmentVariable("ClockifyApiKey");
  19. static HttpClient client = new HttpClient();
  20. public static async Task InitializeClockifyIntegration()
  21. {
  22. client.DefaultRequestHeaders.Add("X-API-Key", clockifyApiKey);
  23. client.BaseAddress = new Uri("https://reports.api.clockify.me/v1");
  24. client.DefaultRequestHeaders.Accept.Clear();
  25. client.DefaultRequestHeaders.Accept
  26. .Add(new MediaTypeWithQualityHeaderValue("application/json"));
  27. }
  28. public static async Task<Uri> CreateClockifyReport(ClockifyReport clockifyReport)
  29. {
  30. HttpResponseMessage httpResponseMessage = await client
  31. .PostAsJsonAsync("api/clockifyreport", clockifyReport);
  32. httpResponseMessage.EnsureSuccessStatusCode();
  33. return httpResponseMessage.Headers.Location;
  34. }
  35. public static async Task<ClockifyReport> GetClockifyReportAsync(string path)
  36. {
  37. ClockifyReport clockifyReport = null;
  38. HttpResponseMessage httpResponseMessage= await client.GetAsync(path);
  39. if (httpResponseMessage.IsSuccessStatusCode)
  40. {
  41. clockifyReport = await httpResponseMessage.Content.ReadAsAsync<ClockifyReport>();
  42. }
  43. return clockifyReport;
  44. }
  45. }
  46. }