Skip to content

Commit ae94eb5

Browse files
add support for reading and writing Name & Caption properties to file blocks ✨
1 parent 0c6c67a commit ae94eb5

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

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

Lines changed: 6 additions & 1 deletion
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,10 @@ public class ExternalFileInput : IFileObjectInput
78
[JsonProperty("external")]
89
public Data External { get; set; }
910

11+
public string Name { get; set; }
12+
13+
public IEnumerable<RichTextBaseInput> Caption { get; set; }
14+
1015
public class Data
1116
{
1217
[JsonProperty("url")]
Lines changed: 9 additions & 1 deletion
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

Lines changed: 5 additions & 0 deletions
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,10 @@ public class UploadedFileInput : IFileObjectInput
89
[JsonProperty("file")]
910
public Data File { get; set; }
1011

12+
public string Name { get; set; }
13+
14+
public IEnumerable<RichTextBaseInput> Caption { get; set; }
15+
1116
public class Data
1217
{
1318
[JsonProperty("url")]

Test/Notion.IntegrationTests/BlocksClientTests.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,51 @@ 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+
file.Name.Should().Be("Test file name.jpg");
441+
file.External.Should().NotBeNull();
442+
file.External.Url.Should().Be("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg");
443+
file.Caption.Should().NotBeNull().And.ContainSingle()
444+
.Subject.Should().BeOfType<RichTextText>().Subject
445+
.Text.Content.Should().Be("Test file caption");
446+
})
402447
}
403448
};
404449
}

0 commit comments

Comments
 (0)