Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
HermanSchoenfeld committed Oct 31, 2024
2 parents d6731b5 + 172570c commit da3d9da
Show file tree
Hide file tree
Showing 46 changed files with 134 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Src/Notion.Client/Api/Blocks/IBlocksClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Task<AppendChildrenResponse> AppendChildrenAsync(
);

/// <summary>
/// Sets a Block object, including page blocks, to archived: true using the ID specified.
/// Moves a Block object, including page blocks, to the trash: true using the ID specified.
/// </summary>
/// <param name="blockId">Identifier for a Notion block</param>
Task DeleteAsync(string blockId, CancellationToken cancellationToken = default);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class BookmarkUpdateBlock : IUpdateBlock
[JsonProperty("bookmark")]
public Info Bookmark { get; set; }

public bool Archived { get; set; }
public bool InTrash { get; set; }

public class Info
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public BreadcrumbUpdateBlock()
[JsonProperty("breadcrumb")]
public Info Breadcrumb { get; set; }

public bool Archived { get; set; }
public bool InTrash { get; set; }

public class Info
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public DividerUpdateBlock()
[JsonProperty("divider")]
public Info Divider { get; set; }

public bool Archived { get; set; }
public bool InTrash { get; set; }

public class Info
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Notion.Client
{
public interface IUpdateBlock
{
[JsonProperty("archived")]
bool Archived { get; set; }
[JsonProperty("in_trash")]
bool InTrash { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public TableOfContentsUpdateBlock()
[JsonProperty("table_of_contents")]
public Info TableOfContents { get; set; }

public bool Archived { get; set; }
public bool InTrash { get; set; }

public class Info
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
public abstract class UpdateBlock : IUpdateBlock
{
public bool Archived { get; set; }
public bool InTrash { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class DatabasesUpdateParameters : IDatabasesUpdateBodyParameters

public FileObject Cover { get; set; }

public bool Archived { get; set; }
public bool InTrash { get; set; }

public bool? IsInline { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public interface IDatabasesUpdateBodyParameters
[JsonProperty("cover")]
FileObject Cover { get; set; }

[JsonProperty("archived")]
bool Archived { get; set; }
[JsonProperty("in_trash")]
bool InTrash { get; set; }

[JsonProperty("is_inline")]
bool? IsInline { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace Notion.Client
{
public interface IPagesUpdateBodyParameters
{
[JsonProperty("archived")]
bool Archived { get; set; }
[JsonProperty("in_trash")]
bool InTrash { get; set; }

[JsonProperty("properties")]
IDictionary<string, PropertyValue> Properties { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class PagesUpdateParameters : IPagesUpdateBodyParameters
[JsonProperty("cover")]
public FileObject Cover { get; set; }

[JsonProperty("archived")]
public bool Archived { get; set; }
[JsonProperty("in_trash")]
public bool InTrash { get; set; }

[JsonProperty("properties")]
public IDictionary<string, PropertyValue> Properties { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions Src/Notion.Client/Models/Blocks/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public abstract class Block : IBlock

public virtual bool HasChildren { get; set; }

public bool InTrash { get; set; }

public PartialUser CreatedBy { get; set; }

public PartialUser LastEditedBy { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions Src/Notion.Client/Models/Blocks/IBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public interface IBlock : IObject, IObjectModificationData
[JsonProperty("has_children")]
bool HasChildren { get; set; }

[JsonProperty("in_trash")]
bool InTrash { get; set; }

[JsonProperty("parent")]
IBlockParent Parent { get; set; }
}
Expand Down
7 changes: 2 additions & 5 deletions Src/Notion.Client/Models/Database/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ public class Database : IObject, IObjectModificationData, IWikiDatabase
[JsonProperty("url")]
public string Url { get; set; }

/// <summary>
/// The archived status of the database.
/// </summary>
[JsonProperty("archived")]
public bool Archived { get; set; }
[JsonProperty("in_trash")]
public bool InTrash { get; set; }

[JsonProperty("is_inline")]
public bool IsInline { get; set; }
Expand Down
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,
}
}
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; }

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

[JsonProperty("type")]
public virtual string Type { get; set; }
}
Expand Down
6 changes: 3 additions & 3 deletions Src/Notion.Client/Models/Page/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public class Page : IObject, IObjectModificationData, IWikiDatabase
public IPageParent Parent { get; set; }

/// <summary>
/// The archived status of the page.
/// Indicates whether the page is currently in the trash.
/// </summary>
[JsonProperty("archived")]
public bool IsArchived { get; set; }
[JsonProperty("in_trash")]
public bool InTrash { get; set; }

/// <summary>
/// Property values of this page.
Expand Down
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,
}
}
5 changes: 4 additions & 1 deletion Src/Notion.Client/NotionAPIErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ public enum NotionAPIErrorCode
[EnumMember(Value = "internal_server_error")]
InternalServerError,

[EnumMember(Value = "bad_gateway")]
BadGateway,

[EnumMember(Value = "service_unavailable")]
ServiceUnavailable,

[EnumMember(Value = "database_connection_unavailable")]
DatabaseConnectionUnavailable,

[EnumMember(Value = "gateway_timeout")]
GetewayTimeout
GatewayTimeout
}
}
2 changes: 1 addition & 1 deletion Test/Notion.IntegrationTests/BlocksClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task InitializeAsync()

public async Task DisposeAsync()
{
await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true });
await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { InTrash = true });
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion Test/Notion.IntegrationTests/CommentsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task InitializeAsync()

public async Task DisposeAsync()
{
await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true });
await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { InTrash = true });
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion Test/Notion.IntegrationTests/DatabasesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task InitializeAsync()

