jinxapi_github/v1_1_4/request/
teams_create.rs1pub struct Content<Body>
10{
11 body: Body,
12 content_type_value: Option<::std::borrow::Cow<'static, [u8]>>,
13}
14
15impl<Body> Content<Body> {
16 pub fn new(body: Body) -> Self {
17 Self { body, content_type_value: None }
18 }
19
20 #[must_use]
21 pub fn with_content_type(mut self, content_type: impl Into<::std::borrow::Cow<'static, [u8]>>) -> Self {
22 self.content_type_value = Some(content_type.into());
23 self
24 }
25
26 fn content_type(&self) -> Option<&[u8]> {
27 self.content_type_value.as_deref()
28 }
29
30 fn into_body(self) -> Body {
31 self.body
32 }
33}
34
35fn url_string(
36 base_url: &str,
37 p_org: &str,
38) -> Result<String, crate::v1_1_4::ApiError> {
39 let trimmed = if base_url.is_empty() {
40 "https://api.github.com"
41 } else {
42 base_url.trim_end_matches('/')
43 };
44 let mut url = String::with_capacity(trimmed.len() + 29);
45 url.push_str(trimmed);
46 url.push_str("/orgs/");
47 ::querylizer::Simple::extend(&mut url, &p_org, false, &::querylizer::encode_path)?;
48 url.push_str("/teams");
49 Ok(url)
50}
51
52#[cfg(feature = "hyper")]
53pub fn http_builder(
54 base_url: &str,
55 p_org: &str,
56 h_user_agent: &str,
57 h_accept: ::std::option::Option<&str>,
58) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
59 let url = url_string(
60 base_url,
61 p_org,
62 )?;
63 let mut builder = ::http::request::Request::post(url);
64 builder = builder.header(
65 "User-Agent",
66 &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
67 );
68 if let Some(value) = &h_accept {
69 builder = builder.header(
70 "Accept",
71 &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
72 );
73 }
74 Ok(builder)
75}
76
77#[cfg(feature = "hyper")]
78pub fn hyper_request(
79 mut builder: ::http::request::Builder,
80 content: Content<::hyper::Body>,
81) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
82{
83 if let Some(content_type) = content.content_type() {
84 builder = builder.header(::http::header::CONTENT_TYPE, content_type);
85 }
86 Ok(builder.body(content.into_body())?)
87}
88
89#[cfg(feature = "hyper")]
90impl From<::hyper::Body> for Content<::hyper::Body> {
91 fn from(body: ::hyper::Body) -> Self {
92 Self::new(body)
93 }
94}
95
96#[cfg(feature = "reqwest")]
97pub fn reqwest_builder(
98 base_url: &str,
99 p_org: &str,
100 h_user_agent: &str,
101 h_accept: ::std::option::Option<&str>,
102) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
103 let url = url_string(
104 base_url,
105 p_org,
106 )?;
107 let reqwest_url = ::reqwest::Url::parse(&url)?;
108 let mut request = ::reqwest::Request::new(::reqwest::Method::POST, reqwest_url);
109 let headers = request.headers_mut();
110 headers.append(
111 "User-Agent",
112 ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
113 );
114 if let Some(value) = &h_accept {
115 headers.append(
116 "Accept",
117 ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
118 );
119 }
120 Ok(request)
121}
122
123#[cfg(feature = "reqwest")]
124pub fn reqwest_request(
125 mut builder: ::reqwest::Request,
126 content: Content<::reqwest::Body>,
127) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
128 if let Some(content_type) = content.content_type() {
129 builder.headers_mut().append(
130 ::reqwest::header::HeaderName::from_static("content-type"),
131 ::reqwest::header::HeaderValue::try_from(content_type)?,
132 );
133 }
134 *builder.body_mut() = Some(content.into_body());
135 Ok(builder)
136}
137
138#[cfg(feature = "reqwest")]
139impl From<::reqwest::Body> for Content<::reqwest::Body> {
140 fn from(body: ::reqwest::Body) -> Self {
141 Self::new(body)
142 }
143}
144
145#[cfg(feature = "reqwest-blocking")]
146pub fn reqwest_blocking_builder(
147 base_url: &str,
148 p_org: &str,
149 h_user_agent: &str,
150 h_accept: ::std::option::Option<&str>,
151) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
152 let url = url_string(
153 base_url,
154 p_org,
155 )?;
156 let reqwest_url = ::reqwest::Url::parse(&url)?;
157 let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::POST, reqwest_url);
158 let headers = request.headers_mut();
159 headers.append(
160 "User-Agent",
161 ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
162 );
163 if let Some(value) = &h_accept {
164 headers.append(
165 "Accept",
166 ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
167 );
168 }
169 Ok(request)
170}
171
172#[cfg(feature = "reqwest-blocking")]
173pub fn reqwest_blocking_request(
174 mut builder: ::reqwest::blocking::Request,
175 content: Content<::reqwest::blocking::Body>,
176) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
177 if let Some(content_type) = content.content_type() {
178 builder.headers_mut().append(
179 ::reqwest::header::HeaderName::from_static("content-type"),
180 ::reqwest::header::HeaderValue::try_from(content_type)?,
181 );
182 }
183 *builder.body_mut() = Some(content.into_body());
184 Ok(builder)
185}
186
187#[cfg(feature = "reqwest-blocking")]
188impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
189 fn from(body: ::reqwest::blocking::Body) -> Self {
190 Self::new(body)
191 }
192}
193
194pub mod body {
196 #[allow(non_snake_case)]
197 #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
198 pub struct Json<'a> {
199 pub name: ::std::borrow::Cow<'a, str>,
201
202 #[serde(skip_serializing_if = "Option::is_none", default)]
204 pub description: ::std::option::Option<::std::borrow::Cow<'a, str>>,
205
206 #[serde(skip_serializing_if = "Option::is_none", default)]
208 pub maintainers: ::std::option::Option<::std::borrow::Cow<'a, [::std::borrow::Cow<'a, str>]>>,
209
210 #[serde(skip_serializing_if = "Option::is_none", default)]
212 pub repo_names: ::std::option::Option<::std::borrow::Cow<'a, [::std::borrow::Cow<'a, str>]>>,
213
214 #[serde(skip_serializing_if = "Option::is_none", default)]
223 pub privacy: ::std::option::Option<::std::borrow::Cow<'a, str>>,
224
225 #[serde(skip_serializing_if = "Option::is_none", default)]
229 pub permission: ::std::option::Option<::std::borrow::Cow<'a, str>>,
230
231 #[serde(skip_serializing_if = "Option::is_none", default)]
233 pub parent_team_id: ::std::option::Option<i64>,
234
235 #[serde(flatten)]
236 pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
237 }
238
239 #[cfg(feature = "hyper")]
240 impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
241 type Error = crate::v1_1_4::ApiError;
242
243 fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
244 Ok(
245 Self::new(::serde_json::to_vec(value)?.into())
246 .with_content_type(&b"application/json"[..])
247 )
248 }
249 }
250
251 #[cfg(feature = "reqwest")]
252 impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
253 type Error = crate::v1_1_4::ApiError;
254
255 fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
256 Ok(
257 Self::new(::serde_json::to_vec(value)?.into())
258 .with_content_type(&b"application/json"[..])
259 )
260 }
261 }
262
263 #[cfg(feature = "reqwest-blocking")]
264 impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
265 type Error = crate::v1_1_4::ApiError;
266
267 fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
268 Ok(
269 Self::new(::serde_json::to_vec(value)?.into())
270 .with_content_type(&b"application/json"[..])
271 )
272 }
273 }
274}