Black Rock Reporting Azure Function
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ClockifyReports.cs 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. namespace BlackRockReportFunction.Bussines
  11. {
  12. public class ClockifyReports
  13. {
  14. static HttpClient client = new HttpClient();
  15. static void InitializeClockifyIntegration()
  16. {
  17. client.BaseAddress = new Uri("https://reports.api.clockify.me/v1");
  18. client.DefaultRequestHeaders.Accept.Clear();
  19. client.DefaultRequestHeaders.Accept
  20. .Add(new MediaTypeWithQualityHeaderValue("application/json"));
  21. }
  22. static async Task<Uri> CreateClockifyReport(ClockifyReport clockifyReport)
  23. {
  24. HttpResponseMessage httpResponseMessage = await client
  25. .PostAsJsonAsync("api/clockifyreport", clockifyReport);
  26. httpResponseMessage.EnsureSuccessStatusCode();
  27. return httpResponseMessage.Headers.Location;
  28. }
  29. static async Task<ClockifyReport> GetClockifyReportAsync(string path)
  30. {
  31. ClockifyReport clockifyReport = null;
  32. HttpResponseMessage httpResponseMessage= await client.GetAsync(path);
  33. if (httpResponseMessage.IsSuccessStatusCode)
  34. {
  35. clockifyReport = await httpResponseMessage.Content.ReadAsAsync<ClockifyReport>();
  36. }
  37. return clockifyReport;
  38. }
  39. }
  40. }