Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Correct filter models #19

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
KoditkarVedant merged 13 commits into notion-dotnet:main from asevos:main
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
13 commits
Select commit Hold shift + click to select a range
71d0540
Merge pull request #17 from notion-dotnet/add-support-for-block-objec...
KoditkarVedant May 30, 2021
6e6b6ef
Merge branch 'develop' of github.com:asevos/notion-sdk-net into develop
Jun 1, 2021
27e1749
🚚 Moved filters to separate files
asevos Jun 1, 2021
cdce41b
🚚 Move filters to separate files
asevos Jun 1, 2021
e5db124
Merge branch 'develop' of github.com:asevos/notion-sdk-net into develop
asevos Jun 1, 2021
6894aa3
🐛 Fix filters formats and property nullability
asevos Jun 1, 2021
2a15e3a
♻️ Change RestClient.defaultSerializerSettings access to protected
asevos Jun 1, 2021
09cc0ff
✅ Adds filter clasees serialization tests
asevos Jun 1, 2021
cb7ab54
Merge branch 'main' of github.com:notion-dotnet/notion-sdk-net into main
asevos Jun 2, 2021
9c9028e
♻️ Makes filter conditions a nested filters class
asevos Jun 2, 2021
f23b595
✨ Adds filter constructors
asevos Jun 3, 2021
9980587
🎨 Updates code formatting to .editorconfig settings
asevos Jun 3, 2021
128b22c
📝 Db querying docs added to readme
asevos Jun 3, 2021
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
37 changes: 34 additions & 3 deletions README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,54 @@
## 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.

![image](https://user-images.githubusercontent.com/18693839/119268863-79925b00-bc12-11eb-92cb-d5a9a8c57fdc.png)

Make A request to any Endpoint. For example you can call below to fetch the paginated list of users.

![image](https://user-images.githubusercontent.com/18693839/119268924-ae9ead80-bc12-11eb-9d1a-925267896d9e.png)

### 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<string, object>());

var orGroup = new List<Filter> { assigneeFilter, selectFilter };
var complexFiler = new CompoundFilter(
and: new List<Filter> { dateFilter, new CompoundFilter(or: orGroup) }
);
```

## Contribution Guideline

Expand Down
208 changes: 0 additions & 208 deletions Src/Notion.Client/Models/Filter.cs
View file Open in desktop

This file was deleted.

34 changes: 34 additions & 0 deletions Src/Notion.Client/Models/Filters/Checkbox.cs
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using Newtonsoft.Json;

namespace Notion.Client
{
public class CheckboxFilter : SinglePropertyFilter
{
public Condition Checkbox { get; set; }

public CheckboxFilter(
string propertyName,
bool? equal = null,
bool? doesNotEqual = null)
{
Property = propertyName;
Checkbox = new Condition(equal: equal, doesNotEqual: doesNotEqual);
}

public class Condition
{
[JsonProperty("equals")]
public bool? Equal { get; set; }

[JsonProperty("does_not_equal")]
public bool? DoesNotEqual { get; set; }

public Condition(Nullable<bool> equal = null, Nullable<bool> doesNotEqual = null)
{
Equal = equal;
DoesNotEqual = doesNotEqual;
}
}
}
}
Loading

AltStyle によって変換されたページ (->オリジナル) /