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