jinxapi_github/v1_1_4/request/
scim_provision_and_invite_user.rs1pub 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_org: &str,
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() + 46);
43 url.push_str(trimmed);
44 url.push_str("/scim/v2/organizations/");
45 ::querylizer::Simple::extend(&mut url, &p_org, false, &::querylizer::encode_path)?;
46 url.push_str("/Users");
47 Ok(url)
48}
49
50#[cfg(feature = "hyper")]
51pub fn http_builder(
52 base_url: &str,
53 p_org: &str,
54 h_user_agent: &str,
55 h_accept: ::std::option::Option<&str>,
56) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
57 let url = url_string(
58 base_url,
59 p_org,
60 )?;
61 let mut builder = ::http::request::Request::post(url);
62 builder = builder.header(
63 "User-Agent",
64 &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
65 );
66 if let Some(value) = &h_accept {
67 builder = builder.header(
68 "Accept",
69 &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
70 );
71 }
72 Ok(builder)
73}
74
75#[cfg(feature = "hyper")]
76pub fn hyper_request(
77 mut builder: ::http::request::Builder,
78 content: Content<::hyper::Body>,
79) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
80{
81 if let Some(content_type) = content.content_type() {
82 builder = builder.header(::http::header::CONTENT_TYPE, content_type);
83 }
84 Ok(builder.body(content.into_body())?)
85}
86
87#[cfg(feature = "hyper")]
88impl From<::hyper::Body> for Content<::hyper::Body> {
89 fn from(body: ::hyper::Body) -> Self {
90 Self::new(body)
91 }
92}
93
94#[cfg(feature = "reqwest")]
95pub fn reqwest_builder(
96 base_url: &str,
97 p_org: &str,
98 h_user_agent: &str,
99 h_accept: ::std::option::Option<&str>,
100) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
101 let url = url_string(
102 base_url,
103 p_org,
104 )?;
105 let reqwest_url = ::reqwest::Url::parse(&url)?;
106 let mut request = ::reqwest::Request::new(::reqwest::Method::POST, reqwest_url);
107 let headers = request.headers_mut();
108 headers.append(
109 "User-Agent",
110 ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
111 );
112 if let Some(value) = &h_accept {
113 headers.append(
114 "Accept",
115 ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
116 );
117 }
118 Ok(request)
119}
120
121#[cfg(feature = "reqwest")]
122pub fn reqwest_request(
123 mut builder: ::reqwest::Request,
124 content: Content<::reqwest::Body>,
125) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
126 if let Some(content_type) = content.content_type() {
127 builder.headers_mut().append(
128 ::reqwest::header::HeaderName::from_static("content-type"),
129 ::reqwest::header::HeaderValue::try_from(content_type)?,
130 );
131 }
132 *builder.body_mut() = Some(content.into_body());
133 Ok(builder)
134}
135
136#[cfg(feature = "reqwest")]
137impl From<::reqwest::Body> for Content<::reqwest::Body> {
138 fn from(body: ::reqwest::Body) -> Self {
139 Self::new(body)
140 }
141}
142
143#[cfg(feature = "reqwest-blocking")]
144pub fn reqwest_blocking_builder(
145 base_url: &str,
146 p_org: &str,
147 h_user_agent: &str,
148 h_accept: ::std::option::Option<&str>,
149) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
150 let url = url_string(
151 base_url,
152 p_org,
153 )?;
154 let reqwest_url = ::reqwest::Url::parse(&url)?;
155 let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::POST, reqwest_url);
156 let headers = request.headers_mut();
157 headers.append(
158 "User-Agent",
159 ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
160 );
161 if let Some(value) = &h_accept {
162 headers.append(
163 "Accept",
164 ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
165 );
166 }
167 Ok(request)
168}
169
170#[cfg(feature = "reqwest-blocking")]
171pub fn reqwest_blocking_request(
172 mut builder: ::reqwest::blocking::Request,
173 content: Content<::reqwest::blocking::Body>,
174) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
175 if let Some(content_type) = content.content_type() {
176 builder.headers_mut().append(
177 ::reqwest::header::HeaderName::from_static("content-type"),
178 ::reqwest::header::HeaderValue::try_from(content_type)?,
179 );
180 }
181 *builder.body_mut() = Some(content.into_body());
182 Ok(builder)
183}
184
185#[cfg(feature = "reqwest-blocking")]
186impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
187 fn from(body: ::reqwest::blocking::Body) -> Self {
188 Self::new(body)
189 }
190}
191
192pub mod body {
194 #[allow(non_snake_case)]
195 #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
196 pub struct Json<'a> {
197 #[serde(rename = "userName")]
205 pub user_name: ::std::borrow::Cow<'a, str>,
206
207 #[serde(rename = "displayName", skip_serializing_if = "Option::is_none", default)]
215 pub display_name: ::std::option::Option<::std::borrow::Cow<'a, str>>,
216
217 pub name: crate::v1_1_4::request::scim_provision_and_invite_user::body::json::Name<'a>,
218
219 pub emails: ::std::borrow::Cow<'a, [crate::v1_1_4::request::scim_provision_and_invite_user::body::json::Emails<'a>]>,
236
237 #[serde(skip_serializing_if = "Option::is_none", default)]
238 pub schemas: ::std::option::Option<::std::borrow::Cow<'a, [::std::borrow::Cow<'a, str>]>>,
239
240 #[serde(rename = "externalId", skip_serializing_if = "Option::is_none", default)]
241 pub external_id: ::std::option::Option<::std::borrow::Cow<'a, str>>,
242
243 #[serde(skip_serializing_if = "Option::is_none", default)]
244 pub groups: ::std::option::Option<::std::borrow::Cow<'a, [::std::borrow::Cow<'a, str>]>>,
245
246 #[serde(skip_serializing_if = "Option::is_none", default)]
247 pub active: ::std::option::Option<bool>,
248
249 #[serde(flatten)]
250 pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
251 }
252
253 pub mod json {
255 #[allow(non_snake_case)]
264 #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
265 pub struct Name<'a> {
266 #[serde(rename = "givenName")]
267 pub given_name: ::std::borrow::Cow<'a, str>,
268
269 #[serde(rename = "familyName")]
270 pub family_name: ::std::borrow::Cow<'a, str>,
271
272 #[serde(skip_serializing_if = "Option::is_none", default)]
273 pub formatted: ::std::option::Option<::std::borrow::Cow<'a, str>>,
274
275 #[serde(flatten)]
276 pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
277 }
278
279 #[allow(non_snake_case)]
280 #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
281 pub struct Emails<'a> {
282 pub value: ::std::borrow::Cow<'a, str>,
283
284 #[serde(skip_serializing_if = "Option::is_none", default)]
285 pub primary: ::std::option::Option<bool>,
286
287 #[serde(skip_serializing_if = "Option::is_none", default)]
288 pub r#type: ::std::option::Option<::std::borrow::Cow<'a, str>>,
289
290 #[serde(flatten)]
291 pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
292 }
293 }
294
295 #[cfg(feature = "hyper")]
296 impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
297 type Error = crate::v1_1_4::ApiError;
298
299 fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
300 Ok(
301 Self::new(::serde_json::to_vec(value)?.into())
302 .with_content_type(&b"application/json"[..])
303 )
304 }
305 }
306
307 #[cfg(feature = "reqwest")]
308 impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
309 type Error = crate::v1_1_4::ApiError;
310
311 fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
312 Ok(
313 Self::new(::serde_json::to_vec(value)?.into())
314 .with_content_type(&b"application/json"[..])
315 )
316 }
317 }
318
319 #[cfg(feature = "reqwest-blocking")]
320 impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
321 type Error = crate::v1_1_4::ApiError;
322
323 fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
324 Ok(
325 Self::new(::serde_json::to_vec(value)?.into())
326 .with_content_type(&b"application/json"[..])
327 )
328 }
329 }
330}