Skip to content

Added support for button properties. #418

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
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
16 changes: 16 additions & 0 deletions Src/Notion.Client/Models/Database/Properties/ButtonProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using System.Threading.Tasks;

namespace Notion.Client
{
public class ButtonProperty : Property
{
public override PropertyType Type => PropertyType.Button;

[JsonProperty("button")]
public Dictionary<string,object> Button { get; set; }
}
}
1 change: 1 addition & 0 deletions Src/Notion.Client/Models/Database/Properties/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace Notion.Client
[JsonSubtypes.KnownSubTypeAttribute(typeof(TitleProperty), PropertyType.Title)]
[JsonSubtypes.KnownSubTypeAttribute(typeof(UrlProperty), PropertyType.Url)]
[JsonSubtypes.KnownSubTypeAttribute(typeof(UniqueIdProperty), PropertyType.UniqueId)]
[JsonSubtypes.KnownSubTypeAttribute(typeof(ButtonProperty), PropertyType.Button)]
public class Property
{
[JsonProperty("id")]
Expand Down
3 changes: 3 additions & 0 deletions Src/Notion.Client/Models/Database/Properties/PropertyType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,8 @@ public enum PropertyType

[EnumMember(Value = "unique_id")]
UniqueId,

[EnumMember(Value = "button")]
Button,
}
}
17 changes: 17 additions & 0 deletions Src/Notion.Client/Models/PropertyValue/ButtonPropertyValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;

namespace Notion.Client
{
public class ButtonPropertyValue : PropertyValue
{
public override PropertyValueType Type => PropertyValueType.Button;

[JsonProperty("button")]
public ButtonValue Button { get; set; }

public class ButtonValue { }
}
}
1 change: 1 addition & 0 deletions Src/Notion.Client/Models/PropertyValue/PropertyValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace Notion.Client
[JsonSubtypes.KnownSubTypeAttribute(typeof(TitlePropertyValue), PropertyValueType.Title)]
[JsonSubtypes.KnownSubTypeAttribute(typeof(UrlPropertyValue), PropertyValueType.Url)]
[JsonSubtypes.KnownSubTypeAttribute(typeof(UniqueIdPropertyValue), PropertyValueType.UniqueId)]
[JsonSubtypes.KnownSubTypeAttribute(typeof(ButtonPropertyValue), PropertyValueType.Button)]
[JsonSubtypes.KnownSubTypeAttribute(typeof(VerificationPropertyValue), PropertyValueType.Verification)]
[SuppressMessage("ReSharper", "UnusedMember.Global")]
[SuppressMessage("ReSharper", "UnassignedGetOnlyAutoProperty")]
Expand Down
3 changes: 3 additions & 0 deletions Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,8 @@ public enum PropertyValueType

[EnumMember(Value = "verification")]
Verification,

[EnumMember(Value = "button")]
Button,
}
}
2 changes: 1 addition & 1 deletion Test/Notion.UnitTests/PagesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public async Task TrashPageAsync()

page.Id.Should().Be(pageId);
page.InTrash.Should().BeTrue();
page.Properties.Should().HaveCount(2);
page.Properties.Should().HaveCount(3);
var updatedProperty = page.Properties.First(x => x.Key == "In stock");

var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItemAsync(
Expand Down
2 changes: 2 additions & 0 deletions Test/Notion.UnitTests/PropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class PropertyTests
[InlineData(typeof(TitleProperty), PropertyType.Title)]
[InlineData(typeof(UrlProperty), PropertyType.Url)]
[InlineData(typeof(UniqueIdProperty), PropertyType.UniqueId)]
[InlineData(typeof(ButtonProperty),PropertyType.Button)]
public void TestPropertyType(Type type, PropertyType expectedPropertyType)
{
var typeInstance = (Property)Activator.CreateInstance(type);
Expand Down Expand Up @@ -56,6 +57,7 @@ public void TestPropertyType(Type type, PropertyType expectedPropertyType)
[InlineData(typeof(TitleProperty), "title")]
[InlineData(typeof(UrlProperty), "url")]
[InlineData(typeof(UniqueIdProperty), "unique_id")]
[InlineData(typeof(ButtonProperty), "button")]
public void TestPropertyTypeText(Type type, string expectedPropertyType)
{
var typeInstance = (Property)Activator.CreateInstance(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
}
}
},
"SimpleButton": {
"id":"_ri%7C",
"name":"SimpleButton",
"type":"button",
"button": {}
},
"Name": {
"id": "title",
"name": "Name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
}
}
},
"SimpleButton": {
"id":"_ri%7C",
"name":"SimpleButton",
"type":"button",
"button": {}
},
"Name": {
"id": "title",
"name": "Name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
"id": "{>U;",
"type": "checkbox",
"checkbox": false
},
"Add Page Button": {
"id":"_ri%7C",
"type":"button",
"button": {}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Test/Notion.UnitTests/data/pages/TrashPageResponse.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
"type": "checkbox",
"checkbox": true
},
"Add Page Button": {
"id":"_ri%7C",
"type":"button",
"button": {}
},
"Name": {
"id": "title",
"type": "title",
Expand Down
Loading