jinxapi_github/v1_1_4/request/
apps_delete_authorization.rs

1//! Delete an app authorization
2//! 
3//! OAuth application owners can revoke a grant for their OAuth application and a specific user. You must use [Basic Authentication](https://docs.github.com/rest/overview/other-authentication-methods#basic-authentication) when accessing this endpoint, using the OAuth application's `client_id` and `client_secret` as the username and password. You must also provide a valid OAuth `access_token` as an input parameter and the grant for the token's owner will be deleted.
4//! Deleting an OAuth application's grant will also delete all OAuth tokens associated with the application for the user. Once deleted, the application will have no access to the user's account and will no longer be listed on [the application authorizations settings screen within GitHub](https://github.com/settings/applications#authorized).
5//! 
6//! [API method documentation](https://docs.github.com/rest/reference/apps#delete-an-app-authorization)
7
8pub struct Content<Body>
9{
10    body: Body,
11    content_type_value: Option<::std::borrow::Cow<'static, [u8]>>,
12}
13
14impl<Body> Content<Body> {
15    pub fn new(body: Body) -> Self {
16        Self { body, content_type_value: None }
17    }
18
19    #[must_use]
20    pub fn with_content_type(mut self, content_type: impl Into<::std::borrow::Cow<'static, [u8]>>) -> Self {
21        self.content_type_value = Some(content_type.into());
22        self
23    }
24
25    fn content_type(&self) -> Option<&[u8]> {
26        self.content_type_value.as_deref()
27    }
28
29    fn into_body(self) -> Body {
30        self.body
31    }
32}
33
34fn url_string(
35    base_url: &str,
36    p_client_id: &str,
37) -> Result<String, crate::v1_1_4::ApiError> {
38    let trimmed = if base_url.is_empty() {
39        "https://api.github.com"
40    } else {
41        base_url.trim_end_matches('/')
42    };
43    let mut url = String::with_capacity(trimmed.len() + 37);
44    url.push_str(trimmed);
45    url.push_str("/applications/");
46    ::querylizer::Simple::extend(&mut url, &p_client_id, false, &::querylizer::encode_path)?;
47    url.push_str("/grant");
48    Ok(url)
49}
50
51#[cfg(feature = "hyper")]
52pub fn http_builder(
53    base_url: &str,
54    p_client_id: &str,
55    h_user_agent: &str,
56    h_accept: ::std::option::Option<&str>,
57) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
58    let url = url_string(
59        base_url,
60        p_client_id,
61    )?;
62    let mut builder = ::http::request::Request::delete(url);
63    builder = builder.header(
64        "User-Agent",
65        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
66    );
67    if let Some(value) = &h_accept {
68        builder = builder.header(
69            "Accept",
70            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
71        );
72    }
73    Ok(builder)
74}
75
76#[cfg(feature = "hyper")]
77pub fn hyper_request(
78    mut builder: ::http::request::Builder,
79    content: Content<::hyper::Body>,
80) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
81{
82    if let Some(content_type) = content.content_type() {
83        builder = builder.header(::http::header::CONTENT_TYPE, content_type);
84    }
85    Ok(builder.body(content.into_body())?)
86}
87
88#[cfg(feature = "hyper")]
89impl From<::hyper::Body> for Content<::hyper::Body> {
90    fn from(body: ::hyper::Body) -> Self {
91        Self::new(body)
92    }
93}
94
95#[cfg(feature = "reqwest")]
96pub fn reqwest_builder(
97    base_url: &str,
98    p_client_id: &str,
99    h_user_agent: &str,
100    h_accept: ::std::option::Option<&str>,
101) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
102    let url = url_string(
103        base_url,
104        p_client_id,
105    )?;
106    let reqwest_url = ::reqwest::Url::parse(&url)?;
107    let mut request = ::reqwest::Request::new(::reqwest::Method::DELETE, reqwest_url);
108    let headers = request.headers_mut();
109    headers.append(
110        "User-Agent",
111        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
112    );
113    if let Some(value) = &h_accept {
114        headers.append(
115            "Accept",
116            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
117        );
118    }
119    Ok(request)
120}
121
122#[cfg(feature = "reqwest")]
123pub fn reqwest_request(
124    mut builder: ::reqwest::Request,
125    content: Content<::reqwest::Body>,
126) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
127    if let Some(content_type) = content.content_type() {
128        builder.headers_mut().append(
129            ::reqwest::header::HeaderName::from_static("content-type"),
130            ::reqwest::header::HeaderValue::try_from(content_type)?,
131        );
132    }
133    *builder.body_mut() = Some(content.into_body());
134    Ok(builder)
135}
136
137#[cfg(feature = "reqwest")]
138impl From<::reqwest::Body> for Content<::reqwest::Body> {
139    fn from(body: ::reqwest::Body) -> Self {
140        Self::new(body)
141    }
142}
143
144#[cfg(feature = "reqwest-blocking")]
145pub fn reqwest_blocking_builder(
146    base_url: &str,
147    p_client_id: &str,
148    h_user_agent: &str,
149    h_accept: ::std::option::Option<&str>,
150) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
151    let url = url_string(
152        base_url,
153        p_client_id,
154    )?;
155    let reqwest_url = ::reqwest::Url::parse(&url)?;
156    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::DELETE, reqwest_url);
157    let headers = request.headers_mut();
158    headers.append(
159        "User-Agent",
160        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
161    );
162    if let Some(value) = &h_accept {
163        headers.append(
164            "Accept",
165            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
166        );
167    }
168    Ok(request)
169}
170
171#[cfg(feature = "reqwest-blocking")]
172pub fn reqwest_blocking_request(
173    mut builder: ::reqwest::blocking::Request,
174    content: Content<::reqwest::blocking::Body>,
175) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
176    if let Some(content_type) = content.content_type() {
177        builder.headers_mut().append(
178            ::reqwest::header::HeaderName::from_static("content-type"),
179            ::reqwest::header::HeaderValue::try_from(content_type)?,
180        );
181    }
182    *builder.body_mut() = Some(content.into_body());
183    Ok(builder)
184}
185
186#[cfg(feature = "reqwest-blocking")]
187impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
188    fn from(body: ::reqwest::blocking::Body) -> Self {
189        Self::new(body)
190    }
191}
192
193/// Types for body parameter in [`super::apps_delete_authorization`]
194pub mod body {
195    #[allow(non_snake_case)]
196    #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
197    pub struct Json<'a> {
198        /// The OAuth access token used to authenticate to the GitHub API.
199        pub access_token: ::std::borrow::Cow<'a, str>,
200
201        #[serde(flatten)]
202        pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
203    }
204
205    #[cfg(feature = "hyper")]
206    impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
207        type Error = crate::v1_1_4::ApiError;
208
209        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
210            Ok(
211                Self::new(::serde_json::to_vec(value)?.into())
212                .with_content_type(&b"application/json"[..])
213            )
214        }
215    }
216
217    #[cfg(feature = "reqwest")]
218    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
219        type Error = crate::v1_1_4::ApiError;
220
221        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
222            Ok(
223                Self::new(::serde_json::to_vec(value)?.into())
224                .with_content_type(&b"application/json"[..])
225            )
226        }
227    }
228
229    #[cfg(feature = "reqwest-blocking")]
230    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::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}