jinxapi_github/v1_1_4/request/
pulls_dismiss_review.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_owner: &str,
36 p_repo: &str,
37 p_pull_number: i64,
38 p_review_id: i64,
39) -> Result<String, crate::v1_1_4::ApiError> {
40 let trimmed = if base_url.is_empty() {
41 "https://api.github.com"
42 } else {
43 base_url.trim_end_matches('/')
44 };
45 let mut url = String::with_capacity(trimmed.len() + 55);
46 url.push_str(trimmed);
47 url.push_str("/repos/");
48 ::querylizer::Simple::extend(&mut url, &p_owner, false, &::querylizer::encode_path)?;
49 url.push('/');
50 ::querylizer::Simple::extend(&mut url, &p_repo, false, &::querylizer::encode_path)?;
51 url.push_str("/pulls/");
52 ::querylizer::Simple::extend(&mut url, &p_pull_number, false, &::querylizer::encode_path)?;
53 url.push_str("/reviews/");
54 ::querylizer::Simple::extend(&mut url, &p_review_id, false, &::querylizer::encode_path)?;
55 url.push_str("/dismissals");
56 Ok(url)
57}
58
59#[cfg(feature = "hyper")]
60pub fn http_builder(
61 base_url: &str,
62 p_owner: &str,
63 p_repo: &str,
64 p_pull_number: i64,
65 p_review_id: i64,
66 h_user_agent: &str,
67 h_accept: ::std::option::Option<&str>,
68) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
69 let url = url_string(
70 base_url,
71 p_owner,
72 p_repo,
73 p_pull_number,
74 p_review_id,
75 )?;
76 let mut builder = ::http::request::Request::put(url);
77 builder = builder.header(
78 "User-Agent",
79 &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
80 );
81 if let Some(value) = &h_accept {
82 builder = builder.header(
83 "Accept",
84 &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
85 );
86 }
87 Ok(builder)
88}
89
90#[cfg(feature = "hyper")]
91pub fn hyper_request(
92 mut builder: ::http::request::Builder,
93 content: Content<::hyper::Body>,
94) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
95{
96 if let Some(content_type) = content.content_type() {
97 builder = builder.header(::http::header::CONTENT_TYPE, content_type);
98 }
99 Ok(builder.body(content.into_body())?)
100}
101
102#[cfg(feature = "hyper")]
103impl From<::hyper::Body> for Content<::hyper::Body> {
104 fn from(body: ::hyper::Body) -> Self {
105 Self::new(body)
106 }
107}
108
109#[cfg(feature = "reqwest")]
110pub fn reqwest_builder(
111 base_url: &str,
112 p_owner: &str,
113 p_repo: &str,
114 p_pull_number: i64,
115 p_review_id: i64,
116 h_user_agent: &str,
117 h_accept: ::std::option::Option<&str>,
118) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
119 let url = url_string(
120 base_url,
121 p_owner,
122 p_repo,
123 p_pull_number,
124 p_review_id,
125 )?;
126 let reqwest_url = ::reqwest::Url::parse(&url)?;
127 let mut request = ::reqwest::Request::new(::reqwest::Method::PUT, reqwest_url);
128 let headers = request.headers_mut();
129 headers.append(
130 "User-Agent",
131 ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
132 );
133 if let Some(value) = &h_accept {
134 headers.append(
135 "Accept",
136 ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
137 );
138 }
139 Ok(request)
140}
141
142#[cfg(feature = "reqwest")]
143pub fn reqwest_request(
144 mut builder: ::reqwest::Request,
145 content: Content<::reqwest::Body>,
146) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
147 if let Some(content_type) = content.content_type() {
148 builder.headers_mut().append(
149 ::reqwest::header::HeaderName::from_static("content-type"),
150 ::reqwest::header::HeaderValue::try_from(content_type)?,
151 );
152 }
153 *builder.body_mut() = Some(content.into_body());
154 Ok(builder)
155}
156
157#[cfg(feature = "reqwest")]
158impl From<::reqwest::Body> for Content<::reqwest::Body> {
159 fn from(body: ::reqwest::Body) -> Self {
160 Self::new(body)
161 }
162}
163
164#[cfg(feature = "reqwest-blocking")]
165pub fn reqwest_blocking_builder(
166 base_url: &str,
167 p_owner: &str,
168 p_repo: &str,
169 p_pull_number: i64,
170 p_review_id: i64,
171 h_user_agent: &str,
172 h_accept: ::std::option::Option<&str>,
173) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
174 let url = url_string(
175 base_url,
176 p_owner,
177 p_repo,
178 p_pull_number,
179 p_review_id,
180 )?;
181 let reqwest_url = ::reqwest::Url::parse(&url)?;
182 let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::PUT, reqwest_url);
183 let headers = request.headers_mut();
184 headers.append(
185 "User-Agent",
186 ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
187 );
188 if let Some(value) = &h_accept {
189 headers.append(
190 "Accept",
191 ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
192 );
193 }
194 Ok(request)
195}
196
197#[cfg(feature = "reqwest-blocking")]
198pub fn reqwest_blocking_request(
199 mut builder: ::reqwest::blocking::Request,
200 content: Content<::reqwest::blocking::Body>,
201) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
202 if let Some(content_type) = content.content_type() {
203 builder.headers_mut().append(
204 ::reqwest::header::HeaderName::from_static("content-type"),
205 ::reqwest::header::HeaderValue::try_from(content_type)?,
206 );
207 }
208 *builder.body_mut() = Some(content.into_body());
209 Ok(builder)
210}
211
212#[cfg(feature = "reqwest-blocking")]
213impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
214 fn from(body: ::reqwest::blocking::Body) -> Self {
215 Self::new(body)
216 }
217}
218
219pub mod body {
221 #[allow(non_snake_case)]
222 #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
223 pub struct Json<'a> {
224 pub message: ::std::borrow::Cow<'a, str>,
226
227 #[serde(skip_serializing_if = "Option::is_none", default)]
233 pub event: ::std::option::Option<::std::borrow::Cow<'a, str>>,
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}