diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs new file mode 100644 index 00000000..f341e441 --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class AudioUpdateBlock : UpdateBlock, IUpdateBlock + { + [JsonProperty("audio")] + public IFileObjectInput Audio { get; set; } + } +} diff --git a/Src/Notion.Client/Models/Blocks/AudioBlock.cs b/Src/Notion.Client/Models/Blocks/AudioBlock.cs new file mode 100644 index 00000000..b43bbc9c --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/AudioBlock.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class AudioBlock : Block + { + public override BlockType Type => BlockType.Audio; + + [JsonProperty("audio")] + public FileObject Audio { get; set; } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Block.cs b/Src/Notion.Client/Models/Blocks/Block.cs index 34c3b7b6..2f34d5d4 100644 --- a/Src/Notion.Client/Models/Blocks/Block.cs +++ b/Src/Notion.Client/Models/Blocks/Block.cs @@ -5,6 +5,7 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] + [JsonSubtypes.KnownSubType(typeof(AudioBlock), BlockType.Audio)] [JsonSubtypes.KnownSubType(typeof(BookmarkBlock), BlockType.Bookmark)] [JsonSubtypes.KnownSubType(typeof(BulletedListItemBlock), BlockType.BulletedListItem)] [JsonSubtypes.KnownSubType(typeof(ChildPageBlock), BlockType.ChildPage)] diff --git a/Src/Notion.Client/Models/Blocks/BlockType.cs b/Src/Notion.Client/Models/Blocks/BlockType.cs index 7a29fbe9..75d3a671 100644 --- a/Src/Notion.Client/Models/Blocks/BlockType.cs +++ b/Src/Notion.Client/Models/Blocks/BlockType.cs @@ -64,6 +64,9 @@ public enum BlockType [EnumMember(Value = "divider")] Divider, + [EnumMember(Value = "audio")] + Audio, + [EnumMember(Value = "unsupported")] Unsupported } diff --git a/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs b/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs new file mode 100644 index 00000000..9c258ceb --- /dev/null +++ b/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class ExternalFileInput : IFileObjectInput + { + [JsonProperty("external")] + public Data External { get; set; } + + public class Data + { + [JsonProperty("url")] + public string Url { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/File/FIleInput/IFileObjectInput.cs b/Src/Notion.Client/Models/File/FIleInput/IFileObjectInput.cs new file mode 100644 index 00000000..31df1573 --- /dev/null +++ b/Src/Notion.Client/Models/File/FIleInput/IFileObjectInput.cs @@ -0,0 +1,6 @@ +namespace Notion.Client +{ + public interface IFileObjectInput + { + } +} diff --git a/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs b/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs new file mode 100644 index 00000000..52d7934d --- /dev/null +++ b/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs @@ -0,0 +1,20 @@ +using System; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class UploadedFileInput : IFileObjectInput + { + [JsonProperty("file")] + public Data File { get; set; } + + public class Data + { + [JsonProperty("url")] + public string Url { get; set; } + + [JsonProperty("expiry_time")] + public DateTime ExpiryTime { get; set; } + } + } +} diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index e141880f..34140883 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -268,6 +268,29 @@ private static IEnumerable BlockData() Assert.NotNull(block); Assert.IsType(block); }) + }, + new object[] { + new AudioBlock { + Audio = new ExternalFile { + External = new ExternalFile.Info { + Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3" + } + } + }, + new AudioUpdateBlock { + Audio = new ExternalFileInput { + External = new ExternalFileInput.Data { + Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3" + } + } + }, + new Action((block) => { + block.Should().NotBeNull(); + + block.Should().BeOfType().Subject + .Audio.Should().BeOfType().Subject + .External.Url.Should().Be("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3"); + }) } }; }