From 6cfa8be646027f1d62165733da157ce8de0b33fd Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 18 Jul 2021 12:53:52 +0200 Subject: [PATCH] Add client endpoint to get all pages Signed-off-by: trivernis --- src/api_core/client.rs | 6 ++++++ src/api_core/common.rs | 11 +++++++++++ src/api_core/managing_pages.rs | 19 +++++++++++++++++++ src/api_core/mod.rs | 1 + tests/client/mod.rs | 1 + tests/client/test_managing_pages.rs | 7 +++++++ 6 files changed, 45 insertions(+) create mode 100644 src/api_core/managing_pages.rs create mode 100644 tests/client/test_managing_pages.rs diff --git a/src/api_core/client.rs b/src/api_core/client.rs index b714320..32260bb 100644 --- a/src/api_core/client.rs +++ b/src/api_core/client.rs @@ -12,6 +12,7 @@ use crate::api_core::adding_urls::{ GetUrlFilesResponse, GetUrlInfo, GetUrlInfoResponse, }; use crate::api_core::common::{FileIdentifier, FileMetadataInfo, FileRecord}; +use crate::api_core::managing_pages::{GetPage, GetPagesResponse}; use crate::api_core::searching_and_fetching_files::{ FileMetadata, FileMetadataResponse, FileSearchLocation, GetFile, SearchFiles, SearchFilesResponse, @@ -307,4 +308,9 @@ impl Client { Ok(()) } + + /// Returns all pages of the client + pub async fn get_pages(&self) -> Result { + self.get_and_parse::(&()).await + } } diff --git a/src/api_core/common.rs b/src/api_core/common.rs index 6160ee6..4af9965 100644 --- a/src/api_core/common.rs +++ b/src/api_core/common.rs @@ -49,3 +49,14 @@ pub struct FileRecord { pub bytes: Vec, pub mime_type: String, } + +#[derive(Clone, Debug, Deserialize)] +pub struct PageInformation { + pub name: String, + pub page_key: String, + pub page_type: u32, + #[serde(alias = "focused")] + pub selected: bool, + #[serde(default = "Vec::new")] + pub pages: Vec, +} diff --git a/src/api_core/managing_pages.rs b/src/api_core/managing_pages.rs new file mode 100644 index 0000000..e553a60 --- /dev/null +++ b/src/api_core/managing_pages.rs @@ -0,0 +1,19 @@ +use crate::api_core::common::PageInformation; +use crate::api_core::Endpoint; + +#[derive(Clone, Debug, Deserialize)] +pub struct GetPagesResponse { + /// The top level notebook page + pub pages: PageInformation, +} + +pub struct GetPage; + +impl Endpoint for GetPage { + type Request = (); + type Response = GetPagesResponse; + + fn path() -> String { + String::from("manage_pages/get_pages") + } +} diff --git a/src/api_core/mod.rs b/src/api_core/mod.rs index 222f522..f9e58a2 100644 --- a/src/api_core/mod.rs +++ b/src/api_core/mod.rs @@ -7,6 +7,7 @@ pub mod adding_tags; pub mod adding_urls; pub mod client; pub mod common; +pub mod managing_pages; pub mod searching_and_fetching_files; pub(crate) trait Endpoint { diff --git a/tests/client/mod.rs b/tests/client/mod.rs index 3c81da6..8f2f88c 100644 --- a/tests/client/mod.rs +++ b/tests/client/mod.rs @@ -2,4 +2,5 @@ mod test_access_management; mod test_adding_files; mod test_adding_tags; mod test_adding_urls; +mod test_managing_pages; mod test_searching_and_fetching_files; diff --git a/tests/client/test_managing_pages.rs b/tests/client/test_managing_pages.rs new file mode 100644 index 0000000..9d12bdf --- /dev/null +++ b/tests/client/test_managing_pages.rs @@ -0,0 +1,7 @@ +use super::super::common; + +#[tokio::test] +async fn it_returns_all_pages() { + let client = common::get_client(); + client.get_pages().await.unwrap(); +}