2 releases
0.1.1 | Apr 16, 2023 |
---|---|
0.1.0 | Apr 14, 2023 |
#1 in #notion
22 downloads per month
30KB
679 lines
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)
Dependencies
~13–25MB
~427K SLoC