8000 Merge pull request #200 from notion-dotnet/feature/194-add-support-fo… · notion-dotnet/notion-sdk-net@815d879 · GitHub
[go: up one dir, main page]

Skip to content

Commit 815d879

Browse files
Merge pull request #200 from notion-dotnet/feature/194-add-support-for-audio-block
Add support for audio block 💖
2 parents 6ef3a9a + bbe9588 commit 815d879

File tree

8 files changed

+91
-0
lines changed

8 files changed

+91
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class AudioUpdateBlock : UpdateBlock, IUpdateBlock
6+
{
7+
[JsonProperty("audio")]
8+
public IFileObjectInput Audio { get; set; }
9+
}
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class AudioBlock : Block
6+
{
7+
public override BlockType Type => BlockType.Audio;
8+
9+
[JsonProperty("audio")]
10+
public FileObject Audio { get; set; }
11+
}
12+
}

Src/Notion.Client/Models/Blocks/Block.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Notion.Client
66
{
77
[JsonConverter(typeof(JsonSubtypes), "type")]
8+
[JsonSubtypes.KnownSubType(typeof(AudioBlock), BlockType.Audio)]
89
[JsonSubtypes.KnownSubType(typeof(BookmarkBlock), BlockType.Bookmark)]
910
[JsonSubtypes.KnownSubType(typeof(BulletedListItemBlock), BlockType.BulletedListItem)]
1011
[JsonSubtypes.KnownSubType(typeof(ChildPageBlock), BlockType.ChildPage)]

Src/Notion.Client/Models/Blocks/BlockType.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public enum BlockType
6464
[EnumMember(Value = "divider")]
6565
Divider,
6666

67+
[EnumMember(Value = "audio")]
68+
Audio,
69+
6770
[EnumMember(Value = "unsupported")]
6871
Unsupported
6972
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class ExternalFileInput : IFileObjectInput
6+
{
7+
[JsonProperty("external")]
8+
public Data External { get; set; }
9+
10+
public class Data
11+
{
12+
[JsonProperty("url")]
13+
public string Url { get; set; }
14+
}
15+
}
16+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Notion.Client
2+
{
3+
public interface IFileObjectInput
4+
{
5+
}
6+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public class UploadedFileInput : IFileObjectInput
7+
{
8+
[JsonProperty("file")]
9+
public Data File { get; set; }
10+
11+
public class Data
12+
{
13+
[JsonProperty("url")]
14+
public string Url { get; set; }
15+
16+
[JsonProperty("expiry_time")]
17+
public DateTime ExpiryTime { get; set; }
18+
}
19+
}
20+
}

Test/Notion.IntegrationTests/IBlocksClientTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,29 @@ private static IEnumerable<object[]> BlockData()
268268
Assert.NotNull(block);
269269
Assert.IsType<DividerBlock>(block);
270270
})
271+
},
272+
new object[] {
273+
new AudioBlock {
274+
Audio = new ExternalFile {
275+
External = new ExternalFile.Info {
276+
Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3"
277+
}
278+
}
279+
},
280+
new AudioUpdateBlock {
281+
Audio = new ExternalFileInput {
282+
External = new ExternalFileInput.Data {
283+
Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3"
284+
}
285+
}
286+
},
287+
new Action<Block>((block) => {
288+
block.Should().NotBeNull();
289+
290+
block.Should().BeOfType<AudioBlock>().Subject
291+
.Audio.Should().BeOfType<ExternalFile>().Subject
292+
.External.Url.Should().Be("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3");
293+
})
271294
}
272295
};
273296
}

0 commit comments

Comments
 (0)
0