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
1 change: 1 addition & 0 deletions Src/Notion.Client/Api/ApiEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public static class FileUploadsApiUrls
public static string Create() => "/v1/file_uploads";
public static string Send(string fileUploadId) => $"/v1/file_uploads/{fileUploadId}/send";
public static string Complete(string fileUploadId) => $"/v1/file_uploads/{fileUploadId}/complete";
public static string List => "/v1/file_uploads";
}
}
}
11 changes: 11 additions & 0 deletions Src/Notion.Client/Api/FileUploads/IFileUploadsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,16 @@ Task<CompleteFileUploadResponse> CompleteAsync(
CompleteFileUploadRequest completeFileUploadRequest,
CancellationToken cancellationToken = default
);

/// <summary>
/// List File Uploads for the current bot integration, sorted by most recent first.
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<ListFileUploadsResponse> ListAsync(
ListFileUploadsRequest request,
CancellationToken cancellationToken = default
);
}
}
28 changes: 28 additions & 0 deletions Src/Notion.Client/Api/FileUploads/List/FileUploadsClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Notion.Client
{
public sealed partial class FileUploadsClient
{
public async Task<ListFileUploadsResponse> ListAsync(
ListFileUploadsRequest request,
System.Threading.CancellationToken cancellationToken = default)
{
IListFileUploadsQueryParameters queryParameters = request;

var queryParams = new Dictionary<string, string>
{
{ "page_size", queryParameters.PageSize?.ToString() },
{ "start_cursor", queryParameters.StartCursor },
{ "status", queryParameters.Status }
};

return await _restClient.GetAsync<ListFileUploadsResponse>(
ApiEndpoints.FileUploadsApiUrls.List,
queryParams: queryParams,
cancellationToken: cancellationToken
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Notion.Client
{
public interface IListFileUploadsQueryParameters
{
/// <summary>
/// Filter file uploads by specifying the status. Supported values are "pending", "uploaded", "expired", "failed".
/// </summary>
string Status { get; set; }

/// <summary>
/// If supplied, this endpoint will return a page of results starting after the cursor provided.
/// If not supplied, this endpoint will return the first page of results.
/// </summary>
string StartCursor { get; set; }

/// <summary>
/// The number of items from the full list desired in the response. Maximum: 100
/// Default to 100
/// </summary>
int? PageSize { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Notion.Client
{
public class ListFileUploadsRequest : IListFileUploadsQueryParameters
{
public string Status { get; set; }
public string StartCursor { get; set; }
public int? PageSize { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class ListFileUploadsResponse : PaginatedList<FileObjectResponse>
{
[JsonProperty("file_uploads")]
public Dictionary<string, object> FileUploads { get; set; }
}
}
18 changes: 18 additions & 0 deletions Test/Notion.IntegrationTests/FileUploadsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,23 @@ public async Task Verify_multi_part_file_upload_flow()
Assert.Equal("completed", completeResponse.Status);
}
}

[Fact]
public async Task ListAsync()
{
// Arrange
var request = new ListFileUploadsRequest
{
PageSize = 5
};

// Act
var response = await Client.FileUploads.ListAsync(request);

// Assert
Assert.NotNull(response);
Assert.NotNull(response.Results);
Assert.True(response.Results.Count <= 5);
}
}
}
41 changes: 41 additions & 0 deletions Test/Notion.UnitTests/FileUploadsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,45 @@ public async Task SendAsync_CallsRestClientPostAsync_WithCorrectParameters()
Assert.Equal(expectedResponse.Id, response.Id);
_restClientMock.VerifyAll();
}

#region ListAsync Tests

[Fact]
public async Task ListAsync_CallsRestClientGetAsync_WithCorrectParameters()
{
// Arrange
var request = new ListFileUploadsRequest
{
PageSize = 10,
StartCursor = "cursor123",
Status = "completed"
};

_restClientMock
.Setup(client => client.GetAsync<ListFileUploadsResponse>(
It.Is<string>(url => url == ApiEndpoints.FileUploadsApiUrls.List),
It.IsAny<IDictionary<string, string>>(),
null,
null,
It.IsAny<CancellationToken>()
))
.ReturnsAsync(new ListFileUploadsResponse
{
Results = new List<FileObjectResponse>
{
new() { Id = "file1", Status = "completed" },
new() { Id = "file2", Status = "completed" }
}
});

// Act
var response = await _fileUploadClient.ListAsync(request);

// Assert
Assert.NotNull(response);
Assert.Equal(2, response.Results.Count);
_restClientMock.VerifyAll();
}

#endregion ListAsync Tests
}
Loading