1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use crate::{api_client::ApiClient, error::ResultApi, model::ShowcaseResponse};
impl ApiClient {
/// Get blog showcase
///
/// # Arguments
/// * `blog_name` - Blog name
/// * `limit` - Limit
/// * `only_visible` - Only visible
/// * `offset` - Offset
///
/// # Returns
/// * On success, returns a `ShowcaseResponse` containing the `data` field with `showcase_items`.
///
/// # Errors
/// * `ApiError::Unauthorized` if the HTTP status is 401 Unauthorized.
/// * `ApiError::HttpStatus` for other non-success HTTP statuses, with status and endpoint info.
/// * `ApiError::HttpRequest` if the HTTP request fails.
/// * `ApiError::JsonParseDetailed` if the response body cannot be parsed into a `ShowcaseResponse`.
pub async fn get_showcase(
&self,
blog_name: &str,
limit: Option<u32>,
only_visible: Option<bool>,
offset: Option<u32>,
) -> ResultApi<ShowcaseResponse> {
let mut path = format!("blog/{blog_name}/showcase/");
let mut params = Vec::new();
if let Some(o) = offset {
params.push(format!("offset={o}"));
}
if let Some(l) = limit {
params.push(format!("limit={l}"));
}
if let Some(ov) = only_visible {
params.push(format!("only_visible={ov}"));
}
if !params.is_empty() {
path.push('?');
path.push_str(¶ms.join("&"));
}
let response = self.get_request(&path).await?;
let response = self.handle_response(&path, response).await?;
self.parse_json(response).await
}
/// Change blog showcase status
///
/// # Arguments
/// * `blog_name` - Blog name
/// * `status` - Status (true to enable, false to disable)
///
/// # Returns
/// * On success, returns `()`.
///
/// # Errors
/// * `ApiError::Unauthorized` if the HTTP status is 401 Unauthorized.
/// * `ApiError::HttpStatus` for other non-success HTTP statuses, with status and endpoint info.
/// * `ApiError::HttpRequest` if the HTTP request fails.
pub async fn change_showcase_status(&self, blog_name: &str, status: bool) -> ResultApi<()> {
let path = format!("blog/{blog_name}/showcase/status/");
let response = self
.put_request(&path, &serde_json::json!({"is_enabled": status}), true)
.await?;
self.handle_response(&path, response).await?;
Ok(())
}
}