-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathClockifyClient.Client.cs
More file actions
82 lines (71 loc) · 3.73 KB
/
Copy pathClockifyClient.Client.cs
File metadata and controls
82 lines (71 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Clockify.Net.Models;
using Clockify.Net.Models.Clients;
using RestSharp;
namespace Clockify.Net
{
public partial class ClockifyClient
{
/// <summary>
/// Find clients on workspace
/// </summary>
public async Task<Response<List<ClientDto>>> FindAllClientsOnWorkspaceAsync(string workspaceId, int page = 1, int pageSize = 50)
{
var request = new RestRequest($"workspaces/{workspaceId}/clients");
request.AddQueryParameter(nameof(page), page.ToString());
request.AddQueryParameter("page-size", pageSize.ToString());
var restResponse = await _client.ExecuteGetAsync<List<ClientDto>>(request).ConfigureAwait(false);
return Response<List<ClientDto>>.FromRestResponse(restResponse);
}
/// <summary>
/// Add a new client to workspace.
/// </summary>
public async Task<Response<ClientDto>> CreateClientAsync(string workspaceId, ClientRequest clientRequest)
{
if (clientRequest == null) { throw new ArgumentNullException(nameof(clientRequest)); }
var request = new RestRequest($"workspaces/{workspaceId}/clients", Method.Post);
request.AddJsonBody(clientRequest);
return Response<ClientDto>.FromRestResponse(await _client.ExecutePostAsync<ClientDto>(request).ConfigureAwait(false));
}
/// <summary>
/// Update a client's name on workspace.
/// </summary>
[Obsolete($"Use {nameof(UpdateClientAsync)} instead.")]
public async Task<Response<ClientUpdateDto>> UpdateClientNameAsync(string workspaceId, string? clientId, ClientName clientName)
{
if (clientName == null) { throw new ArgumentNullException(nameof(clientName)); }
var request = new RestRequest($"workspaces/{workspaceId}/clients/{clientId}", Method.Put);
request.AddJsonBody(clientName);
return Response<ClientUpdateDto>.FromRestResponse(await _client.ExecuteAsync<ClientUpdateDto>(request).ConfigureAwait(false));
}
/// <summary>
/// Update a client's name on workspace.
/// </summary>
public async Task<Response<ClientUpdateDto>> UpdateClientAsync(string workspaceId, string? clientId, ClientUpdateRequest updateRequest)
{
var request = new RestRequest($"workspaces/{workspaceId}/clients/{clientId}", Method.Put);
request.AddJsonBody(updateRequest);
return Response<ClientUpdateDto>.FromRestResponse(await _client.ExecuteAsync<ClientUpdateDto>(request).ConfigureAwait(false));
}
/// <summary>
/// Delete a client from a workspace.
/// </summary>
public async Task<Response> DeleteClientAsync(string workspaceId, string? clientId)
{
var request = new RestRequest($"workspaces/{workspaceId}/clients/{clientId}");
return Response.FromRestResponse(await _client.ExecuteAsync(request, Method.Delete).ConfigureAwait(false));
}
/// <summary>
/// Delete a client from a workspace.
/// </summary>
public async Task<Response> ArchiveAndDeleteClientAsync(string workspaceId, string? clientId)
{
var clientUpdateRequest = new ClientUpdateRequest {Archived = true, Name = Guid.NewGuid().ToString()};
var updateClientResponse = await UpdateClientAsync(workspaceId, clientId, clientUpdateRequest).ConfigureAwait(false);
if (!updateClientResponse.IsSuccessful) return updateClientResponse;
return await this.DeleteClientAsync(workspaceId, clientId).ConfigureAwait(false);
}
}
}