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