8000 Add support for reading and writing Name & Caption properties to file blocks by KoditkarVedant · Pull Request #436 · notion-dotnet/notion-sdk-net · GitHub
[go: up one dir, main page]

Skip to content

Add support for reading and writing Name & Caption properties to file blocks #436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9 changes: 8 additions & 1 deletion Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using Newtonsoft.Json;

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

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("caption")]
public IEnumerable<RichTextBaseInput> Caption { get; set; }

public class Data
{
[JsonProperty("url")]
Expand Down
10 changes: 9 additions & 1 deletion Src/Notion.Client/Models/File/FIleInput/IFileObjectInput.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
namespace Notion.Client
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public interface IFileObjectInput
{
[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("caption")]
public IEnumerable<RichTextBaseInput> Caption { get; set; }
}
}
7 changes: 7 additions & 0 deletions Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs
< 10000 /tr>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

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

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("caption")]
public IEnumerable<RichTextBaseInput> Caption { get; set; }

public class Data
{
[JsonProperty("url")]
Expand Down
3 changes: 3 additions & 0 deletions Src/Notion.Client/Models/File/FileObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public abstract class FileObject : IPageIcon
[JsonProperty("caption")]
public IEnumerable<RichTextBase> Caption { get; set; }

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

Expand Down
48 changes: 48 additions & 0 deletions Test/Notion.IntegrationTests/BlocksClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,54 @@ private static IEnumerable<object[]> BlockData()
.Subject.Should().BeOfType<RichTextText>()
.Subject.Text.Content.Should().Be("Data");
})
},
new object[]
{
new FileBlockRequest {
File = new ExternalFile
{
Name = "Test file",
External = new ExternalFile.Info
{
Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg"
},
Caption = new List<RichTextBase>
{
new RichTextTextInput { Text = new Text { Content = "Test file" } }
}
}
},
new FileUpdateBlock
{
File = new ExternalFileInput
{
Name = "Test file name",
External = new ExternalFileInput.Data
{
Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg"
},
Caption = new List<RichTextBaseInput>
{
new RichTextTextInput { Text = new Text { Content = "Test file caption" } }
}
}
},
new Action<IBlock, INotionClient>((block, client) =>
{
var fileBlock = block.Should().NotBeNull().And.BeOfType<FileBlock>().Subject;
fileBlock.HasChildren.Should().BeFalse();

var file = fileBlock.File.Should().NotBeNull().And.BeOfType<ExternalFile>().Subject;

// NOTE: The name of the file block, as shown in the Notion UI. Note that the UI may auto-append .pdf or other extensions.
file.Name.Should().Be("Test file name.jpg");

file.External.Should().NotBeNull();
file.External.Url.Should().Be("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg");
file.Caption.Should().NotBeNull().And.ContainSingle()
.Subject.Should().BeOfType<RichTextText>().Subject
.Text.Content.Should().Be("Test file caption");
})
}
};
}
Expand Down
Loading
0