Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cn-kali-team committed Dec 15, 2023
1 parent da0971c commit 11051dc
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 9 deletions.
10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
[package]
name = "notion-rs" #改这个
[workspace.package]
#name = "notion-rs" #改这个
version = "0.1.0"
edition = "2021"
authors = ["Kali-Team <root@kali-team.cn>"]
include = ["LICENSE", "Cargo.toml", "src/**/*.rs"]
license-file = "LICENSE"
license = "GPL-3.0-only"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[workspace]
members = ["notion-sdk"]
resolver = "2"

#https://github.com/johnthagen/min-sized-rust
[profile.release]
Expand All @@ -29,4 +32,5 @@ codegen-units = 1
opt-level = 3


[dependencies]
[workspace.dependencies]
notion-sdk = { path = "notion-sdk", version = "0.1.0" }
8 changes: 7 additions & 1 deletion notion-sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
[package]
name = "notion-sdk"
version = "0.1.0"
edition = "2021"
description = "A rust implementation of the nvd-yew."
homepage = "https://github.com/emo-crab/notion-rs"
repository = "https://github.com/emo-crab/notion-rs"
authors = ["Kali-Team <root@kali-team.cn>"]
readme = "README.md"
license = "GPL-3.0-only"
version = "0.0.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
8 changes: 8 additions & 0 deletions notion-sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Notion SDK

[![github]](https://github.com/emo-crab/notion-rs)&ensp;[![crates-io]](https://crates.io/crates/notion-sdk)&ensp;[![docs-rs]](crate)
[github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
[crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust
[docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs

- UnOfficial Notion SDK mplemented by rust
13 changes: 13 additions & 0 deletions notion-sdk/src/block/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
//!
//! # Notion Block
//!
//! ## Examples
//! ```rust,no_run
//! use notion_sdk::block::TextAndChildren;
//! use notion_sdk::common::rich_text::TextColor;
//! let text = TextAndChildren{
//! rich_text: vec![],
//! children: None,
//! color: TextColor::Default
//! };
//! ```
mod api;
mod code;
pub mod id;
Expand Down
4 changes: 3 additions & 1 deletion notion-sdk/src/comment/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@

//!
//! # Notion Comment
//!
3 changes: 3 additions & 0 deletions notion-sdk/src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//!
//! # Notion Common
//!
pub mod aka;
pub mod file;
pub mod parent;
Expand Down
2 changes: 1 addition & 1 deletion notion-sdk/src/common/rich_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub struct Text {
pub link: Option<Link>,
}

/// See https://developers.notion.com/reference/rich-text#mention-objects
/// See <https://developers.notion.com/reference/rich-text#mention-objects>
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
Expand Down
14 changes: 14 additions & 0 deletions notion-sdk/src/database/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
//!
//! # Notion DataBase
//!
//! ## Examples
//! ```rust,no_run
//! use notion_sdk::common::parent::Parent;
//! use notion_sdk::database::CreateDatabase;
//! use notion_sdk::database::properties::Properties;
//! let database = CreateDatabase{
//! parent: Parent::Workspace,
//! title: vec![],
//! properties: Properties { properties: Default::default()},
//! };
//! ```
pub mod properties;

use crate::common::file::FileOrEmojiObject;
Expand Down
5 changes: 4 additions & 1 deletion notion-sdk/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//!
//! # Notion Error
//!
use crate::pagination::Object;
use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Display, Formatter};
use std::num::NonZeroU16;

/// An wrapper Error type for all errors produced by the [`NotionApi`](NotionApi) client.
/// An wrapper Error type for all errors produced by the NotionApi client.
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Invalid UUID: {}", source)]
Expand Down
27 changes: 25 additions & 2 deletions notion-sdk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
//! [![github]](https://github.com/emo-crab/notion-rs)&ensp;[![crates-io]](https://crates.io/crates/notion-sdk)&ensp;[![docs-rs]](crate)
//!
//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
//! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust
//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs
//!
//!
//! UnOfficial Notion SDK mplemented by rust
//!
//!
//! ## Examples
//! ```rust,no_run
//! use notion_sdk::NotionApi;
//! async fn main(){
//! let notion = NotionApi::new("token")?;
//! let me = notion.users_me().await;
//! println!("{:#?}", me);
//! }
//!
//! ```
pub mod block;
pub mod comment;
pub mod common;
Expand All @@ -14,14 +34,17 @@ use reqwest::{ClientBuilder, RequestBuilder};

const NOTION_API_VERSION: &str = "2022-02-22";

/// Notion Api Client
#[derive(Debug, Clone)]
pub struct NotionApi {
base_path: String,
client: reqwest::Client,
}

/// new a notion api client with api token
impl NotionApi {
pub fn new(api_token: String) -> Result<Self, Error> {
pub fn new<T>(api_token: T) -> Result<Self, Error> where
T: Into<String>, {
let mut headers = reqwest::header::HeaderMap::new();
headers.insert(
"Notion-Version",
Expand All @@ -43,7 +66,7 @@ impl NotionApi {
}

impl NotionApi {
pub async fn request(&self, request: RequestBuilder) -> Result<Object, Error> {
async fn request(&self, request: RequestBuilder) -> Result<Object, Error> {
let request = request.build()?;
let json = self
.client
Expand Down
1 change: 1 addition & 0 deletions notion-sdk/src/pages/aka.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::database::properties::PropertyValue;
use crate::pages::Page;

impl Page {
/// get page's title
pub fn get_title(&self) -> String {
if let Some(PropertyValue::Title { title, .. }) = self.properties.properties.get("Title") {
let tit: Vec<String> = title.iter().map(|r| r.plain_text().to_string()).collect();
Expand Down
15 changes: 15 additions & 0 deletions notion-sdk/src/pages/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
//!
//! # Notion Page
//!
//! ## Examples
//! ```rust,no_run
//! use notion_sdk::common::parent::Parent;
//! use notion_sdk::database::properties::Properties;
//! use notion_sdk::pages::CreatePage;
//! let page = CreatePage{
//! icon: None,
//! parent: Parent::Workspace,
//! properties: Properties { properties: Default::default()},
//! children: vec![],
//! };
//! ```
mod aka;
mod api;
mod builder;
Expand Down
3 changes: 3 additions & 0 deletions notion-sdk/src/pagination.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//!
//! # Notion Pagination
//!
use crate::block::Block;
use crate::database::properties::PropertyValue;
use crate::database::Database;
Expand Down
3 changes: 3 additions & 0 deletions notion-sdk/src/search/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//!
//! # Notion Search
//!
mod api;

use crate::pages::id::PageId;
Expand Down
1 change: 1 addition & 0 deletions notion-sdk/src/user/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{Error, NotionApi, Object};
const ROUTER: &str = "users";

impl NotionApi {
/// list users
pub async fn users_list(&self) -> Result<Object, Error> {
let u = format!("{}/{}", self.base_path, ROUTER);
self.request(self.client.get(u)).await
Expand Down
3 changes: 3 additions & 0 deletions notion-sdk/src/user/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//!
//! # Notion User
//!
mod api;
pub mod id;
mod tests;
Expand Down

0 comments on commit 11051dc

Please sign in to comment.