| @@ -7,6 +7,7 @@ | |||
| <Nullable>enable</Nullable> | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" /> | |||
| <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="4.0.4" /> | |||
| <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.1.0" /> | |||
| <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.3.0" OutputItemType="Analyzer" /> | |||
| @@ -0,0 +1,52 @@ | |||
| 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; | |||
| namespace BlackRockReportFunction.Bussines | |||
| { | |||
| public class ClockifyReports | |||
| { | |||
| static HttpClient client = new HttpClient(); | |||
| static void InitializeClockifyIntegration() | |||
| { | |||
| client.BaseAddress = new Uri("https://reports.api.clockify.me/v1"); | |||
| client.DefaultRequestHeaders.Accept.Clear(); | |||
| client.DefaultRequestHeaders.Accept | |||
| .Add(new MediaTypeWithQualityHeaderValue("application/json")); | |||
| } | |||
| static async Task<Uri> CreateClockifyReport(ClockifyReport clockifyReport) | |||
| { | |||
| HttpResponseMessage httpResponseMessage = await client | |||
| .PostAsJsonAsync("api/clockifyreport", clockifyReport); | |||
| httpResponseMessage.EnsureSuccessStatusCode(); | |||
| return httpResponseMessage.Headers.Location; | |||
| } | |||
| 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; | |||
| } | |||
| } | |||
| } | |||
| @@ -9,40 +9,17 @@ namespace BlackRockReportFunction | |||
| public class ClockifyApiIntegrationFunction | |||
| { | |||
| private readonly ILogger _logger; | |||
| public static HttpClient HttpApiClient { get; set; } = new HttpClient(); | |||
| public ClockifyApiIntegrationFunction(ILoggerFactory loggerFactory) | |||
| { | |||
| _logger = loggerFactory.CreateLogger<ClockifyApiIntegrationFunction>(); | |||
| } | |||
| public static void InitializeClockifyIntegration() | |||
| { | |||
| HttpApiClient = new HttpClient(); | |||
| HttpApiClient.BaseAddress = new Uri("https://reports.api.clockify.me/v1"); | |||
| HttpApiClient.DefaultRequestHeaders.Accept.Clear(); | |||
| HttpApiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |||
| } | |||
| public static void GetReportsFromClockify(string url) | |||
| { | |||
| //adding api key header | |||
| HttpApiClient.DefaultRequestHeaders.Add("X-Api-Key", "*********"); | |||
| //making request | |||
| } | |||
| [Function("ClockifyApiIntegrationFunction")] | |||
| public void Run([TimerTrigger("* * * */5 * *")] MyInfo myTimer) | |||
| { | |||
| _logger.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}"); | |||
| } | |||
| } | |||
| public class MyInfo | |||