From 9c240dcf9381d98126758491141c2f9505b4f172 Mon Sep 17 00:00:00 2001 From: Jake Swenson Date: Mon, 17 May 2021 08:46:30 -0700 Subject: ci: adding doc build step (#10) --- src/lib.rs | 16 +++++++++++++++- src/models.rs | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 82e395f..5605333 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,7 @@ pub mod models; const NOTION_API_VERSION: &str = "2021-05-13"; +/// An wrapper Error type for all errors produced by the [`NotionApi`](NotionApi) client. #[derive(Debug, Snafu)] pub enum Error { #[snafu(display("Invalid Notion API Token: {}", source))] @@ -27,15 +28,21 @@ pub enum Error { JsonParseError { source: serde_json::Error }, } +/// Meant to be a helpful trait allowing anything that can be +/// identified by the type specified in `ById`. pub trait AsIdentifier { fn id(&self) -> ById; } +/// An API client for Notion. +/// Create a client by using [new(api_token: String)](Self::new()). pub struct NotionApi { client: Client, } impl NotionApi { + /// Creates an instance of NotionApi. + /// May fail if the provided api_token is an improper value. pub fn new(api_token: String) -> Result { let mut headers = HeaderMap::new(); headers.insert( @@ -76,13 +83,18 @@ impl NotionApi { Ok(result) } - /// This method is apparently deprecated/"not recommended" + /// List all the databases shared with the supplied integration token. + /// > This method is apparently deprecated/"not recommended" and + /// > [search()](Self::search()) should be used instead. pub async fn list_databases(&self) -> Result, Error> { let builder = self.client.get("https://api.notion.com/v1/databases"); Ok(NotionApi::make_json_request(builder).await?) } + /// Search all pages in notion. + /// Query: can either be a [SearchRequest] or a + /// [NotionSearch](models::search::NotionSearch) query. pub async fn search>( &self, query: T, @@ -95,6 +107,7 @@ impl NotionApi { .await?) } + /// Get a database by [DatabaseId]. pub async fn get_database>( &self, database_id: T, @@ -106,6 +119,7 @@ impl NotionApi { .await?) } + /// Query a database and return the matching pages. pub async fn query_database( &self, database: D, diff --git a/src/models.rs b/src/models.rs index 734ece5..82ef7c9 100644 --- a/src/models.rs +++ b/src/models.rs @@ -282,7 +282,7 @@ impl BlockId { impl From for BlockId { fn from(page_id: PageId) -> Self { - BlockId(page_id.0.clone()) + BlockId(page_id.0) } } -- cgit v1.2.3