Skip to content

Commit 135b515

Browse files
Merge pull request #436 from notion-dotnet/435-add-support-for-reading-and-writing-names-and-caption-to-file-blocks
Add support for reading and writing Name & Caption properties to file blocks
2 parents 0c6c67a + dcd3d98 commit 135b515

File tree

5 files changed

+75
-2
lines changed

5 files changed

+75
-2
lines changed

Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Newtonsoft.Json;
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
23

34
namespace Notion.Client
45
{
@@ -7,6 +8,12 @@ public class ExternalFileInput : IFileObjectInput
78
[JsonProperty("external")]
89
public Data External { get; set; }
910

11+
[JsonProperty("name")]
12+
public string Name { get; set; }
13+
14+
[JsonProperty("caption")]
15+
public IEnumerable<RichTextBaseInput> Caption { get; set; }
16+
1017
public class Data
1118
{
1219
[JsonProperty("url")]
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
namespace Notion.Client
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
25
{
36
public interface IFileObjectInput
47
{
8+
[JsonProperty("name")]
9+
public string Name { get; set; }
10+
11+
[JsonProperty("caption")]
12+
public IEnumerable<RichTextBaseInput> Caption { get; set; }
513
}
614
}

Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using Newtonsoft.Json;
34

45
namespace Notion.Client
@@ -8,6 +9,12 @@ public class UploadedFileInput : IFileObjectInput
89
[JsonProperty("file")]
910
public Data File { get; set; }
1011

12+
[JsonProperty("name")]
13+
public string Name { get; set; }
14+
15+
[JsonProperty("caption")]
16+
public IEnumerable<RichTextBaseInput> Caption { get; set; }
17+
1118
public class Data
1219
{
1320
[JsonProperty("url")]

Src/Notion.Client/Models/File/FileObject.cs

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public abstract class FileObject : IPageIcon
1212
[JsonProperty("caption")]
1313
public IEnumerable<RichTextBase> Caption { get; set; }
1414

15+
/// <summary>
16+
/// The name of the file block, as shown in the Notion UI. Note that the UI may auto-append .pdf or other extensions.
17+
/// </summary>
1518
[JsonProperty("name")]
1619
public string Name { get; set; }
1720

Test/Notion.IntegrationTests/BlocksClientTests.cs

+48
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,54 @@ private static IEnumerable<object[]> BlockData()
399399
.Subject.Should().BeOfType<RichTextText>()
400400
.Subject.Text.Content.Should().Be("Data");
401401
})
402+
},
403+
new object[]
404+
{
405+
new FileBlockRequest {
406+
File = new ExternalFile
407+
{
408+
Name = "Test file",
409+
External = new ExternalFile.Info
410+
{
411+
Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg"
412+
},
413+
Caption = new List<RichTextBase>
414+
{
415+
new RichTextTextInput { Text = new Text { Content = "Test file" } }
416+
}
417+
}
418+
},
419+
new FileUpdateBlock
420+
{
421+
File = new ExternalFileInput
422+
{
423+
Name = "Test file name",
424+
External = new ExternalFileInput.Data
425+
{
426+
Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg"
427+
},
428+
Caption = new List<RichTextBaseInput>
429+
{
430+
new RichTextTextInput { Text = new Text { Content = "Test file caption" } }
431+
}
432+
}
433+
},
434+
new Action<IBlock, INotionClient>((block, client) =>
435+
{
436+
var fileBlock = block.Should().NotBeNull().And.BeOfType<FileBlock>().Subject;
437+
fileBlock.HasChildren.Should().BeFalse();
438+
439+
var file = fileBlock.File.Should().NotBeNull().And.BeOfType<ExternalFile>().Subject;
440+
441+
// NOTE: The name of the file block, as shown in the Notion UI. Note that the UI may auto-append .pdf or other extensions.
442+
file.Name.Should().Be("Test file name.jpg");
443+
444+
file.External.Should().NotBeNull();
445+
file.External.Url.Should().Be("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg");
446+
file.Caption.Should().NotBeNull().And.ContainSingle()
447+
.Subject.Should().BeOfType<RichTextText>().Subject
448+
.Text.Content.Should().Be("Test file caption");
449+
})
402450
}
403451
};
404452
}

0 commit comments

Comments
 (0)