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