Skip to content

Commit

Permalink
Improve readme and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangomz committed Jun 22, 2021
1 parent 0b8c1de commit 2d4067c
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 43 deletions.
50 changes: 47 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Notion API client for dart.

![CI](https://github.com/jonathangomz/notion_api/actions/workflows/main.yml/badge.svg)

See the [ROADMAP](ROADMAP.md) file to see what is coming next.

# Using
# Usage
**Important**: The methods return a `NotionResponse`. You can find how to use it in its [documentation][1].

You can see some examples [here](example/example.md).

## `NotionClient` class
You only have to create a new instance of the `NotionClient` class and all the API requests will be available as class methods.
```dart
Expand All @@ -27,6 +27,50 @@ NotionDatabasesClient databases = NotionDatabasesClient(token: 'YOUR_TOKEN');
databases.fetchAll();
```

## Some examples
_To see more examples [go here](example/example.md)._

### Append blocks children
```dart
// Create children instance:
Children children = Children().addAll([
Heading(text: Text('Test')),
Paragraph(texts: [
Text('Lorem ipsum (A)'),
Text('Lorem ipsum (B)',
annotations: TextAnnotations(
bold: true,
underline: true,
color: ColorsTypes.Orange,
))
])
]);
// Send the instance to Notion
notion.blocks.append(
to: 'YOUR_BLOCK_ID',
children: children,
);
```

### Create a page
```dart
// Create a page instance
Page page = Page(
parent: Parent.database(id: 'YOUR_DATABASE_ID'),
title: Text('NotionClient (v1): Page test'),
);
// Send the instance to Notion.
notion.pages.create(page);
```

# Next release
## v1.0.0:
> Release date: 25/Jun/2021
### Changes
* Fix any error

# Contributions
Please help, I don't even know if what I'm doing is right.

Expand Down
101 changes: 61 additions & 40 deletions example/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
- [Full instance](#full-instance)
- [Individual classes](#individual-classes)
- [Pages](#pages)
- [Creating pages](#creating-pages)
- [Retrieving pages](#retrieving-pages)
- [Create a page](#create-a-page)
- [Retrieve a page](#retrieve-a-page)
- [Databases](#databases)
- [Retrieving a database](#retrieving-a-database)
- [Retrieving all databases](#retrieving-all-databases)
- [Retrieve a database](#retrieve-a-database)
- [List databases](#list-databases)
- [Block children](#block-children)
- [Retrieving block children](#retrieving-block-children)
- [Retrieve block children](#retrieve-block-children)
- [Append block children](#append-block-children)
- [Example](#example)
- [Heading & Paragraph](#heading--paragraph)
Expand Down Expand Up @@ -41,7 +41,13 @@ databases.fetchAll();
```

# Pages
## Creating pages
## Create a page
You have to define the parent of the page. It can be:
- `database`
- `page`
- `workspace`

There is a constructor for each one (_see example below_) but the main constructor can be used as well but the `ParentType` will be required.
```dart
// With database parent
Page page = Page(
Expand All @@ -58,18 +64,18 @@ Page page = Page(
notion.pages.create(page);
```

## Retrieving pages
## Retrieve a page
```dart
notion.pages.fetch('YOUR_PAGE_ID');
```

# Databases
## Retrieving a database
## Retrieve a database
```dart
notion.databases.fetch('YOUR_DATABASE_ID');
```

## Retrieving all databases
## List databases
> **Warning**: [This endpoint is not recommended][1] by the Notion team.
_Parameters:_
Expand All @@ -80,7 +86,7 @@ notion.databases.fetchAll();
```

# Block children
## Retrieving block children
## Retrieve block children
```dart
notion.blocks.fetch('YOUR_BLOCK_ID');
```
Expand All @@ -99,25 +105,39 @@ _Parameters:_
```dart
// Create children instance:
// * Old way
Children oldWay = Children(
heading: Heading('Test'),
paragraph: Paragraph(
content: [
Text('Lorem ipsum (A)'),
Text(
'Lorem ipsum (B)',
// Children oldWay = Children(
// heading: Heading('Test'),
// paragraph: Paragraph(
// content: [
// Text('Lorem ipsum (A)'),
// Text(
// 'Lorem ipsum (B)',
// annotations: TextAnnotations(
// bold: true,
// underline: true,
// color: ColorsTypes.orange,
// ),
// ),
// ],
// ),
//);
//
// * New way using `addAll()`
Children childrenA = Children().addAll([
Heading(text: Text('Test')),
Paragraph(texts: [
Text('Lorem ipsum (A)'),
Text('Lorem ipsum (B)',
annotations: TextAnnotations(
bold: true,
underline: true,
color: ColorsTypes.orange,
),
),
],
),
);
color: ColorsTypes.Orange,
))
])
]);
// * New way
Children newWay =
// * New way using single `add()`
Children childrenB =
Children().add(Heading(text: Text('Test'))).add(Paragraph(texts: [
Text('Lorem ipsum (A)'),
Text('Lorem ipsum (B)',
Expand All @@ -131,7 +151,7 @@ Children newWay =
// Send the instance to Notion
notion.blocks.append(
to: 'YOUR_BLOCK_ID',
children: newWay,
children: childrenB, // or `childrenA`, both are the same.
);
```

Expand All @@ -141,20 +161,21 @@ notion.blocks.append(
#### To do
##### Code
```dart
Children children = Children(
toDo: [
ToDo(text: Text('This is a todo item A')),
ToDo(
texts: [
Text('This is a todo item'),
Text(
'B',
annotations: TextAnnotations(bold: true),
),
],
),
],
);
Children children =
Children(
toDo: [
ToDo(text: Text('This is a todo item A')),
ToDo(
texts: [
Text('This is a todo item'),
Text(
'B',
annotations: TextAnnotations(bold: true),
),
],
),
],
);
// Send the instance to Notion
notion.blocks.append(
Expand Down

0 comments on commit 2d4067c

Please sign in to comment.