Crates.io | simple-notion |
lib.rs | simple-notion |
version | 0.1.1 |
source | src |
created_at | 2023-04-14 13:57:58.619695 |
updated_at | 2023-04-16 13:27:01.654504 |
description | Easy to use library to read-only Notion DataBase using the NotionAPI |
homepage | |
repository | https://github.com/eVisualUser/simple-notion |
max_upload_size | |
id | 839187 |
size | 29,582 |
Easy to use library to read Notion DataBase using the NotionAPI.
Please note that this library is not officially supported by the Notion team.
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");
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();
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);
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());
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);
// 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)