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