Skip to content

Commit e23801b

Browse files
Merge pull request #493 from notion-dotnet/481-add-support-to-list-file-uploads
Add support to List file uploads API
2 parents 46df956 + 35aa804 commit e23801b

File tree

8 files changed

+141
-0
lines changed

8 files changed

+141
-0
lines changed

Src/Notion.Client/Api/ApiEndpoints.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public static class FileUploadsApiUrls
145145
public static string Create() => "/v1/file_uploads";
146146
public static string Send(string fileUploadId) => $"/v1/file_uploads/{fileUploadId}/send";
147147
public static string Complete(string fileUploadId) => $"/v1/file_uploads/{fileUploadId}/complete";
148+
public static string List => "/v1/file_uploads";
148149
}
149150
}
150151
}

Src/Notion.Client/Api/FileUploads/IFileUploadsClient.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,16 @@ Task<CompleteFileUploadResponse> CompleteAsync(
4040
CompleteFileUploadRequest completeFileUploadRequest,
4141
CancellationToken cancellationToken = default
4242
);
43+
44+
/// <summary>
45+
/// List File Uploads for the current bot integration, sorted by most recent first.
46+
/// </summary>
47+
/// <param name="request"></param>
48+
/// <param name="cancellationToken"></param>
49+
/// <returns></returns>
50+
Task<ListFileUploadsResponse> ListAsync(
51+
ListFileUploadsRequest request,
52+
CancellationToken cancellationToken = default
53+
);
4354
}
4455
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
4+
namespace Notion.Client
5+
{
6+
public sealed partial class FileUploadsClient
7+
{
8+
public async Task<ListFileUploadsResponse> ListAsync(
9+
ListFileUploadsRequest request,
10+
System.Threading.CancellationToken cancellationToken = default)
11+
{
12+
IListFileUploadsQueryParameters queryParameters = request;
13+
14+
var queryParams = new Dictionary<string, string>
15+
{
16+
{ "page_size", queryParameters.PageSize?.ToString() },
17+
{ "start_cursor", queryParameters.StartCursor },
18+
{ "status", queryParameters.Status }
19+
};
20+
21+
return await _restClient.GetAsync<ListFileUploadsResponse>(
22+
ApiEndpoints.FileUploadsApiUrls.List,
23+
queryParams: queryParams,
24+
cancellationToken: cancellationToken
25+
);
26+
}
27+
}
28+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace Notion.Client
2+
{
3+
public interface IListFileUploadsQueryParameters
4+
{
5+
/// <summary>
6+
/// Filter file uploads by specifying the status. Supported values are "pending", "uploaded", "expired", "failed".
7+
/// </summary>
8+
string Status { get; set; }
9+
10+
/// <summary>
11+
/// If supplied, this endpoint will return a page of results starting after the cursor provided.
12+
/// If not supplied, this endpoint will return the first page of results.
13+
/// </summary>
14+
string StartCursor { get; set; }
15+
16+
/// <summary>
17+
/// The number of items from the full list desired in the response. Maximum: 100
18+
/// Default to 100
19+
/// </summary>
20+
int? PageSize { get; set; }
21+
}
22+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Notion.Client
2+
{
3+
public class ListFileUploadsRequest : IListFileUploadsQueryParameters
4+
{
5+
public string Status { get; set; }
6+
public string StartCursor { get; set; }
7+
public int? PageSize { get; set; }
8+
}
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public class ListFileUploadsResponse : PaginatedList<FileObjectResponse>
7+
{
8+
[JsonProperty("file_uploads")]
9+
public Dictionary<string, object> FileUploads { get; set; }
10+
}
11+
}

Test/Notion.IntegrationTests/FileUploadsClientTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,23 @@ public async Task Verify_multi_part_file_upload_flow()
121121
Assert.Equal("completed", completeResponse.Status);
122122
}
123123
}
124+
125+
[Fact]
126+
public async Task ListAsync()
127+
{
128+
// Arrange
129+
var request = new ListFileUploadsRequest
130+
{
131+
PageSize = 5
132+
};
133+
134+
// Act
135+
var response = await Client.FileUploads.ListAsync(request);
136+
137+
// Assert
138+
Assert.NotNull(response);
139+
Assert.NotNull(response.Results);
140+
Assert.True(response.Results.Count <= 5);
141+
}
124142
}
125143
}

Test/Notion.UnitTests/FileUploadsClientTests.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,45 @@ public async Task SendAsync_CallsRestClientPostAsync_WithCorrectParameters()
178178
Assert.Equal(expectedResponse.Id, response.Id);
179179
_restClientMock.VerifyAll();
180180
}
181+
182+
#region ListAsync Tests
183+
184+
[Fact]
185+
public async Task ListAsync_CallsRestClientGetAsync_WithCorrectParameters()
186+
{
187+
// Arrange
188+
var request = new ListFileUploadsRequest
189+
{
190+
PageSize = 10,
191+
StartCursor = "cursor123",
192+
Status = "completed"
193+
};
194+
195+
_restClientMock
196+
.Setup(client => client.GetAsync<ListFileUploadsResponse>(
197+
It.Is<string>(url => url == ApiEndpoints.FileUploadsApiUrls.List),
198+
It.IsAny<IDictionary<string, string>>(),
199+
null,
200+
null,
201+
It.IsAny<CancellationToken>()
202+
))
203+
.ReturnsAsync(new ListFileUploadsResponse
204+
{
205+
Results = new List<FileObjectResponse>
206+
{
207+
new() { Id = "file1", Status = "completed" },
208+
new() { Id = "file2", Status = "completed" }
209+
}
210+
});
211+
212+
// Act
213+
var response = await _fileUploadClient.ListAsync(request);
214+
215+
// Assert
216+
Assert.NotNull(response);
217+
Assert.Equal(2, response.Results.Count);
218+
_restClientMock.VerifyAll();
219+
}
220+
221+
#endregion ListAsync Tests
181222
}

0 commit comments

Comments
 (0)