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