twilight_http/request/
update_user_application.rs1use std::future::IntoFuture;
2
3use serde::Serialize;
4use twilight_model::oauth::{
5 Application, ApplicationFlags, ApplicationIntegrationMap, ApplicationIntegrationTypeConfig,
6 InstallParams,
7};
8
9#[cfg(not(target_os = "wasi"))]
10use crate::response::{Response, ResponseFuture};
11use crate::{
12 client::Client,
13 error::Error,
14 request::{Nullable, Request, TryIntoRequest},
15 routing::Route,
16};
17
18#[derive(Serialize)]
19struct UpdateCurrentUserApplicationFields<'a> {
20 #[serde(skip_serializing_if = "Option::is_none")]
21 cover_image: Option<Nullable<&'a str>>,
22 #[serde(skip_serializing_if = "Option::is_none")]
23 custom_install_url: Option<&'a str>,
24 #[serde(skip_serializing_if = "Option::is_none")]
25 description: Option<&'a str>,
26 #[serde(skip_serializing_if = "Option::is_none")]
27 flags: Option<ApplicationFlags>,
28 #[serde(skip_serializing_if = "Option::is_none")]
29 icon: Option<Nullable<&'a str>>,
30 #[serde(skip_serializing_if = "Option::is_none")]
31 install_params: Option<InstallParams>,
32 #[serde(skip_serializing_if = "Option::is_none")]
33 integration_types_config: Option<ApplicationIntegrationMap<ApplicationIntegrationTypeConfig>>,
34 #[serde(skip_serializing_if = "Option::is_none")]
35 interactions_endpoint_url: Option<&'a str>,
36 #[serde(skip_serializing_if = "Option::is_none")]
37 role_connections_verification_url: Option<&'a str>,
38 #[serde(skip_serializing_if = "Option::is_none")]
39 tags: Option<Vec<&'a str>>,
40}
41
42#[must_use = "requests must be configured and executed"]
71pub struct UpdateCurrentUserApplication<'a> {
72 fields: UpdateCurrentUserApplicationFields<'a>,
73 http: &'a Client,
74}
75
76impl<'a> UpdateCurrentUserApplication<'a> {
77 pub(crate) const fn new(http: &'a Client) -> Self {
78 Self {
79 fields: UpdateCurrentUserApplicationFields {
80 cover_image: None,
81 custom_install_url: None,
82 description: None,
83 flags: None,
84 icon: None,
85 install_params: None,
86 integration_types_config: None,
87 interactions_endpoint_url: None,
88 role_connections_verification_url: None,
89 tags: None,
90 },
91 http,
92 }
93 }
94
95 pub const fn cover_image(mut self, cover_image: Option<&'a str>) -> Self {
97 self.fields.cover_image = Some(Nullable(cover_image));
98
99 self
100 }
101
102 pub const fn custom_install_url(mut self, custom_install_url: &'a str) -> Self {
104 self.fields.custom_install_url = Some(custom_install_url);
105
106 self
107 }
108
109 pub const fn description(mut self, description: &'a str) -> Self {
111 self.fields.description = Some(description);
112
113 self
114 }
115
116 pub const fn flags(mut self, flags: ApplicationFlags) -> Self {
120 self.fields.flags = Some(flags);
121
122 self
123 }
124
125 pub const fn icon(mut self, icon: Option<&'a str>) -> Self {
127 self.fields.icon = Some(Nullable(icon));
128
129 self
130 }
131
132 pub fn install_params(mut self, install_params: InstallParams) -> Self {
134 self.fields.install_params = Some(install_params);
135
136 self
137 }
138
139 pub fn integrations_types_config(
140 mut self,
141 guild: Option<InstallParams>,
142 user: Option<InstallParams>,
143 ) -> Self {
144 let guild = guild.map(|g| ApplicationIntegrationTypeConfig {
145 oauth2_install_params: Some(g),
146 });
147
148 let user = user.map(|u| ApplicationIntegrationTypeConfig {
149 oauth2_install_params: Some(u),
150 });
151
152 self.fields.integration_types_config = Some(ApplicationIntegrationMap { guild, user });
153
154 self
155 }
156
157 pub const fn interactions_endpoint_url(mut self, interactions_endpoint_url: &'a str) -> Self {
159 self.fields.interactions_endpoint_url = Some(interactions_endpoint_url);
160
161 self
162 }
163
164 pub const fn role_connections_verification_url(
166 mut self,
167 role_connections_verification_url: &'a str,
168 ) -> Self {
169 self.fields.role_connections_verification_url = Some(role_connections_verification_url);
170
171 self
172 }
173
174 pub fn tags(mut self, tags: Vec<&'a str>) -> Self {
176 self.fields.tags = Some(tags);
177
178 self
179 }
180}
181
182#[cfg(not(target_os = "wasi"))]
183#[cfg(not(target_os = "wasi"))]
184impl IntoFuture for UpdateCurrentUserApplication<'_> {
185 type Output = Result<Response<Application>, Error>;
186
187 type IntoFuture = ResponseFuture<Application>;
188
189 fn into_future(self) -> Self::IntoFuture {
190 let http = self.http;
191
192 match self.try_into_request() {
193 Ok(request) => http.request(request),
194 Err(source) => ResponseFuture::error(source),
195 }
196 }
197}
198
199impl TryIntoRequest for UpdateCurrentUserApplication<'_> {
200 fn try_into_request(self) -> Result<Request, Error> {
201 let mut request = Request::builder(&Route::UpdateCurrentUserApplication);
202
203 request = request.json(&self.fields);
204
205 request.build()
206 }
207}