aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/build.yml6
-rw-r--r--Cargo.toml2
-rw-r--r--README.md6
-rw-r--r--src/lib.rs16
-rw-r--r--src/models.rs2
5 files changed, 29 insertions, 3 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index ce57b95..a68d7f4 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -41,3 +41,9 @@ jobs:
with:
command: test
args: --all-features
+ - name: Docs
+ uses: actions-rs/cargo@v1
+ env:
+ NOTION_API_TOKEN: ${{ secrets.NOTION_API_TOKEN }}
+ with:
+ command: doc
diff --git a/Cargo.toml b/Cargo.toml
index f3f352b..1a037ba 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,6 +3,8 @@ name = "notion"
version = "0.0.1-beta.3"
authors = ["Jake Swenson <jake@jakeswenson.com>"]
edition = "2018"
+repository = "https://github.com/jakeswenson/notion"
+readme = "README.md"
description = "A Notion Api Client"
license = "MIT"
diff --git a/README.md b/README.md
index fb77a1e..c27cadc 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,6 @@
# notion
-Notion API library for rust
+[![Build](https://github.com/jakeswenson/notion/actions/workflows/build.yml/badge.svg)](https://github.com/jakeswenson/notion/actions/workflows/build.yml)
+[![Crates.io](https://img.shields.io/crates/v/notion?style=for-the-badge)](https://crates.io/crates/notion)
+
+Notion API client library for rust.
+
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<ById> {
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<Self, Error> {
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<ListResponse<Database>, 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<T: Into<SearchRequest>>(
&self,
query: T,
@@ -95,6 +107,7 @@ impl NotionApi {
.await?)
}
+ /// Get a database by [DatabaseId].
pub async fn get_database<T: AsIdentifier<DatabaseId>>(
&self,
database_id: T,
@@ -106,6 +119,7 @@ impl NotionApi {
.await?)
}
+ /// Query a database and return the matching pages.
pub async fn query_database<D, T>(
&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<PageId> for BlockId {
fn from(page_id: PageId) -> Self {
- BlockId(page_id.0.clone())
+ BlockId(page_id.0)
}
}