Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions Clockify.Net/Clients/ClockifyExperimentalClient.cs

This file was deleted.

10 changes: 0 additions & 10 deletions Clockify.Net/Clients/ClockifyReportsClient.cs

This file was deleted.

21 changes: 0 additions & 21 deletions Clockify.Net/Clients/IClockifyClient.cs

This file was deleted.

9 changes: 0 additions & 9 deletions Clockify.Net/Clients/IClockifyExperimentalClient.cs

This file was deleted.

9 changes: 0 additions & 9 deletions Clockify.Net/Clients/IClockifyReportsClient.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Clockify.Net/ClockifyClient.Projects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public async Task<Response> DeleteProjectAsync(string workspaceId, string id)
public async Task<Response> FindProjectByIdAsync(string workspaceId, string id)
{
var request = new RestRequest($"workspaces/{workspaceId}/projects/{id}");
return Response.FromRestResponse(await _experimentalClient.ExecuteAsync(request, Method.Get).ConfigureAwait(false));
return Response.FromRestResponse(await _client.ExecuteAsync(request, Method.Get).ConfigureAwait(false));
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions Clockify.Net/ClockifyClient.Reports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async Task<Response<DetailedReportDto>> GetDetailedReportAsync(string wor
var request = new RestRequest($"workspaces/{workspaceId}/reports/detailed", Method.Post);
request.AddJsonBody(detailedReportRequest);

return Response<DetailedReportDto>.FromRestResponse(await _reportsClient.ExecutePostAsync<DetailedReportDto>(request).ConfigureAwait(false));
return Response<DetailedReportDto>.FromRestResponse(await _client.ExecutePostAsync<DetailedReportDto>(request).ConfigureAwait(false));
}

/// <summary>
Expand All @@ -32,7 +32,7 @@ public async Task<Response<SummaryReportDto>> GetSummaryReportAsync(string works
var request = new RestRequest($"workspaces/{workspaceId}/reports/summary", Method.Post);
request.AddJsonBody(summaryReportRequest);

return Response<SummaryReportDto>.FromRestResponse(await _reportsClient.ExecuteAsync<SummaryReportDto>(request).ConfigureAwait(false));
return Response<SummaryReportDto>.FromRestResponse(await _client.ExecuteAsync<SummaryReportDto>(request).ConfigureAwait(false));
}

/// <summary>
Expand All @@ -43,7 +43,7 @@ public async Task<Response<WeeklyReportDto>> GetWeeklyReportAsync(string workspa
var request = new RestRequest($"workspaces/{workspaceId}/reports/weekly", Method.Post);
request.AddJsonBody(weeklyReportRequest);

return Response<WeeklyReportDto>.FromRestResponse(await _reportsClient.ExecuteAsync<WeeklyReportDto>(request, Method.Post).ConfigureAwait(false));
return Response<WeeklyReportDto>.FromRestResponse(await _client.ExecuteAsync<WeeklyReportDto>(request, Method.Post).ConfigureAwait(false));
}
}
}
2 changes: 1 addition & 1 deletion Clockify.Net/ClockifyClient.TimeEntries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public async Task<Response<IEnumerable<TimeEntryDtoImpl>>> FindAllTimeEntriesFor
// Find project
var requestProject = new RestRequest($"workspaces/{workspaceId}/projects/{projectId}");
var projectResponse =
await _experimentalClient.ExecuteAsync(requestProject, Method.Get).ConfigureAwait(false);
await _client.ExecuteAsync(requestProject, Method.Get).ConfigureAwait(false);

var project = JsonConvert.DeserializeObject<ProjectDtoImpl>(projectResponse.Content);

