Skip to content

Commit e0ec3bd

Browse files
committed
Version 2.0.4
* Added an ability to create team webhooks.
1 parent 0d12600 commit e0ec3bd

File tree

9 files changed

+344
-6
lines changed

9 files changed

+344
-6
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ Test.DB.*
1818
TestResults/
1919
Dapper.Tests/*.sdf
2020
Dapper.Tests/SqlServerTypes/
21-
.dotnet/*
21+
.dotnet/*
22+
/msbuild.log

Chinchilla.ClickUp.Tests/ClickUpApiTests.cs

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ public void ShouldGetSpaceFolders()
254254
Assert.Fail($"The Test Method of '{methodName}' generate an error with status: {response.RequestStatus} and response: {response.ResponseError.Err}");
255255
else
256256
{
257-
Assert.That(response.ResponseSuccess.Folders.Count == 1, $"The Response of the request through the method '{methodName}' did not return one space!");
258-
Assert.That(response.ResponseSuccess.Folders.Single().Lists.Count > 2, $"The Response of the request through the method '{methodName}' returned a space without at least two lists!");
257+
Assert.That(response.ResponseSuccess.Folders.Count > 1, $"The Response of the request through the method '{methodName}' did not return one space!");
258+
Assert.That(response.ResponseSuccess.Folders.Any(x => x.Lists.Count > 2), $"The Response of the request through the method '{methodName}' returned a space but without at least two lists!");
259259
}
260260
}
261261
else
@@ -572,6 +572,44 @@ public void ShouldEditTask()
572572
}
573573
}
574574

575+
/// <summary>
576+
/// Tests of CreateTeamWebhook method
577+
/// </summary>
578+
[Test]
579+
public void ShouldCreateTeamWebhook()
580+
{
581+
string methodName = "CreateTeamWebhook";
582+
string endpoint = $"https://localhost:{new Random().Next(100, 9999)}";
583+
ResponseGeneric<ResponseWebhook, ResponseError> response = null;
584+
try
585+
{
586+
ClickUpApi clickUpAPI = new ClickUpApi(_accessToken);
587+
response = clickUpAPI.CreateTeamWebhook
588+
(
589+
new ParamsCreateTeamWebhook(_teamId),
590+
new RequestCreateTeamWebhook(endpoint)
591+
);
592+
}
593+
catch (Exception ex)
594+
{
595+
Assert.Fail($"The Test Method of '{methodName}' generate exception: {ex.Message}"); // Always return false
596+
}
597+
if (response != null)
598+
{
599+
Assert.That(response.ResponseSuccess != null || response.ResponseError != null, $"The ResponseSuccess and the ResponseError of the GenericResponse of the request through the method '{methodName}' are null!"); // Always return false
600+
if (response.ResponseError != null)
601+
Assert.Fail($"The Test Method of '{methodName}' generate an error with status: {response.RequestStatus} and response: {response.ResponseError.Err}");
602+
else
603+
{
604+
Assert.That(response.ResponseSuccess.Webhook.Endpoint == endpoint, $"The Response of the request through the method '{methodName}' did not return a new webhook with the same name!");
605+
}
606+
}
607+
else
608+
{
609+
Assert.Fail($"The Response of the request through the method '{methodName}' is null!");
610+
}
611+
}
612+
575613
#endregion
576614

577615

@@ -834,8 +872,8 @@ public void ShouldGetSpaceFoldersAsync()
834872
Assert.Fail($"The Test Method of '{methodName}' generate an error with status: {response.RequestStatus} and response: {response.ResponseError.Err}");
835873
else
836874
{
837-
Assert.That(response.ResponseSuccess.Folders.Count == 1, $"The Response of the request through the method '{methodName}' did not return one space!");
838-
Assert.That(response.ResponseSuccess.Folders.Single().Lists.Count > 2, $"The Response of the request through the method '{methodName}' returned a space without at least two lists!");
875+
Assert.That(response.ResponseSuccess.Folders.Count > 1, $"The Response of the request through the method '{methodName}' did not return one space!");
876+
Assert.That(response.ResponseSuccess.Folders.Any(x => x.Lists.Count > 2), $"The Response of the request through the method '{methodName}' returned a space but without at least two lists!");
839877
}
840878
}
841879
else
@@ -1135,6 +1173,47 @@ public void ShouldEditTaskAsync()
11351173
}
11361174
}
11371175

1176+
/// <summary>
1177+
/// Tests of CreateTeamWebhookAsync method
1178+
/// </summary>
1179+
[Test]
1180+
public void ShouldCreateTeamWebhookAsync()
1181+
{
1182+
string methodName = "CreateTeamWebhookAsync";
1183+
string endpoint = $"https://localhost:{new Random().Next(100, 9999)}";
1184+
ResponseGeneric<ResponseWebhook, ResponseError> response = null;
1185+
try
1186+
{
1187+
ClickUpApi clickUpAPI = new ClickUpApi(_accessToken);
1188+
Task.Run(async () => {
1189+
response = await clickUpAPI.CreateTeamWebhookAsync
1190+
(
1191+
new ParamsCreateTeamWebhook(_teamId),
1192+
new RequestCreateTeamWebhook(endpoint)
1193+
);
1194+
})
1195+
.Wait();
1196+
}
1197+
catch (Exception ex)
1198+
{
1199+
Assert.Fail($"The Test Method of '{methodName}' generate exception: {ex.Message}"); // Always return false
1200+
}
1201+
if (response != null)
1202+
{
1203+
Assert.That(response.ResponseSuccess != null || response.ResponseError != null, $"The ResponseSuccess and the ResponseError of the GenericResponse of the request through the method '{methodName}' are null!"); // Always return false
1204+
if (response.ResponseError != null)
1205+
Assert.Fail($"The Test Method of '{methodName}' generate an error with status: {response.RequestStatus} and response: {response.ResponseError.Err}");
1206+
else
1207+
{
1208+
Assert.That(response.ResponseSuccess.Webhook.Endpoint == endpoint, $"The Response of the request through the method '{methodName}' did not return a new webhook with the same name!");
1209+
}
1210+
}
1211+
else
1212+
{
1213+
Assert.Fail($"The Response of the request through the method '{methodName}' is null!");
1214+
}
1215+
}
1216+
11381217
#endregion
11391218
}
11401219
}

Chinchilla.ClickUp/Chinchilla.ClickUp.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212
<RepositoryType>git</RepositoryType>
1313
<PackageTags>api;csharp;rest;clickup</PackageTags>
1414
<PackageId>Chinchilla.ClickUp</PackageId>
15-
<Version>2.0.4</Version>
15+
<Version>2.0.5</Version>
1616
<PackageReleaseNotes>
17+
Version 2.0.5
18+
19+
* Added an ability to create team webhooks.
20+
1721
Version 2.0.4
1822

1923
* Added an ability to get folderless lists.

Chinchilla.ClickUp/ClickUpApi.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,26 @@ public ResponseGeneric<ResponseModelTask, ResponseError> EditTask(ParamsEditTask
316316
return result;
317317
}
318318

319+
/// <summary>
320+
/// Create a webhook in a Team
321+
/// </summary>
322+
/// <param name="paramsCreateTeamWebhook">param object of create webhook request</param>
323+
/// <param name="requestData">RequestCreateTeamWebhook object</param>
324+
/// <returns>ResponseGeneric with ResponseWebhook response object</returns>
325+
public ResponseGeneric<ResponseWebhook, ResponseError> CreateTeamWebhook(ParamsCreateTeamWebhook paramsCreateTeamWebhook, RequestCreateTeamWebhook requestData)
326+
{
327+
requestData.ValidateData();
328+
329+
var client = new RestClient(_baseAddress);
330+
var request = new RestRequest($"team/{paramsCreateTeamWebhook.TeamId}/webhook", Method.POST);
331+
request.AddHeader("authorization", _accessToken);
332+
request.AddJsonBody(requestData);
333+
334+
// execute the request
335+
ResponseGeneric<ResponseWebhook, ResponseError> result = RestSharperHelper.ExecuteRequest<ResponseWebhook, ResponseError>(client, request);
336+
return result;
337+
}
338+
319339
#endregion
320340

321341
#region API Methods Async
@@ -553,6 +573,25 @@ public Task<ResponseGeneric<ResponseModelTask, ResponseError>> EditTaskAsync(Par
553573
return RestSharperHelper.ExecuteRequestAsync<ResponseModelTask, ResponseError>(client, request);
554574
}
555575

576+
/// <summary>
577+
/// Create a webhook in a Team
578+
/// </summary>
579+
/// <param name="paramsCreateTeamWebhook">param object of create webhook request</param>
580+
/// <param name="requestData">RequestCreateTeamWebhook object</param>
581+
/// <returns>ResponseGeneric with ResponseWebhook response object</returns>
582+
public Task<ResponseGeneric<ResponseWebhook, ResponseError>> CreateTeamWebhookAsync(ParamsCreateTeamWebhook paramsCreateTeamWebhook, RequestCreateTeamWebhook requestData)
583+
{
584+
requestData.ValidateData();
585+
586+
var client = new RestClient(_baseAddress);
587+
var request = new RestRequest($"team/{paramsCreateTeamWebhook.TeamId}/webhook", Method.POST);
588+
request.AddHeader("authorization", _accessToken);
589+
request.AddJsonBody(requestData);
590+
591+
// execute the request
592+
return RestSharperHelper.ExecuteRequestAsync<ResponseWebhook, ResponseError>(client, request);
593+
}
594+
556595
#endregion
557596
}
558597
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Runtime.Serialization;
4+
5+
namespace Chinchilla.ClickUp.Params
6+
{
7+
8+
/// <summary>
9+
/// The param object of create team space request
10+
/// </summary>
11+
public class ParamsCreateTeamWebhook
12+
{
13+
#region Attributes
14+
15+
/// <summary>
16+
/// The Team Id
17+
/// </summary>
18+
[JsonProperty("team_id")]
19+
[DataMember(Name = "team_id")]
20+
public string TeamId { get; set; }
21+
22+
#endregion
23+
24+
25+
#region Constructor
26+
27+
/// <summary>
28+
/// The constructor of ParamsCreateTeamWebhook
29+
/// </summary>
30+
/// <param name="teamId"></param>
31+
public ParamsCreateTeamWebhook(string teamId)
32+
{
33+
TeamId = teamId;
34+
}
35+
36+
#endregion
37+
38+
39+
#region Public Methods
40+
41+
/// <summary>
42+
/// Method that validate data insert
43+
/// </summary>
44+
public void ValidateData()
45+
{
46+
if (string.IsNullOrEmpty(TeamId))
47+
{
48+
throw new ArgumentNullException("TeamId");
49+
}
50+
}
51+
52+
#endregion
53+
}
54+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Linq;
4+
using System.Runtime.Serialization;
5+
6+
namespace Chinchilla.ClickUp.Requests
7+
{
8+
/// <summary>
9+
/// Request object for method CreateTeamSpace()
10+
/// </summary>
11+
[Serializable]
12+
[DataContract]
13+
public class RequestCreateTeamWebhook
14+
{
15+
#region Attributes
16+
17+
/// <summary>
18+
/// Name of the new list
19+
/// </summary>
20+
[JsonProperty("endpoint")]
21+
[DataMember(Name = "endpoint")]
22+
public string Endpoint { get; set; }
23+
24+
[JsonProperty("events")]
25+
[DataMember(Name = "events")]
26+
public string[] Events { get; set; }
27+
28+
#endregion
29+
30+
31+
#region Constructor
32+
33+
/// <summary>
34+
/// The constructor of RequestCreateTeamWebhook
35+
/// </summary>
36+
/// <param name="endpoint"></param>
37+
public RequestCreateTeamWebhook(string endpoint)
38+
{
39+
Endpoint = endpoint;
40+
Events = new[] { "*" };
41+
}
42+
43+
/// <summary>
44+
/// The constructor of RequestCreateTeamWebhook
45+
/// </summary>
46+
/// <param name="endpoint"></param>
47+
public RequestCreateTeamWebhook(string endpoint, string[] events)
48+
{
49+
Endpoint = endpoint;
50+
Events = events;
51+
}
52+
53+
#endregion
54+
55+
56+
#region Public Methods
57+
58+
/// <summary>
59+
/// Validation method of data
60+
/// </summary>
61+
public void ValidateData()
62+
{
63+
if (string.IsNullOrEmpty(Endpoint))
64+
{
65+
throw new ArgumentNullException("Name");
66+
}
67+
68+
if (!Events.Any())
69+
{
70+
throw new ArgumentNullException("Events");
71+
}
72+
}
73+
74+
#endregion
75+
}
76+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Chinchilla.ClickUp.Responses.Model
4+
{
5+
6+
public partial class ResponseModelWebhook
7+
: Helpers.IResponse
8+
{
9+
/// <summary>
10+
/// The id of the Webhook
11+
/// </summary>
12+
[JsonProperty("id")]
13+
public string Id { get; set; }
14+
15+
[JsonProperty("userid")]
16+
public int UserId { get; set; }
17+
18+
[JsonProperty("team_id")]
19+
public int TeamId { get; set; }
20+
21+
[JsonProperty("endpoint")]
22+
public string Endpoint { get; set; }
23+
24+
[JsonProperty("client_id")]
25+
public string ClientId { get; set; }
26+
27+
[JsonProperty("events")]
28+
public string[] Events { get; set; }
29+
30+
[JsonProperty("task_id")]
31+
public int? TaskId { get; set; }
32+
33+
[JsonProperty("list_id")]
34+
public int? ListId { get; set; }
35+
36+
[JsonProperty("folder_id")]
37+
public int? FolderId { get; set; }
38+
39+
[JsonProperty("space_id")]
40+
public int? SpaceId { get; set; }
41+
42+
[JsonProperty("health")]
43+
public ResponseModelWebhookHealth Health { get; set; }
44+
45+
[JsonProperty("secret")]
46+
public string Secret { get; set; }
47+
}
48+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Chinchilla.ClickUp.Responses.Model
4+
{
5+
6+
public partial class ResponseModelWebhook
7+
{
8+
public class ResponseModelWebhookHealth
9+
: Helpers.IResponse
10+
{
11+
[JsonProperty("status")]
12+
public string Status { get; set; }
13+
14+
[JsonProperty("fail_count")]
15+
public int FailedCount { get; set; }
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)