jinxapi_github/v1_1_4/request/
projects_update.rs

1//! Update a project
2//! 
3//! Updates a project board's information. Returns a `404 Not Found` status if projects are disabled. If you do not have sufficient privileges to perform this action, a `401 Unauthorized` or `410 Gone` status is returned.
4//! 
5//! [API method documentation](https://docs.github.com/rest/reference/projects#update-a-project)
6
7pub struct Content<Body>
8{
9    body: Body,
10    content_type_value: Option<::std::borrow::Cow<'static, [u8]>>,
11}
12
13impl<Body> Content<Body> {
14    pub fn new(body: Body) -> Self {
15        Self { body, content_type_value: None }
16    }
17
18    #[must_use]
19    pub fn with_content_type(mut self, content_type: impl Into<::std::borrow::Cow<'static, [u8]>>) -> Self {
20        self.content_type_value = Some(content_type.into());
21        self
22    }
23
24    fn content_type(&self) -> Option<&[u8]> {
25        self.content_type_value.as_deref()
26    }
27
28    fn into_body(self) -> Body {
29        self.body
30    }
31}
32
33fn url_string(
34    base_url: &str,
35    p_project_id: i64,
36) -> Result<String, crate::v1_1_4::ApiError> {
37    let trimmed = if base_url.is_empty() {
38        "https://api.github.com"
39    } else {
40        base_url.trim_end_matches('/')
41    };
42    let mut url = String::with_capacity(trimmed.len() + 27);
43    url.push_str(trimmed);
44    url.push_str("/projects/");
45    ::querylizer::Simple::extend(&mut url, &p_project_id, false, &::querylizer::encode_path)?;
46    Ok(url)
47}
48
49#[cfg(feature = "hyper")]
50pub fn http_builder(
51    base_url: &str,
52    p_project_id: i64,
53    h_user_agent: &str,
54    h_accept: ::std::option::Option<&str>,
55) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
56    let url = url_string(
57        base_url,
58        p_project_id,
59    )?;
60    let mut builder = ::http::request::Request::patch(url);
61    builder = builder.header(
62        "User-Agent",
63        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
64    );
65    if let Some(value) = &h_accept {
66        builder = builder.header(
67            "Accept",
68            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
69        );
70    }
71    Ok(builder)
72}
73
74#[cfg(feature = "hyper")]
75pub fn hyper_request(
76    mut builder: ::http::request::Builder,
77    content: Content<::hyper::Body>,
78) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
79{
80    if let Some(content_type) = content.content_type() {
81        builder = builder.header(::http::header::CONTENT_TYPE, content_type);
82    }
83    Ok(builder.body(content.into_body())?)
84}
85
86#[cfg(feature = "hyper")]
87impl From<::hyper::Body> for Content<::hyper::Body> {
88    fn from(body: ::hyper::Body) -> Self {
89        Self::new(body)
90    }
91}
92
93#[cfg(feature = "reqwest")]
94pub fn reqwest_builder(
95    base_url: &str,
96    p_project_id: i64,
97    h_user_agent: &str,
98    h_accept: ::std::option::Option<&str>,
99) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
100    let url = url_string(
101        base_url,
102        p_project_id,
103    )?;
104    let reqwest_url = ::reqwest::Url::parse(&url)?;
105    let mut request = ::reqwest::Request::new(::reqwest::Method::PATCH, reqwest_url);
106    let headers = request.headers_mut();
107    headers.append(
108        "User-Agent",
109        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
110    );
111    if let Some(value) = &h_accept {
112        headers.append(
113            "Accept",
114            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
115        );
116    }
117    Ok(request)
118}
119
120#[cfg(feature = "reqwest")]
121pub fn reqwest_request(
122    mut builder: ::reqwest::Request,
123    content: Content<::reqwest::Body>,
124) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
125    if let Some(content_type) = content.content_type() {
126        builder.headers_mut().append(
127            ::reqwest::header::HeaderName::from_static("content-type"),
128            ::reqwest::header::HeaderValue::try_from(content_type)?,
129        );
130    }
131    *builder.body_mut() = Some(content.into_body());
132    Ok(builder)
133}
134
135#[cfg(feature = "reqwest")]
136impl From<::reqwest::Body> for Content<::reqwest::Body> {
137    fn from(body: ::reqwest::Body) -> Self {
138        Self::new(body)
139    }
140}
141
142#[cfg(feature = "reqwest-blocking")]
143pub fn reqwest_blocking_builder(
144    base_url: &str,
145    p_project_id: i64,
146    h_user_agent: &str,
147    h_accept: ::std::option::Option<&str>,
148) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
149    let url = url_string(
150        base_url,
151        p_project_id,
152    )?;
153    let reqwest_url = ::reqwest::Url::parse(&url)?;
154    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::PATCH, reqwest_url);
155    let headers = request.headers_mut();
156    headers.append(
157        "User-Agent",
158        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
159    );
160    if let Some(value) = &h_accept {
161        headers.append(
162            "Accept",
163            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
164        );
165    }
166    Ok(request)
167}
168
169#[cfg(feature = "reqwest-blocking")]
170pub fn reqwest_blocking_request(
171    mut builder: ::reqwest::blocking::Request,
172    content: Content<::reqwest::blocking::Body>,
173) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
174    if let Some(content_type) = content.content_type() {
175        builder.headers_mut().append(
176            ::reqwest::header::HeaderName::from_static("content-type"),
177            ::reqwest::header::HeaderValue::try_from(content_type)?,
178        );
179    }
180    *builder.body_mut() = Some(content.into_body());
181    Ok(builder)
182}
183
184#[cfg(feature = "reqwest-blocking")]
185impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
186    fn from(body: ::reqwest::blocking::Body) -> Self {
187        Self::new(body)
188    }
189}
190
191/// Types for body parameter in [`super::projects_update`]
192pub mod body {
193    #[allow(non_snake_case)]
194    #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
195    pub struct Json<'a> {
196        /// Name of the project
197        /// 
198        /// # Example
199        /// 
200        /// ```json
201        /// "Week One Sprint"
202        /// ```
203        #[serde(skip_serializing_if = "Option::is_none", default)]
204        pub name: ::std::option::Option<::std::borrow::Cow<'a, str>>,
205
206        /// Body of the project
207        /// 
208        /// # Example
209        /// 
210        /// ```json
211        /// "This project represents the sprint of the first week in January"
212        /// ```
213        #[serde(skip_serializing_if = "Option::is_none", default, deserialize_with = "crate::v1_1_4::support::deserialize_some")]
214        pub body: ::std::option::Option<::std::option::Option<::std::borrow::Cow<'a, str>>>,
215
216        /// State of the project; either 'open' or 'closed'
217        /// 
218        /// # Example
219        /// 
220        /// ```json
221        /// "open"
222        /// ```
223        #[serde(skip_serializing_if = "Option::is_none", default)]
224        pub state: ::std::option::Option<::std::borrow::Cow<'a, str>>,
225
226        /// The baseline permission that all organization members have on this project
227        #[serde(skip_serializing_if = "Option::is_none", default)]
228        pub organization_permission: ::std::option::Option<::std::borrow::Cow<'a, str>>,
229
230        /// Whether or not this project can be seen by everyone.
231        #[serde(skip_serializing_if = "Option::is_none", default)]
232        pub private: ::std::option::Option<bool>,
233
234        #[serde(flatten)]
235        pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
236    }
237
238    #[cfg(feature = "hyper")]
239    impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
240        type Error = crate::v1_1_4::ApiError;
241
242        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
243            Ok(
244                Self::new(::serde_json::to_vec(value)?.into())
245                .with_content_type(&b"application/json"[..])
246            )
247        }
248    }
249
250    #[cfg(feature = "reqwest")]
251    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
252        type Error = crate::v1_1_4::ApiError;
253
254        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
255            Ok(
256                Self::new(::serde_json::to_vec(value)?.into())
257                .with_content_type(&b"application/json"[..])
258            )
259        }
260    }
261
262    #[cfg(feature = "reqwest-blocking")]
263    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
264        type Error = crate::v1_1_4::ApiError;
265
266        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
267            Ok(
268                Self::new(::serde_json::to_vec(value)?.into())
269                .with_content_type(&b"application/json"[..])
270            )
271        }
272    }
273}