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
use reqwest::{header, Url};
use serde::de::DeserializeOwned;
use std::fmt::Debug;

use crate::CodebergClient;

impl CodebergClient {
    pub async fn patch_body<B, T>(&self, api_endpoint: Url, body: B) -> anyhow::Result<T>
    where
        B: serde::Serialize,
        T: DeserializeOwned + Debug,
    {
        tracing::debug!(
            "Making POST call. API endpoint: {:?}",
            api_endpoint.as_str()
        );
        let body = serde_json::to_string(&body)?;
        tracing::debug!("POST Body: {body}");
        let response = self
            .patch(api_endpoint)
            .header(
                header::CONTENT_TYPE,
                "application/json".parse::<header::HeaderValue>()?,
            )
            .body(body)
            .send()
            .await?;
        tracing::debug!("Response Status: {:?}", response.status());
        let json_response = response.json().await?;
        tracing::debug!("Response: {:?}", json_response);
        Ok(json_response)
    }
}