Skip to content

Commit

Permalink
Merge pull request #156 from notion-dotnet/2.0.0
Browse files Browse the repository at this point in the history
Merge 2.0.0 release 🎉
  • Loading branch information
KoditkarVedant authored Oct 2, 2021
2 parents 079dc2f + 0b43508 commit e51fce1
Show file tree
Hide file tree
Showing 135 changed files with 1,161 additions and 109 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ Provides the following packages:
dotnet add package Notion.Net
```

> Note: From Nuget 2.0.0 notion client sdk default sets the Notion-Version header to 2021-08-16.


## Usage

> Before getting started, you need to [create an integration](https://www.notion.com/my-integrations) and find the token. You can learn more about authorization [here](https://developers.notion.com/docs/authorization).
Expand Down Expand Up @@ -93,12 +97,13 @@ var complexFiler = new CompoundFilter(
```

## Supported Endpoints

- [x] Databases
- [x] Retrieve a database
- [x] Query a database
- [x] List databases
- [x] Create a database
- [x] Update database
- [x] Retrieve a database
- [x] List databases (Deprecated: use Search API instead)
- [x] Pages
- [x] Retrieve a page
- [x] Create a page
Expand All @@ -108,6 +113,7 @@ var complexFiler = new CompoundFilter(
- [x] Update a block
- [x] Retrieve block children
- [x] Append block children
- [x] Delete a block
- [x] Users
- [x] Retrieve a User
- [x] List all users
Expand All @@ -116,4 +122,3 @@ var complexFiler = new CompoundFilter(
## Contribution Guideline

Hello! Thank you for choosing to help contribute to this open source library. There are many ways you can contribute and help is always welcome. You can read the detailed [Contribution Guideline](https://github.com/notion-dotnet/notion-sdk-net/blob/main/CONTRIBUTING.md) defined here - we will continue to improve it.

8 changes: 8 additions & 0 deletions Src/Notion.Client/Api/ApiEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public static class BlocksApiUrls
{
public static string Retrieve(string blockId) => $"/v1/blocks/{blockId}";
public static string Update(string blockId) => $"/v1/blocks/{blockId}";

/// <summary>
/// Get the <see cref="uri string"/> for deleting a block.
/// </summary>
/// <param name="blockId">Identifier for a Notion block</param>
/// <returns>Returns a <see cref="uri string"/> for deleting a block.</returns>
public static string Delete(string blockId) => $"/v1/blocks/{blockId}";

public static string RetrieveChildren(string blockId) => $"/v1/blocks/{blockId}/children";
public static string AppendChildren(string blockId) => $"/v1/blocks/{blockId}/children";
}
Expand Down
16 changes: 14 additions & 2 deletions Src/Notion.Client/Api/Blocks/BlocksClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task<PaginatedList<Block>> RetrieveChildrenAsync(string blockId, Bl
return await _client.GetAsync<PaginatedList<Block>>(url, queryParams);
}

public async Task<Block> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null)
public async Task<PaginatedList<Block>> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null)
{
if (string.IsNullOrWhiteSpace(blockId))
{
Expand All @@ -45,7 +45,7 @@ public async Task<Block> AppendChildrenAsync(string blockId, BlocksAppendChildre

var body = (IBlocksAppendChildrenBodyParameters)parameters;

return await _client.PatchAsync<Block>(url, body);
return await _client.PatchAsync<PaginatedList<Block>>(url, body);
}

public async Task<Block> RetrieveAsync(string blockId)
Expand All @@ -71,5 +71,17 @@ public async Task<Block> UpdateAsync(string blockId, IUpdateBlock updateBlock)

return await _client.PatchAsync<Block>(url, updateBlock);
}

public async Task DeleteAsync(string blockId)
{
if (string.IsNullOrWhiteSpace(blockId))
{
throw new ArgumentNullException(nameof(blockId));
}

var url = BlocksApiUrls.Delete(blockId);

await _client.DeleteAsync(url);
}
}
}
15 changes: 14 additions & 1 deletion Src/Notion.Client/Api/Blocks/IBlocksClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ public interface IBlocksClient
Task<Block> UpdateAsync(string blockId, IUpdateBlock updateBlock);

Task<PaginatedList<Block>> RetrieveChildrenAsync(string blockId, BlocksRetrieveChildrenParameters parameters = null);
Task<Block> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null);

/// <summary>
/// Creates and appends new children blocks to the parent block_id specified.
/// </summary>
/// <param name="blockId">Identifier for a block</param>
/// <param name="parameters"></param>
/// <returns>A paginated list of newly created first level children block objects.</returns>
Task<PaginatedList<Block>> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null);

/// <summary>
/// Sets a Block object, including page blocks, to archived: true using the ID specified.
/// </summary>
/// <param name="blockId">Identifier for a Notion block</param>
Task DeleteAsync(string blockId);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
namespace Notion.Client
using Newtonsoft.Json;

