jinxapi_github/v1_1_4/request/
projects_update_column.rs

1//! Update an existing project column
2//! 
3//! [API method documentation](https://docs.github.com/rest/reference/projects#update-a-project-column)
4
5pub struct Content<Body>
6{
7    body: Body,
8    content_type_value: Option<::std::borrow::Cow<'static, [u8]>>,
9}
10
11impl<Body> Content<Body> {
12    pub fn new(body: Body) -> Self {
13        Self { body, content_type_value: None }
14    }
15
16    #[must_use]
17    pub fn with_content_type(mut self, content_type: impl Into<::std::borrow::Cow<'static, [u8]>>) -> Self {
18        self.content_type_value = Some(content_type.into());
19        self
20    }
21
22    fn content_type(&self) -> Option<&[u8]> {
23        self.content_type_value.as_deref()
24    }
25
26    fn into_body(self) -> Body {
27        self.body
28    }
29}
30
31fn url_string(
32    base_url: &str,
33    p_column_id: i64,
34) -> Result<String, crate::v1_1_4::ApiError> {
35    let trimmed = if base_url.is_empty() {
36        "https://api.github.com"
37    } else {
38        base_url.trim_end_matches('/')
39    };
40    let mut url = String::with_capacity(trimmed.len() + 35);
41    url.push_str(trimmed);
42    url.push_str("/projects/columns/");
43    ::querylizer::Simple::extend(&mut url, &p_column_id, false, &::querylizer::encode_path)?;
44    Ok(url)
45}
46
47#[cfg(feature = "hyper")]
48pub fn http_builder(
49    base_url: &str,
50    p_column_id: i64,
51    h_user_agent: &str,
52    h_accept: ::std::option::Option<&str>,
53) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
54    let url = url_string(
55        base_url,
56        p_column_id,
57    )?;
58    let mut builder = ::http::request::Request::patch(url);
59    builder = builder.header(
60        "User-Agent",
61        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
62    );
63    if let Some(value) = &h_accept {
64        builder = builder.header(
65            "Accept",
66            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
67        );
68    }
69    Ok(builder)
70}
71
72#[cfg(feature = "hyper")]
73pub fn hyper_request(
74    mut builder: ::http::request::Builder,
75    content: Content<::hyper::Body>,
76) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
77{
78    if let Some(content_type) = content.content_type() {
79        builder = builder.header(::http::header::CONTENT_TYPE, content_type);
80    }
81    Ok(builder.body(content.into_body())?)
82}
83
84#[cfg(feature = "hyper")]
85impl From<::hyper::Body> for Content<::hyper::Body> {
86    fn from(body: ::hyper::Body) -> Self {
87        Self::new(body)
88    }
89}
90
91#[cfg(feature = "reqwest")]
92pub fn reqwest_builder(
93    base_url: &str,
94    p_column_id: i64,
95    h_user_agent: &str,
96    h_accept: ::std::option::Option<&str>,
97) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
98    let url = url_string(
99        base_url,
100        p_column_id,
101    )?;
102    let reqwest_url = ::reqwest::Url::parse(&url)?;
103    let mut request = ::reqwest::Request::new(::reqwest::Method::PATCH, reqwest_url);
104    let headers = request.headers_mut();
105    headers.append(
106        "User-Agent",
107        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
108    );
109    if let Some(value) = &h_accept {
110        headers.append(
111            "Accept",
112            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
113        );
114    }
115    Ok(request)
116}
117
118#[cfg(feature = "reqwest")]
119pub fn reqwest_request(
120    mut builder: ::reqwest::Request,
121    content: Content<::reqwest::Body>,
122) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
123    if let Some(content_type) = content.content_type() {
124        builder.headers_mut().append(
125            ::reqwest::header::HeaderName::from_static("content-type"),
126            ::reqwest::header::HeaderValue::try_from(content_type)?,
127        );
128    }
129    *builder.body_mut() = Some(content.into_body());
130    Ok(builder)
131}
132
133#[cfg(feature = "reqwest")]
134impl From<::reqwest::Body> for Content<::reqwest::Body> {
135    fn from(body: ::reqwest::Body) -> Self {
136        Self::new(body)
137    }
138}
139
140#[cfg(feature = "reqwest-blocking")]
141pub fn reqwest_blocking_builder(
142    base_url: &str,
143    p_column_id: i64,
144    h_user_agent: &str,
145    h_accept: ::std::option::Option<&str>,
146) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
147    let url = url_string(
148        base_url,
149        p_column_id,
150    )?;
151    let reqwest_url = ::reqwest::Url::parse(&url)?;
152    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::PATCH, reqwest_url);
153    let headers = request.headers_mut();
154    headers.append(
155        "User-Agent",
156        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
157    );
158    if let Some(value) = &h_accept {
159        headers.append(
160            "Accept",
161            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
162        );
163    }
164    Ok(request)
165}
166
167#[cfg(feature = "reqwest-blocking")]
168pub fn reqwest_blocking_request(
169    mut builder: ::reqwest::blocking::Request,
170    content: Content<::reqwest::blocking::Body>,
171) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
172    if let Some(content_type) = content.content_type() {
173        builder.headers_mut().append(
174            ::reqwest::header::HeaderName::from_static("content-type"),
175            ::reqwest::header::HeaderValue::try_from(content_type)?,
176        );
177    }
178    *builder.body_mut() = Some(content.into_body());
179    Ok(builder)
180}
181
182#[cfg(feature = "reqwest-blocking")]
183impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
184    fn from(body: ::reqwest::blocking::Body) -> Self {
185        Self::new(body)
186    }
187}
188
189/// Types for body parameter in [`super::projects_update_column`]
190pub mod body {
191    #[allow(non_snake_case)]
192    #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
193    pub struct Json<'a> {
194        /// Name of the project column
195        /// 
196        /// # Example
197        /// 
198        /// ```json
199        /// "Remaining tasks"
200        /// ```
201        pub name: ::std::borrow::Cow<'a, str>,
202
203        #[serde(flatten)]
204        pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
205    }
206
207    #[cfg(feature = "hyper")]
208    impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
209        type Error = crate::v1_1_4::ApiError;
210
211        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
212            Ok(
213                Self::new(::serde_json::to_vec(value)?.into())
214                .with_content_type(&b"application/json"[..])
215            )
216        }
217    }
218
219    #[cfg(feature = "reqwest")]
220    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
221        type Error = crate::v1_1_4::ApiError;
222
223        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
224            Ok(
225                Self::new(::serde_json::to_vec(value)?.into())
226                .with_content_type(&b"application/json"[..])
227            )
228        }
229    }
230
231    #[cfg(feature = "reqwest-blocking")]
232    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
233        type Error = crate::v1_1_4::ApiError;
234
235        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
236            Ok(
237                Self::new(::serde_json::to_vec(value)?.into())
238                .with_content_type(&b"application/json"[..])
239            )
240        }
241    }
242}