public async Task DisposeAsync()
{
await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true });
await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { InTrash = true });
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion Test/Notion.IntegrationTests/PageClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public async Task InitializeAsync()

public async Task DisposeAsync()
{
await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true });
await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { InTrash = true });
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion Test/Notion.IntegrationTests/PageWithPageParentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task InitializeAsync()

public async Task DisposeAsync()
{
await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true });
await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { InTrash = true });
}

[Fact]
Expand Down
1 change: 1 addition & 0 deletions Test/Notion.UnitTests/BlocksClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public async Task UpdateAsync()

block.Id.Should().Be(blockId);
block.HasChildren.Should().BeFalse();
block.InTrash.Should().BeFalse();
block.Type.Should().Be(BlockType.ToDo);

var todoBlock = (ToDoBlock)block;
Expand Down
2 changes: 1 addition & 1 deletion Test/Notion.UnitTests/Notion.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<None Update="data\databases\UpdateDatabaseResponse.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\pages\ArchivePageResponse.json">
<None Update="data\pages\TrashPageResponse.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\pages\CreatePageResponse.json">
Expand Down
16 changes: 8 additions & 8 deletions Test/Notion.UnitTests/PagesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task RetrieveAsync()
page.Id.Should().Be(pageId);
page.Parent.Type.Should().Be(ParentType.DatabaseId);
((DatabaseParent)page.Parent).DatabaseId.Should().Be("48f8fee9-cd79-4180-bc2f-ec0398253067");
page.IsArchived.Should().BeFalse();
page.InTrash.Should().BeFalse();
}

[Fact]
Expand Down Expand Up @@ -72,7 +72,7 @@ public async Task CreateAsync()
page.Url.Should().NotBeNullOrEmpty();
page.Properties.Should().HaveCount(1);
page.Properties.First().Key.Should().Be("Name");
page.IsArchived.Should().BeFalse();
page.InTrash.Should().BeFalse();
page.Parent.Should().NotBeNull();
((DatabaseParent)page.Parent).DatabaseId.Should().Be("3c357473-a281-49a4-88c0-10d2b245a589");
}
Expand Down Expand Up @@ -172,7 +172,7 @@ public async Task UpdatePageAsync()
var page = await _client.UpdateAsync(pageId, pagesUpdateParameters);

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

Expand All @@ -187,14 +187,14 @@ public async Task UpdatePageAsync()
}

[Fact]
public async Task ArchivePageAsync()
public async Task TrashPageAsync()
{
var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c";
var propertyId = "{>U;";

var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId);

var jsonData = await File.ReadAllTextAsync("data/pages/ArchivePageResponse.json");
var jsonData = await File.ReadAllTextAsync("data/pages/TrashPageResponse.json");

Server.Given(CreatePatchRequestBuilder(path))
.RespondWith(
Expand All @@ -211,7 +211,7 @@ public async Task ArchivePageAsync()

var pagesUpdateParameters = new PagesUpdateParameters
{
Archived = true,
InTrash = true,
Properties = new Dictionary<string, PropertyValue>
{
{ "In stock", new CheckboxPropertyValue { Checkbox = true } }
Expand All @@ -221,8 +221,8 @@ public async Task ArchivePageAsync()
var page = await _client.UpdateAsync(pageId, pagesUpdateParameters);

page.Id.Should().Be(pageId);
page.IsArchived.Should().BeTrue();
page.Properties.Should().HaveCount(2);
page.InTrash.Should().BeTrue();
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
2 changes: 1 addition & 1 deletion Test/Notion.UnitTests/SearchClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async Task Search()
obj.Object.Should().Be(ObjectType.Page);

var page = (Page)obj;
page.IsArchived.Should().BeFalse();
page.InTrash.Should().BeFalse();
page.Properties.Should().HaveCount(1);
page.Parent.Should().BeAssignableTo<DatabaseParent>();
((DatabaseParent)page.Parent).DatabaseId.Should().Be("e6c6f8ff-c70e-4970-91ba-98f03e0d7fc6");
Expand Down
Loading

0 comments on commit da3d9da

Please sign in to comment.