| <Nullable>enable</Nullable> | <Nullable>enable</Nullable> | ||||
| </PropertyGroup> | </PropertyGroup> | ||||
| <ItemGroup> | <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.Storage" Version="4.0.4" /> | ||||
| <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.1.0" /> | <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" /> | <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.3.0" OutputItemType="Analyzer" /> |
| 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; | |||||
| } | |||||
| } | |||||
| } |
| public class ClockifyApiIntegrationFunction | public class ClockifyApiIntegrationFunction | ||||
| { | { | ||||
| private readonly ILogger _logger; | private readonly ILogger _logger; | ||||
| public static HttpClient HttpApiClient { get; set; } = new HttpClient(); | |||||
| public ClockifyApiIntegrationFunction(ILoggerFactory loggerFactory) | public ClockifyApiIntegrationFunction(ILoggerFactory loggerFactory) | ||||
| { | { | ||||
| _logger = loggerFactory.CreateLogger<ClockifyApiIntegrationFunction>(); | _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")] | [Function("ClockifyApiIntegrationFunction")] | ||||
| public void Run([TimerTrigger("* * * */5 * *")] MyInfo myTimer) | public void Run([TimerTrigger("* * * */5 * *")] MyInfo myTimer) | ||||
| { | { | ||||
| _logger.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}"); | _logger.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}"); | ||||
| } | } | ||||
| } | } | ||||
| public class MyInfo | public class MyInfo |