8000 Add support for additional block types by KoditkarVedant · Pull Request #149 · notion-dotnet/notion-sdk-net · GitHub
[go: up one dir, main page]

Skip to content

Add support for additional block types #149

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Notion.Client
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using Newtonsoft.Json;

namespace Notion.Client
Expand Down
9 changes: 9 additions & 0 deletions Src/Notion.Client/Models/Blocks/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@
namespace Notion.Client
{
[JsonConverter(typeof(JsonSubtypes), "type")]
[JsonSubtypes.KnownSubType(typeof(BookmarkBlock), BlockType.Bookmark)]
[JsonSubtypes.KnownSubType(typeof(BulletedListItemBlock), BlockType.BulletedListItem)]
[JsonSubtypes.KnownSubType(typeof(ChildPageBlock), BlockType.ChildPage)]
[JsonSubtypes.KnownSubType(typeof(ChildDatabaseBlock), BlockType.ChildDatabase)]
[JsonSubtypes.KnownSubType(typeof(CodeBlock), BlockType.Code)]
[JsonSubtypes.KnownSubType(typeof(EmbedBlock), BlockType.Embed)]
[JsonSubtypes.KnownSubType(typeof(EquationBlock), BlockType.Equation)]
[JsonSubtypes.KnownSubType(typeof(FileBlock), BlockType.File)]
[JsonSubtypes.KnownSubType(typeof(HeadingOneBlock), BlockType.Heading_1)]
[JsonSubtypes.KnownSubType(typeof(HeadingTwoBlock), BlockType.Heading_2)]
[JsonSubtypes.KnownSubType(typeof(HeadingThreeeBlock), BlockType.Heading_3)]
[JsonSubtypes.KnownSubType(typeof(ImageBlock), BlockType.Image)]
[JsonSubtypes.KnownSubType(typeof(NumberedListItemBlock), BlockType.NumberedListItem)]
[JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)]
[JsonSubtypes.KnownSubType(typeof(PDFBlock), BlockType.PDF)]
[JsonSubtypes.KnownSubType(typeof(ToDoBlock), BlockType.ToDo)]
[JsonSubtypes.KnownSubType(typeof(ToggleBlock), BlockType.Toggle)]
[JsonSubtypes.KnownSubType(typeof(VideoBlock), BlockType.Video)]
[JsonSubtypes.KnownSubType(typeof(UnsupportedBlock), BlockType.Unsupported)]
public class Block : IObject
{
Expand Down
27 changes: 27 additions & 0 deletions Src/Notion.Client/Models/Blocks/BlockType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,33 @@ public enum BlockType
[EnumMember(Value = "child_page")]
ChildPage,

[EnumMember(Value = "code")]
Code,

[EnumMember(Value = "child_database")]
ChildDatabase,

[EnumMember(Value = "embed")]
Embed,

[EnumMember(Value = "image")]
Image,

[EnumMember(Value = "video")]
Video,

[EnumMember(Value = "file")]
File,

[EnumMember(Value = "pdf")]
PDF,

[EnumMember(Value = "bookmark")]
Bookmark,

[EnumMember(Value = "equation")]
Equation,

[EnumMember(Value = "unsupported")]
Unsupported
}
Expand Down
18 changes: 18 additions & 0 deletions Src/Notion.Client/Models/Blocks/BookmarkBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class BookmarkBlock : Block
{
public override BlockType Type => BlockType.Bookmark;

[JsonProperty("bookmark")]
public Info Bookmark { get; set; }

public class Info
{
[JsonProperty("url")]
public string Url { get; set; }
}
}
}
18 changes: 18 additions & 0 deletions Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class ChildDatabaseBlock : Block
{
public override BlockType Type => BlockType.ChildDatabase;

[JsonProperty("child_database")]
public Info ChildDatabase { get; set; }

public class Info
{
[JsonProperty("title")]
public string Title { get; set; }
}
}
}
22 changes: 22 additions & 0 deletions Src/Notion.Client/Models/Blocks/CodeBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class CodeBlock : Block
{
public override BlockType Type => BlockType.Code;

[JsonProperty("code")]
public Info Code { get; set; }

public class Info
{
[JsonProperty("text")]
public IEnumerable<RichTextBase> Text { get; set; }

[JsonProperty("language")]
public string Language { get; set; }
}
}
}
18 changes: 18 additions & 0 deletions Src/Notion.Client/Models/Blocks/EmbedBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class EmbedBlock : Block
{
public override BlockType Type => BlockType.Embed;

[JsonProperty("embed")]
public Info Embed { get; set; }

public class Info
{
[JsonProperty("url")]
public string Url { get; set; }
}
}
}
18 changes: 18 additions & 0 deletions Src/Notion.Client/Models/Blocks/EquationBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class EquationBlock : Block
{
public override BlockType Type => BlockType.Equation;

[JsonProperty("equation")]
public Info Equation { get; set; }

public class Info
{
[JsonProperty("expression")]
public string Expression { get; set; }
}
}
}
12 changes: 12 additions & 0 deletions Src/Notion.Client/Models/Blocks/FileBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class FileBlock : Block
{
public override BlockType Type => BlockType.File;

[JsonProperty("file")]
public FileObject File { get; set; }
}
}
12 changes: 12 additions & 0 deletions Src/Notion.Client/Models/Blocks/ImageBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class ImageBlock : Block
{
public override BlockType Type => BlockType.Image;

[JsonProperty("image")]
public FileObject Image { get; set; }
}
}
12 changes: 12 additions & 0 deletions Src/Notion.Client/Models/Blocks/PDFBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class PDFBlock : Block
{
public override BlockType Type => BlockType.PDF;

[JsonProperty("pdf")]
public FileObject PDF { get; set; }
}
}
12 changes: 12 additions & 0 deletions Src/Notion.Client/Models/Blocks/VideoBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class VideoBlock : Block
{
public override BlockType Type => BlockType.Video;

[JsonProperty("video")]
public FileObject Video { get; set; }
}
}
0