Expand Down
2 changes: 1 addition & 1 deletion Clockify.Net/ClockifyClient.Users.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task<Response<CurrentUserDto>> GetCurrentUserAsync(bool includeMemb
public async Task<Response<UserDto>> SetActiveWorkspaceFor(string userId, string workspaceId)
{
var request = new RestRequest($"users/{userId}/activeWorkspace/{workspaceId}");
return Response<UserDto>.FromRestResponse(await _experimentalClient.ExecutePostAsync<UserDto>(request).ConfigureAwait(false));
return Response<UserDto>.FromRestResponse(await _client.ExecutePostAsync<UserDto>(request).ConfigureAwait(false));
}

public async Task<Response<List<UserDto>>> FilterWorkspaceUsers(string workspaceId, WorkspaceUsersRequest requestBody)
Expand Down
2 changes: 1 addition & 1 deletion Clockify.Net/ClockifyClient.Workspaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task<Response<WorkspaceDto>> CreateWorkspaceAsync(WorkspaceRequest
public async Task<Response> DeleteWorkspaceAsync(string id)
{
var request = new RestRequest($"workspaces/{id}");
return Response.FromRestResponse(await _experimentalClient.ExecuteAsync(request, Method.Delete).ConfigureAwait(false));
return Response.FromRestResponse(await _client.ExecuteAsync(request, Method.Delete).ConfigureAwait(false));
}

/// <summary>
Expand Down
29 changes: 7 additions & 22 deletions Clockify.Net/ClockifyClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Clockify.Net.Clients;
using Newtonsoft.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using RestSharp;
Expand All @@ -8,31 +7,23 @@
using System.Collections.Generic;

namespace Clockify.Net;
public partial class ClockifyClient : IClockifyClient {
public partial class ClockifyClient
{

private RestClient _client;
private RestClient _experimentalClient;
private RestClient _reportsClient;

public ClockifyClient(string apiKey,
string apiUrl = Constants.ApiUrl,
string experimentalApiUrl = Constants.ExperimentalApiUrl,
string reportsApiUrl = Constants.ReportsApiUrl) {
InitClients(apiKey, apiUrl, experimentalApiUrl, reportsApiUrl);
string apiUrl = Constants.ApiUrl) {
InitClients(apiKey, apiUrl);
}

public IClockifyExperimentalClient Experimental => throw new NotImplementedException();

public IClockifyReportsClient Reports => throw new NotImplementedException();

/// <summary>
/// Creates new <see cref="ClockifyClient"/>.
/// Uses value from environment variable named "CAPI_KEY"
/// </summary>


#region Private methods
private void InitClients(string apiKey, string apiUrl, string experimentalApiUrl, string reportsApi) {
private void InitClients(string apiKey, string apiUrl) {
var jsonSerializerSettings = new JsonSerializerSettings() {
NullValueHandling = NullValueHandling.Ignore,

Expand All @@ -46,13 +37,7 @@ private void InitClients(string apiKey, string apiUrl, string experimentalApiUrl
};

_client = new RestClient(apiUrl, configureSerialization: config => config.UseNewtonsoftJson(jsonSerializerSettings));
_client.AddDefaultHeader(Constants.ApiKeyHeaderName, apiKey);

_experimentalClient = new RestClient(experimentalApiUrl, configureSerialization: config => config.UseNewtonsoftJson(jsonSerializerSettings));
_experimentalClient.AddDefaultHeader(Constants.ApiKeyHeaderName, apiKey);

_reportsClient = new RestClient(reportsApi, configureSerialization: config => config.UseNewtonsoftJson(jsonSerializerSettings));
_reportsClient.AddDefaultHeader(Constants.ApiKeyHeaderName, apiKey);
_client.AddDefaultHeader(Constants.ApiKeyHeaderName, apiKey);
}
#endregion
}
29 changes: 8 additions & 21 deletions Clockify.Net/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Clockify.Net;
using Clockify.Net.Clients;
using Clockify.Net.Exceptions;

using Microsoft.Extensions.Configuration;

using System;

namespace Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -30,27 +31,13 @@ public static IServiceCollection AddClockifyClient(this IServiceCollection servi
if (string.IsNullOrWhiteSpace(finalApiKey))
throw new InvalidClockifyConfigurationException($"Cannot a configuration value for the Environment Variable {Constants.ApiKeyVariableName} or the config key {Constants.ApiKeyConfigurationKey}");

services.AddTransient<ClockifyClient>();

services.AddTransient<IClockifyClient, ClockifyClient>();


services.AddHttpClient<IClockifyExperimentalClient>(Constants.ExperimentalClientName, httpClient =>
{
httpClient.BaseAddress = new Uri(Constants.ExperimentalApiUrl);
httpClient.DefaultRequestHeaders.Add(Constants.ApiKeyHeaderName, finalApiKey);
});

services.AddHttpClient<IClockifyReportsClient>(Constants.ReportsClientName, httpClient =>
{
httpClient.BaseAddress = new Uri(Constants.ReportsApiUrl);
httpClient.DefaultRequestHeaders.Add(Constants.ApiKeyHeaderName, finalApiKey);
});

services.AddHttpClient<IClockifyClient>(Constants.ClockifyClientName, httpClient =>
{
httpClient.BaseAddress = new Uri(Constants.ApiUrl);
httpClient.DefaultRequestHeaders.Add(Constants.ApiKeyHeaderName, finalApiKey);
});
services.AddHttpClient<ClockifyClient>(Constants.ClockifyClientName, httpClient =>
{
httpClient.BaseAddress = new Uri(Constants.ApiUrl);
httpClient.DefaultRequestHeaders.Add(Constants.ApiKeyHeaderName, finalApiKey);
});

return services;
}
Expand Down
10 changes: 5 additions & 5 deletions Clockify.Tests/Clockify.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<IsPackable>false</IsPackable>
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
<RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.1" />
<PackageReference Include="nunit" Version="4.3.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="TimeZoneConverter" Version="6.1.0" />
<PackageReference Include="nunit" Version="4.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="TimeZoneConverter" Version="7.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down