Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/list databases #1

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use crate::models::{Database, ListResponse, Object, Page};
use ids::{AsIdentifier, PageId};
use models::block::Block;
use models::search::NotionSearch;
use models::PageCreateRequest;
use reqwest::header::{HeaderMap, HeaderValue};
use reqwest::{header, Client, ClientBuilder, RequestBuilder};
Expand All @@ -16,7 +17,7 @@

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

/// An wrapper Error type for all errors produced by the [`NotionApi`](NotionApi) client.

Check warning on line 20 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build

redundant explicit link target
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Invalid Notion API Token: {}", source)]
Expand Down Expand Up @@ -112,20 +113,21 @@
}

/// 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.
/// Because of the deprecation of the original endpoint this just calls
/// [search()](Self::search()) with a filter on databases
///
#[deprecated(
note = "This method is deprecated. Please use `search()` with a filter on databases instead."
)]
pub async fn list_databases(&self) -> Result<ListResponse<Database>, Error> {
let builder = self.client.get("https://api.notion.com/v1/databases");

match self.make_json_request(builder).await? {
Object::List { list } => Ok(list.expect_databases()?),
response => Err(Error::UnexpectedResponse { response }),
}
self.search(NotionSearch::filter_by_databases())
.await
.map(|response| response.only_databases())
}

/// Search all pages in notion.
/// `query` can either be a [SearchRequest] or a slightly more convenient
/// [NotionSearch](models::search::NotionSearch) query.

Check warning on line 130 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build

redundant explicit link target
pub async fn search<T: Into<SearchRequest>>(
&self,
query: T,
Expand Down
Loading