jinxapi_github/v1_1_4/request/
users_update_authenticated.rs

1//! Update the authenticated user
2//! 
3//! **Note:** If your email is set to private and you send an `email` parameter as part of this request to update your profile, your privacy settings are still enforced: the email address will not be displayed on your public profile or via the API.
4//! 
5//! [API method documentation](https://docs.github.com/rest/reference/users/#update-the-authenticated-user)
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
33#[cfg(feature = "hyper")]
34pub fn http_builder(
35    base_url: &str,
36    h_user_agent: &str,
37    h_accept: ::std::option::Option<&str>,
38) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
39    let default_url = concat!("https://api.github.com", "/user");
40    let url = if base_url.is_empty() {
41        ::http::uri::Uri::from_static(default_url)
42    } else {
43        let trimmed = base_url.trim_end_matches('/');
44        let mut url = String::with_capacity(trimmed.len() + 5);
45        url.push_str(trimmed);
46        url.push_str(&default_url[22..]);
47        url.try_into().map_err(::http::Error::from)?
48    };
49    let mut builder = ::http::request::Request::patch(url);
50    builder = builder.header(
51        "User-Agent",
52        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
53    );
54    if let Some(value) = &h_accept {
55        builder = builder.header(
56            "Accept",
57            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
58        );
59    }
60    Ok(builder)
61}
62
63#[cfg(feature = "hyper")]
64pub fn hyper_request(
65    mut builder: ::http::request::Builder,
66    content: Content<::hyper::Body>,
67) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
68{
69    if let Some(content_type) = content.content_type() {
70        builder = builder.header(::http::header::CONTENT_TYPE, content_type);
71    }
72    Ok(builder.body(content.into_body())?)
73}
74
75#[cfg(feature = "hyper")]
76impl From<::hyper::Body> for Content<::hyper::Body> {
77    fn from(body: ::hyper::Body) -> Self {
78        Self::new(body)
79    }
80}
81
82#[cfg(feature = "reqwest")]
83pub fn reqwest_builder(
84    base_url: &str,
85    h_user_agent: &str,
86    h_accept: ::std::option::Option<&str>,
87) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
88    let default_url = concat!("https://api.github.com", "/user");
89    let reqwest_url = if base_url.is_empty() {
90        ::reqwest::Url::parse(default_url)?
91    } else {
92        let trimmed = base_url.trim_end_matches('/');
93        let mut url = String::with_capacity(trimmed.len() + 5);
94        url.push_str(trimmed);
95        url.push_str(&default_url[22..]);
96        ::reqwest::Url::parse(&url)?
97    };
98    let mut request = ::reqwest::Request::new(::reqwest::Method::PATCH, reqwest_url);
99    let headers = request.headers_mut();
100    headers.append(
101        "User-Agent",
102        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
103    );
104    if let Some(value) = &h_accept {
105        headers.append(
106            "Accept",
107            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
108        );
109    }
110    Ok(request)
111}
112
113#[cfg(feature = "reqwest")]
114pub fn reqwest_request(
115    mut builder: ::reqwest::Request,
116    content: Content<::reqwest::Body>,
117) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
118    if let Some(content_type) = content.content_type() {
119        builder.headers_mut().append(
120            ::reqwest::header::HeaderName::from_static("content-type"),
121            ::reqwest::header::HeaderValue::try_from(content_type)?,
122        );
123    }
124    *builder.body_mut() = Some(content.into_body());
125    Ok(builder)
126}
127
128#[cfg(feature = "reqwest")]
129impl From<::reqwest::Body> for Content<::reqwest::Body> {
130    fn from(body: ::reqwest::Body) -> Self {
131        Self::new(body)
132    }
133}
134
135#[cfg(feature = "reqwest-blocking")]
136pub fn reqwest_blocking_builder(
137    base_url: &str,
138    h_user_agent: &str,
139    h_accept: ::std::option::Option<&str>,
140) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
141    let default_url = concat!("https://api.github.com", "/user");
142    let reqwest_url = if base_url.is_empty() {
143        ::reqwest::Url::parse(default_url)?
144    } else {
145        let trimmed = base_url.trim_end_matches('/');
146        let mut url = String::with_capacity(trimmed.len() + 5);
147        url.push_str(trimmed);
148        url.push_str(&default_url[22..]);
149        ::reqwest::Url::parse(&url)?
150    };
151    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::PATCH, reqwest_url);
152    let headers = request.headers_mut();
153    headers.append(
154        "User-Agent",
155        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
156    );
157    if let Some(value) = &h_accept {
158        headers.append(
159            "Accept",
160            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
161        );
162    }
163    Ok(request)
164}
165
166#[cfg(feature = "reqwest-blocking")]
167pub fn reqwest_blocking_request(
168    mut builder: ::reqwest::blocking::Request,
169    content: Content<::reqwest::blocking::Body>,
170) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
171    if let Some(content_type) = content.content_type() {
172        builder.headers_mut().append(
173            ::reqwest::header::HeaderName::from_static("content-type"),
174            ::reqwest::header::HeaderValue::try_from(content_type)?,
175        );
176    }
177    *builder.body_mut() = Some(content.into_body());
178    Ok(builder)
179}
180
181#[cfg(feature = "reqwest-blocking")]
182impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
183    fn from(body: ::reqwest::blocking::Body) -> Self {
184        Self::new(body)
185    }
186}
187
188/// Types for body parameter in [`super::users_update_authenticated`]
189pub mod body {
190    #[allow(non_snake_case)]
191    #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
192    pub struct Json<'a> {
193        /// The new name of the user.
194        /// 
195        /// # Example
196        /// 
197        /// ```json
198        /// "Omar Jahandar"
199        /// ```
200        #[serde(skip_serializing_if = "Option::is_none", default)]
201        pub name: ::std::option::Option<::std::borrow::Cow<'a, str>>,
202
203        /// The publicly visible email address of the user.
204        /// 
205        /// # Example
206        /// 
207        /// ```json
208        /// "omar@example.com"
209        /// ```
210        #[serde(skip_serializing_if = "Option::is_none", default)]
211        pub email: ::std::option::Option<::std::borrow::Cow<'a, str>>,
212
213        /// The new blog URL of the user.
214        /// 
215        /// # Example
216        /// 
217        /// ```json
218        /// "blog.example.com"
219        /// ```
220        #[serde(skip_serializing_if = "Option::is_none", default)]
221        pub blog: ::std::option::Option<::std::borrow::Cow<'a, str>>,
222
223        /// The new Twitter username of the user.
224        /// 
225        /// # Example
226        /// 
227        /// ```json
228        /// "therealomarj"
229        /// ```
230        #[serde(skip_serializing_if = "Option::is_none", default, deserialize_with = "crate::v1_1_4::support::deserialize_some")]
231        pub twitter_username: ::std::option::Option<::std::option::Option<::std::borrow::Cow<'a, str>>>,
232
233        /// The new company of the user.
234        /// 
235        /// # Example
236        /// 
237        /// ```json
238        /// "Acme corporation"
239        /// ```
240        #[serde(skip_serializing_if = "Option::is_none", default)]
241        pub company: ::std::option::Option<::std::borrow::Cow<'a, str>>,
242
243        /// The new location of the user.
244        /// 
245        /// # Example
246        /// 
247        /// ```json
248        /// "Berlin, Germany"
249        /// ```
250        #[serde(skip_serializing_if = "Option::is_none", default)]
251        pub location: ::std::option::Option<::std::borrow::Cow<'a, str>>,
252
253        /// The new hiring availability of the user.
254        #[serde(skip_serializing_if = "Option::is_none", default)]
255        pub hireable: ::std::option::Option<bool>,
256
257        /// The new short biography of the user.
258        #[serde(skip_serializing_if = "Option::is_none", default)]
259        pub bio: ::std::option::Option<::std::borrow::Cow<'a, str>>,
260
261        #[serde(flatten)]
262        pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
263    }
264
265    #[cfg(feature = "hyper")]
266    impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
267        type Error = crate::v1_1_4::ApiError;
268
269        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
270            Ok(
271                Self::new(::serde_json::to_vec(value)?.into())
272                .with_content_type(&b"application/json"[..])
273            )
274        }
275    }
276
277    #[cfg(feature = "reqwest")]
278    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
279        type Error = crate::v1_1_4::ApiError;
280
281        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
282            Ok(
283                Self::new(::serde_json::to_vec(value)?.into())
284                .with_content_type(&b"application/json"[..])
285            )
286        }
287    }
288
289    #[cfg(feature = "reqwest-blocking")]
290    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
291        type Error = crate::v1_1_4::ApiError;
292
293        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
294            Ok(
295                Self::new(::serde_json::to_vec(value)?.into())
296                .with_content_type(&b"application/json"[..])
297            )
298        }
299    }
300}