1use crate::error::{ApiError, Result};
4use reqwest::Client;
5use serde_json::Value;
6use url::Url;
7
8pub struct WikiClient {
10 base_url: String,
11 client: Client,
12}
13
14impl WikiClient {
15 pub fn new(base_url: String, client: Client) -> Self {
17 Self { base_url, client }
18 }
19
20 pub fn with_auth(self, token: &str) -> Self {
22 self
24 }
25
26 pub async fn post_repo_upload_wiki_branch_name(
28 &self,
29 repo: String,
30 branch_name: String,
31 request_data: serde_json::Value,
32 ) -> Result<Value> {
33 let path = format!("/{}/-/upload/wiki/{}", repo, branch_name);
34 let url = Url::parse(&format!("{}{}", self.base_url, path))?;
35
36
37
38 let mut request = self.client.request(
39 reqwest::Method::POST,
40 url
41 );
42
43
44
45 request = request.json(&request_data);
46
47 let response = request.send().await?;
48
49 if response.status().is_success() {
50 let json: Value = response.json().await?;
51 Ok(json)
52 } else {
53 Err(ApiError::HttpError(response.status().as_u16()))
54 }
55 }
56
57}