From c90b8253bfd671c3e6ff841d325ac9bebb1463bd Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Wed, 18 Aug 2021 21:19:21 +0530 Subject: [PATCH] Add separate readme file for nuget package :package: --- Src/Notion.Client/Notion.Client.csproj | 2 +- docs/README.md | 85 ++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 docs/README.md diff --git a/Src/Notion.Client/Notion.Client.csproj b/Src/Notion.Client/Notion.Client.csproj index 0146722c..a0aece6d 100644 --- a/Src/Notion.Client/Notion.Client.csproj +++ b/Src/Notion.Client/Notion.Client.csproj @@ -33,7 +33,7 @@ True - + True diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..f04a2bf0 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,85 @@ +# Notion SDK for .Net + +A simple and easy to use client for the [Notion API](https://developers.notion.com) + +## Installation + +.Net CLI + +``` +dotnet add package Notion.Net +``` + +## 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). + +Import and initialize the client using the integration token created above. + +```csharp +var client = new NotionClient(new ClientOptions +{ + AuthToken = "" +}); +``` + +Make A request to any Endpoint. For example you can call below to fetch the paginated list of users. + +```csharp +var usersList = await client.Users.ListAsync(); +``` + +### Querying a database + +After you initialized your client and got an id of a database, you can query it for any contained pages. You can add filters and sorts to your request. Here is a simple example: + +```C# +// Date filter for page property called "When" +var dateFilter = new DateFilter("When", onOrAfter: DateTime.Now); + +var queryParams = new DatabasesQueryParameters { Filter = dateFilter }; +var pages = await client.Databases.QueryAsync(databaseId, queryParams); +``` + +Filters constructors contain all possible filter conditions, but you need to choose only condition per filter, all other should be `null`. So, for example this code would not filter by 2 conditions as one might expect: + +```C# +var filter = new TextFilter("Name", startsWith: "Mr", contains: "John"); // WRONG FILTER USAGE + +``` + +To use complex filters, use class `CompoundFilter`. It allows adding many filters and even nesting compound filters into each other (it works as filter group in Notion interface). Here is an example of filter that would return pages that were due in past month AND either had a certain assignee OR had high urgency: + +```C# +var selectFilter = new SelectFilter("Urgency", equal: "High"); +var assigneeFilter = new PeopleFilter("Assignee", contains: "some-uuid"); +var dateFilter = new DateFilter("Due", pastMonth: new Dictionary()); + +var orGroup = new List { assigneeFilter, selectFilter }; +var complexFiler = new CompoundFilter( + and: new List { dateFilter, new CompoundFilter(or: orGroup) } +); +``` + +## Supported Endpoints + +- [ ] Databases + - [x] Retrieve a database + - [x] Query a database + - [x] List databases + - [ ] Create a Database +- [x] Pages + - [x] Retrieve a page + - [x] Create a page + - [x] Update page +- [x] Blocks + - [x] Retrieve Block Children + - [x] Append Block Children +- [x] Users + - [x] Retrieve a User + - [x] List all users +- [x] Search + +## 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.