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