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