Add endpoint to get information about a single page

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/2/head
trivernis 3 years ago
parent 6cfa8be646
commit 9854927938
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -12,7 +12,9 @@ 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::managing_pages::{
GetPageInfo, GetPageInfoResponse, GetPages, GetPagesResponse,
};
use crate::api_core::searching_and_fetching_files::{
FileMetadata, FileMetadataResponse, FileSearchLocation, GetFile, SearchFiles,
SearchFilesResponse,
@ -311,6 +313,12 @@ impl Client {
/// Returns all pages of the client
pub async fn get_pages(&self) -> Result<GetPagesResponse> {
self.get_and_parse::<GetPage, ()>(&()).await
self.get_and_parse::<GetPages, ()>(&()).await
}
/// Returns information about a single page
pub async fn get_page_info<S: AsRef<str>>(&self, page_key: S) -> Result<GetPageInfoResponse> {
self.get_and_parse::<GetPageInfo, [(&str, &str)]>(&[("page_key", page_key.as_ref())])
.await
}
}

@ -56,7 +56,7 @@ pub struct PageInformation {
pub page_key: String,
pub page_type: u32,
#[serde(alias = "focused")]
pub selected: bool,
pub selected: Option<bool>,
#[serde(default = "Vec::new")]
pub pages: Vec<PageInformation>,
}

@ -7,9 +7,9 @@ pub struct GetPagesResponse {
pub pages: PageInformation,
}
pub struct GetPage;
pub struct GetPages;
impl Endpoint for GetPage {
impl Endpoint for GetPages {
type Request = ();
type Response = GetPagesResponse;
@ -17,3 +17,19 @@ impl Endpoint for GetPage {
String::from("manage_pages/get_pages")
}
}
#[derive(Clone, Debug, Deserialize)]
pub struct GetPageInfoResponse {
pub page_info: PageInformation,
}
pub struct GetPageInfo;
impl Endpoint for GetPageInfo {
type Request = ();
type Response = GetPageInfoResponse;
fn path() -> String {
String::from("manage_pages/get_page_info")
}
}

@ -5,3 +5,12 @@ async fn it_returns_all_pages() {
let client = common::get_client();
client.get_pages().await.unwrap();
}
#[tokio::test]
async fn it_returns_page_info() {
let client = common::get_client();
let result = client
.get_page_info("0c33d6599c22d5ec12a57b79d8c5a528ebdab7a8c2b462e6d76e2d0512e917fd")
.await;
assert!(result.is_err()); // page does not exist
}

Loading…
Cancel
Save