jinxapi_github/v1_1_4/request/
gists_update_comment.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_gist_id: &str,
34 p_comment_id: i64,
35) -> Result<String, crate::v1_1_4::ApiError> {
36 let trimmed = if base_url.is_empty() {
37 "https://api.github.com"
38 } else {
39 base_url.trim_end_matches('/')
40 };
41 let mut url = String::with_capacity(trimmed.len() + 35);
42 url.push_str(trimmed);
43 url.push_str("/gists/");
44 ::querylizer::Simple::extend(&mut url, &p_gist_id, false, &::querylizer::encode_path)?;
45 url.push_str("/comments/");
46 ::querylizer::Simple::extend(&mut url, &p_comment_id, false, &::querylizer::encode_path)?;
47 Ok(url)
48}
49
50#[cfg(feature = "hyper")]
51pub fn http_builder(
52 base_url: &str,
53 p_gist_id: &str,
54 p_comment_id: i64,
55 h_user_agent: &str,
56 h_accept: ::std::option::Option<&str>,
57) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
58 let url = url_string(
59 base_url,
60 p_gist_id,
61 p_comment_id,
62 )?;
63 let mut builder = ::http::request::Request::patch(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_gist_id: &str,
100 p_comment_id: i64,
101 h_user_agent: &str,
102 h_accept: ::std::option::Option<&str>,
103) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
104 let url = url_string(
105 base_url,
106 p_gist_id,
107 p_comment_id,
108 )?;
109 let reqwest_url = ::reqwest::Url::parse(&url)?;
110 let mut request = ::reqwest::Request::new(::reqwest::Method::PATCH, 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_gist_id: &str,
151 p_comment_id: i64,
152 h_user_agent: &str,
153 h_accept: ::std::option::Option<&str>,
154) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
155 let url = url_string(
156 base_url,
157 p_gist_id,
158 p_comment_id,
159 )?;
160 let reqwest_url = ::reqwest::Url::parse(&url)?;
161 let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::PATCH, reqwest_url);
162 let headers = request.headers_mut();
163 headers.append(
164 "User-Agent",
165 ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
166 );
167 if let Some(value) = &h_accept {
168 headers.append(
169 "Accept",
170 ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
171 );
172 }
173 Ok(request)
174}
175
176#[cfg(feature = "reqwest-blocking")]
177pub fn reqwest_blocking_request(
178 mut builder: ::reqwest::blocking::Request,
179 content: Content<::reqwest::blocking::Body>,
180) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
181 if let Some(content_type) = content.content_type() {
182 builder.headers_mut().append(
183 ::reqwest::header::HeaderName::from_static("content-type"),
184 ::reqwest::header::HeaderValue::try_from(content_type)?,
185 );
186 }
187 *builder.body_mut() = Some(content.into_body());
188 Ok(builder)
189}
190
191#[cfg(feature = "reqwest-blocking")]
192impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
193 fn from(body: ::reqwest::blocking::Body) -> Self {
194 Self::new(body)
195 }
196}
197
198pub mod body {
200 #[allow(non_snake_case)]
201 #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
202 pub struct Json<'a> {
203 pub body: ::std::borrow::Cow<'a, str>,
211
212 #[serde(flatten)]
213 pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
214 }
215
216 #[cfg(feature = "hyper")]
217 impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
218 type Error = crate::v1_1_4::ApiError;
219
220 fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
221 Ok(
222 Self::new(::serde_json::to_vec(value)?.into())
223 .with_content_type(&b"application/json"[..])
224 )
225 }
226 }
227
228 #[cfg(feature = "reqwest")]
229 impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
230 type Error = crate::v1_1_4::ApiError;
231
232 fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
233 Ok(
234 Self::new(::serde_json::to_vec(value)?.into())
235 .with_content_type(&b"application/json"[..])
236 )
237 }
238 }
239
240 #[cfg(feature = "reqwest-blocking")]
241 impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
242 type Error = crate::v1_1_4::ApiError;
243
244 fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
245 Ok(
246 Self::new(::serde_json::to_vec(value)?.into())
247 .with_content_type(&b"application/json"[..])
248 )
249 }
250 }
251}