aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorGravatar Jake Swenson <jake@jakeswenson.com> 2021-05-14 07:20:01 -0700
committerGravatar Jake Swenson <jake@jakeswenson.com> 2021-05-14 07:20:01 -0700
commitb22ae2cf8a9e2b6af1a54f79ecdb31ad4d2c31c5 (patch)
treee6f9e1dcfcf6aed2a09517ce08d276b6ce9e2b79 /src/lib.rs
parentf7ef8d6d7f009990ba0c6be61cca507f097673b6 (diff)
downloadnotion-b22ae2cf8a9e2b6af1a54f79ecdb31ad4d2c31c5.tar.gz
notion-b22ae2cf8a9e2b6af1a54f79ecdb31ad4d2c31c5.tar.zst
notion-b22ae2cf8a9e2b6af1a54f79ecdb31ad4d2c31c5.zip
clean code
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs40
1 files changed, 27 insertions, 13 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 7a65f31..53e639f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,37 +1,45 @@
+use crate::models::search::SearchRequest;
use crate::models::{Database, ListResponse};
use std::collections::HashMap;
-use crate::models::search::SearchRequest;
mod models;
struct NotionApi {
- token: String
+ token: String,
}
impl NotionApi {
/// This method is apparently deprecated
- pub async fn list_databases(&self) -> Result<ListResponse<Database>, Box<dyn std::error::Error>> {
+ pub async fn list_databases(
+ &self,
+ ) -> Result<ListResponse<Database>, Box<dyn std::error::Error>> {
let client = reqwest::ClientBuilder::new().build()?;
- let json = client.get("https://api.notion.com/v1/databases")
+ let json = client
+ .get("https://api.notion.com/v1/databases")
.bearer_auth(self.token.clone())
.send()
.await?
- .text().await?;
+ .text()
+ .await?;
dbg!(&json);
let result = serde_json::from_str(&json)?;
Ok(result)
}
-
- pub async fn search<T: Into<SearchRequest>>(&self, query: T) -> Result<ListResponse<Database>, Box<dyn std::error::Error>> {
+ pub async fn search<T: Into<SearchRequest>>(
+ &self,
+ query: T,
+ ) -> Result<ListResponse<Database>, Box<dyn std::error::Error>> {
let client = reqwest::ClientBuilder::new().build()?;
- let json = client.post("https://api.notion.com/v1/search")
+ let json = client
+ .post("https://api.notion.com/v1/search")
.bearer_auth(self.token.clone())
.json(&query.into())
.send()
.await?
- .text().await?;
+ .text()
+ .await?;
dbg!(serde_json::from_str::<serde_json::Value>(&json)?);
let result = serde_json::from_str(&json)?;
@@ -42,14 +50,14 @@ impl NotionApi {
#[cfg(test)]
mod tests {
+ use crate::models::search::{FilterProperty, FilterValue, NotionSearch};
use crate::NotionApi;
- use crate::models::search::{NotionSearch, FilterValue, FilterProperty};
const TEST_TOKEN: &'static str = include_str!(".api_token");
#[tokio::test]
async fn list_databases() -> Result<(), Box<dyn std::error::Error>> {
let api = NotionApi {
- token: TEST_TOKEN.to_string()
+ token: TEST_TOKEN.to_string(),
};
dbg!(api.list_databases().await?);
@@ -60,10 +68,16 @@ mod tests {
#[tokio::test]
async fn search() -> Result<(), Box<dyn std::error::Error>> {
let api = NotionApi {
- token: TEST_TOKEN.to_string()
+ token: TEST_TOKEN.to_string(),
};
- dbg!(api.search(NotionSearch::Filter {value: FilterValue::Database, property: FilterProperty::Object}).await?);
+ dbg!(
+ api.search(NotionSearch::Filter {
+ value: FilterValue::Database,
+ property: FilterProperty::Object
+ })
+ .await?
+ );
Ok(())
}