Skip to content

Commit 9cc0165

Browse files
committed
Version 2.0.7
* Added an ability to get a task by its ID.
1 parent a3db095 commit 9cc0165

File tree

4 files changed

+161
-1
lines changed

4 files changed

+161
-1
lines changed

Chinchilla.ClickUp.Tests/ClickUpApiTests.cs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,40 @@ public void ShouldEditList()
495495
#endregion
496496

497497
#region Tasks
498+
/// <summary>
499+
/// Tests of GetTaskById method
500+
/// </summary>
501+
[Test]
502+
public void ShouldGetTaskById()
503+
{
504+
string methodName = "GetTaskById";
505+
ResponseGeneric<ResponseModelTask, ResponseError> response = null;
506+
try
507+
{
508+
ClickUpApi clickUpAPI = new ClickUpApi(_accessToken);
509+
response = clickUpAPI.GetTaskById(new ParamsGetTaskById("te05k"));
510+
}
511+
catch (Exception ex)
512+
{
513+
Assert.Fail($"The Test Method of '{methodName}' generate exception: {ex.Message}"); // Always return false
514+
}
515+
if (response != null)
516+
{
517+
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
518+
if (response.ResponseError != null)
519+
Assert.Fail($"The Test Method of '{methodName}' generate an error with status: {response.RequestStatus} and response: {response.ResponseError.Err}");
520+
else
521+
{
522+
Assert.That(response.ResponseSuccess.Id == "te05k", $"The Response of the request through the method '{methodName}' did not return the expected task by ID!");
523+
Assert.That(response.ResponseSuccess.Name == "test task", $"The Response of the request through the method '{methodName}' did not return the expected task by name!");
524+
}
525+
}
526+
else
527+
{
528+
Assert.Fail($"The Response of the request through the method '{methodName}' is null!");
529+
}
530+
}
531+
498532
/// <summary>
499533
/// Tests of GetTasks method
500534
/// </summary>
@@ -1171,6 +1205,43 @@ public void ShouldEditListAsync()
11711205
#endregion
11721206

11731207
#region Tasks
1208+
/// <summary>
1209+
/// Tests of GetTaskByIdAsync method
1210+
/// </summary>
1211+
[Test]
1212+
public void ShouldGetTaskByIdAsync()
1213+
{
1214+
string methodName = "GetTaskByIdAsync";
1215+
ResponseGeneric<ResponseModelTask, ResponseError> response = null;
1216+
try
1217+
{
1218+
ClickUpApi clickUpAPI = new ClickUpApi(_accessToken);
1219+
Task.Run(async () => {
1220+
response = await clickUpAPI.GetTaskByIdAsync(new ParamsGetTaskById("te05k"));
1221+
})
1222+
.Wait();
1223+
}
1224+
catch (Exception ex)
1225+
{
1226+
Assert.Fail($"The Test Method of '{methodName}' generate exception: {ex.Message}"); // Always return false
1227+
}
1228+
if (response != null)
1229+
{
1230+
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
1231+
if (response.ResponseError != null)
1232+
Assert.Fail($"The Test Method of '{methodName}' generate an error with status: {response.RequestStatus} and response: {response.ResponseError.Err}");
1233+
else
1234+
{
1235+
Assert.That(response.ResponseSuccess.Id == "te05k", $"The Response of the request through the method '{methodName}' did not return the expected task by ID!");
1236+
Assert.That(response.ResponseSuccess.Name == "test task", $"The Response of the request through the method '{methodName}' did not return the expected task by name!");
1237+
}
1238+
}
1239+
else
1240+
{
1241+
Assert.Fail($"The Response of the request through the method '{methodName}' is null!");
1242+
}
1243+
}
1244+
11741245
/// <summary>
11751246
/// Tests of GetTasksAsync method
11761247
/// </summary>

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.6</Version>
15+
<Version>2.0.7</Version>
1616
<PackageReleaseNotes>
17+
Version 2.0.7
18+
19+
* Added an ability to get a task by its ID.
20+
1721
Version 2.0.6
1822

1923
* Added an ability to get team webhooks.

Chinchilla.ClickUp/ClickUpApi.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,22 @@ public ResponseGeneric<ResponseModelList, ResponseError> EditList(ParamsEditList
288288
#endregion
289289

290290
#region Tasks
291+
/// <summary>
292+
/// Get a task by id
293+
/// </summary>
294+
/// <param name="paramsGetTaskById">param object of get task by id request</param>
295+
/// <returns>ResponseGeneric with ResponseModelTask response object</returns>
296+
public ResponseGeneric<ResponseModelTask, ResponseError> GetTaskById(ParamsGetTaskById paramsGetTaskById)
297+
{
298+
var client = new RestClient(_baseAddress);
299+
var request = new RestRequest($"task/{paramsGetTaskById.TaskId}", Method.GET);
300+
request.AddHeader("authorization", _accessToken);
301+
302+
// execute the request
303+
ResponseGeneric<ResponseModelTask, ResponseError> result = RestSharperHelper.ExecuteRequest<ResponseModelTask, ResponseError>(client, request);
304+
return result;
305+
}
306+
291307
/// <summary>
292308
/// Get Tasks of the Team and filter its by optionalParams
293309
/// </summary>
@@ -593,6 +609,21 @@ public Task<ResponseGeneric<ResponseModelList, ResponseError>> EditListAsync(Par
593609
#endregion
594610

595611
#region Tasks
612+
/// <summary>
613+
/// Get a task by id
614+
/// </summary>
615+
/// <param name="paramsGetTaskById">param object of get task by id request</param>
616+
/// <returns>ResponseGeneric with ResponseModelTask response object</returns>
617+
public Task<ResponseGeneric<ResponseModelTask, ResponseError>> GetTaskByIdAsync(ParamsGetTaskById paramsGetTaskById)
618+
{
619+
var client = new RestClient(_baseAddress);
620+
var request = new RestRequest($"task/{paramsGetTaskById.TaskId}", Method.GET);
621+
request.AddHeader("authorization", _accessToken);
622+
623+
// execute the request
624+
return RestSharperHelper.ExecuteRequestAsync<ResponseModelTask, ResponseError>(client, request);
625+
}
626+
596627
/// <summary>
597628
/// Get Tasks of the Team and filter its by optionalParams
598629
/// </summary>
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 Get Task By ID request
10+
/// </summary>
11+
public class ParamsGetTaskById
12+
{
13+
#region Attributes
14+
15+
/// <summary>
16+
/// The Team Id
17+
/// </summary>
18+
[JsonProperty("task_id")]
19+
[DataMember(Name = "task_id")]
20+
public string TaskId { get; set; }
21+
22+
#endregion
23+
24+
25+
#region Constructor
26+
27+
/// <summary>
28+
/// The constructor of ParamsGetTasksById
29+
/// </summary>
30+
/// <param name="teamId"></param>
31+
public ParamsGetTaskById(string taskId)
32+
{
33+
TaskId = taskId;
34+
}
35+
36+
#endregion
37+
38+
39+
#region Public Methods
40+
41+
/// <summary>
42+
/// Method that validate the data insert
43+
/// </summary>
44+
public void ValidateData()
45+
{
46+
if (string.IsNullOrEmpty(TaskId))
47+
{
48+
throw new ArgumentNullException("TaskId");
49+
}
50+
}
51+
52+
#endregion
53+
}
54+
}

0 commit comments

Comments
 (0)