pinterest_api/api/
patch_boards_board_id_sections_section_id.rs1use reqwest::RequestBuilder;
2use serde::{Deserialize, Serialize};
3
4use crate::{
5 api::{execute_api, ApiResponse},
6 error::Error,
7 options::{apply_options, make_url, ApiOptions},
8 response::board_section::BoardSection,
9};
10
11#[derive(Serialize, Deserialize, Debug, Default, Clone)]
12pub struct Body {
13 pub name: String,
14}
15
16#[derive(Debug, Clone, Default)]
17pub struct Api {
18 options: Option<ApiOptions>,
19 board_id: String,
20 section_id: String,
21 ad_account_id: Option<String>,
22 body: Body,
23}
24
25impl Api {
26 pub fn new(options: Option<ApiOptions>, body: Body, board_id: &str, section_id: &str) -> Self {
27 Self {
28 options,
29 body,
30 board_id: board_id.to_string(),
31 section_id: section_id.to_string(),
32 ..Default::default()
33 }
34 }
35
36 pub fn ad_account_id(mut self, ad_account_id: &str) -> Self {
37 self.ad_account_id = Some(ad_account_id.to_string());
38 self
39 }
40
41 pub fn build(self, bearer_code: &str) -> RequestBuilder {
42 let mut query_parameters = vec![];
43 if let Some(ad_account_id) = self.ad_account_id {
44 query_parameters.push(("ad_account_id", ad_account_id));
45 }
46 let client = reqwest::Client::new()
47 .patch(make_url(
48 &format!("/boards/{}/sections/{}", self.board_id, self.section_id),
49 &self.options,
50 ))
51 .query(&query_parameters)
52 .json(&self.body)
53 .bearer_auth(bearer_code);
54 apply_options(client, &self.options)
55 }
56
57 pub async fn execute(self, bearer_code: &str) -> Result<ApiResponse<BoardSection>, Error> {
58 execute_api(self.build(bearer_code)).await
59 }
60}
61
62#[cfg(test)]
63mod tests {
64 use super::*;
65
66 #[tokio::test]
69 async fn test_patch_boards_board_id_sections_section_id() {
70 let bearer_code = std::env::var("BEARER_CODE").unwrap_or_default();
71 let board_id = std::env::var("BOARD_ID").unwrap_or_default();
72 let section_id = std::env::var("SECTION_ID").unwrap_or_default();
73 let body = Body {
74 name: "test".to_owned(),
75 };
76 let response = Api::new(None, body, &board_id, §ion_id)
77 .execute(bearer_code.as_str())
78 .await
79 .unwrap();
80 println!("{:?}", response);
81 }
82}