namespace Notion.Client
{
public class ParagraphUpdateBlock : IUpdateBlock
{
[JsonProperty("paragraph")]
public TextContentUpdate Paragraph { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class TextContentUpdate
{
[JsonProperty("text")]
public IEnumerable<RichTextBaseInput> Text { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class ToDoUpdateBlock : IUpdateBlock

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

[JsonProperty("checked")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
namespace Notion.Client
using Newtonsoft.Json;

namespace Notion.Client
{
public class ToggleUpdateBlock : IUpdateBlock
{
[JsonProperty("toggle")]
public TextContentUpdate Toggle { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
// TODO: need an input version of Block
public interface IBlocksAppendChildrenBodyParameters
{
[JsonProperty("children")]
IEnumerable<Block> Children { get; set; }
}
}
4 changes: 3 additions & 1 deletion Src/Notion.Client/Api/Databases/DatabasesClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using static Notion.Client.ApiEndpoints;

Expand All @@ -18,6 +19,7 @@ public async Task<Database> RetrieveAsync(string databaseId)
return await _client.GetAsync<Database>(DatabasesApiUrls.Retrieve(databaseId));
}

[Obsolete("This endpoint is no longer recommended, use Search instead. This endpoint will only return explicitly shared pages, while search will also return child pages within explicitly shared pages. This endpoint's results cannot be filtered, while search can be used to match on page title.", false)]
public async Task<PaginatedList<Database>> ListAsync(DatabasesListParameters databasesListParameters = null)
{
var databasesListQueryParmaters = (IDatabasesListQueryParmaters)databasesListParameters;
Expand Down
10 changes: 9 additions & 1 deletion Src/Notion.Client/Api/Databases/IDatabasesClient.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;

namespace Notion.Client
{
public interface IDatabasesClient
{
Task<Database> RetrieveAsync(string databaseId);
Task<PaginatedList<Page>> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters);

/// <summary>
/// List all Databases shared with the authenticated integration.
/// </summary>
/// <param name="databasesListParameters">database list request parameters.</param>
/// <returns>PaginatedList of databases.</returns>
[Obsolete("This endpoint is no longer recommended, use Search instead. This endpoint will only return explicitly shared pages, while search will also return child pages within explicitly shared pages. This endpoint's results cannot be filtered, while search can be used to match on page title.", false)]
Task<PaginatedList<Database>> ListAsync(DatabasesListParameters databasesListParameters = null);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class DatabasesCreateParameters : IDatabasesCreateBodyParameters, IDatabasesCreateQueryParameters
{
[JsonProperty("parent")]
public ParentPageInput Parent { get; set; }

[JsonProperty("properties")]
public Dictionary<string, IPropertySchema> Properties { get; set; }

[JsonProperty("title")]
public List<RichTextBaseInput> Title { get; set; }

[JsonProperty("icon")]
public IPageIcon Icon { get; set; }

[JsonProperty("cover")]
public FileObject Cover { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public interface IDatabasesCreateBodyParameters
{
[JsonProperty("parent")]
ParentPageInput Parent { get; set; }

[JsonProperty("properties")]
Dictionary<string, IPropertySchema> Properties { get; set; }

[JsonProperty("title")]
List<RichTextBaseInput> Title { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
namespace Notion.Client
using Newtonsoft.Json;

namespace Notion.Client
{
public class MentionInput
{
[JsonProperty("type")]
public string Type { get; set; }

[JsonProperty("user")]
public Person User { get; set; }

[JsonProperty("page")]
public ObjectId Page { get; set; }

[JsonProperty("database")]
public ObjectId Database { get; set; }

[JsonProperty("date")]
public DatePropertyValue Date { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class CheckboxPropertySchema : IPropertySchema
{
[JsonProperty("checkbox")]
public Dictionary<string, object> Checkbox { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class DatePropertySchema : IPropertySchema
{
[JsonProperty("date")]
public Dictionary<string, object> Date { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class EmailPropertySchema : IPropertySchema
{
[JsonProperty("email")]
public Dictionary<string, object> Email { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class FilePropertySchema : IPropertySchema
{
[JsonProperty("files")]
public Dictionary<string, object> Files { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
namespace Notion.Client
using Newtonsoft.Json;

namespace Notion.Client
{
public class FormulaPropertySchema : IPropertySchema
{
[JsonProperty("formula")]
public Formula Formula { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
namespace Notion.Client
using Newtonsoft.Json;

namespace Notion.Client
{
public class NumberPropertySchema : IPropertySchema
{
[JsonProperty("number")]
public Number Number { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class PeoplePropertySchema : IPropertySchema
{
[JsonProperty("people")]
public Dictionary<string, object> People { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using Newtonsoft.Json;

namespace Notion.Client
{
public class RelationPropertySchema : IPropertySchema
{
[JsonProperty("relation")]
public RelationInfo Relation { get; set; }

public class RelationInfo
{
[JsonProperty("database_id")]
public Guid DatabaseId { get; set; }

[JsonProperty("synced_property_id")]
public string SynchedPropertyId { get; set; }

[JsonProperty("synced_property_name")]
public string SynchedPropertyName { get; set; }
}
}
}
Loading

0 comments on commit e51fce1

Please sign in to comment.