simple-notion

Crates.iosimple-notion
lib.rssimple-notion
version0.1.1
sourcesrc
created_at2023-04-14 13:57:58.619695
updated_at2023-04-16 13:27:01.654504
descriptionEasy to use library to read-only Notion DataBase using the NotionAPI
homepage
repositoryhttps://github.com/eVisualUser/simple-notion
max_upload_size
id839187
size29,582
Sylvain (eVisualUser)

documentation

README

Simple Notion

Easy to use library to read Notion DataBase using the NotionAPI.

Disclaimer

Please note that this library is not officially supported by the Notion team.

Features

  • Read Data-Base

Getting Started

API Client

To start you need to get access to the API using the NotionClient.

let mut client = crate::client::NotionClient::default();

// Added the full URL of the database page:
client.set_url("https://www.notion.so/user-name/data-base-id?v=other");

// And you need to pass your integration token
client.set_token("integration-token");

Get the DataBase

Now you have the access, and need to download the data-base.

// Get the Raw Json data-base
let data_base = client.get_table_sync().unwrap();

Parse the data-base

You will convert each element to an enum named DataType. To do it you need the NotionResponseParser

// Take the data_base as input
let parser = crate::parser::NotionResponseParser::new(data_base);

Let's simplify

Now you have have the data-base and the parser. So you can create a NotionDataBase.

let data_table = crate::notion_data_base::NotionDataBase::new(parser.parse_table());

Access an element

Great! You have done the setup, let's use it.

// Getting the element.
let element = parser.parse_element(data_table.get(&parser, "MyLineTitle", "MyColumnName").unwrap().1);

// Priting the result
println!("My Element: {:?}", element);

Some other useful functions

// Get the Vec<String> of all lines titles
data_table.get_line_list(&parser);

// Get the Vec<String> of all columns names
data_table.get_column_list(&parser);

// Parse the full data-base to a Vec<Vec<DataType>>
data_table.get_all(&parser)
Commit count: 13

cargo fmt