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