-
-
Notifications
You must be signed in to change notification settings - Fork 148
feat(model, cache): Add support for application editing and new application fields #2284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
suneettipirneni
merged 11 commits into
twilight-rs:main
from
suneettipirneni:feat/application-edit
Dec 30, 2023
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
323eeb3
update application struct
suneettipirneni b96b1a6
feat(http): add support for editing applications
suneettipirneni 84100b5
fix tests
suneettipirneni e0adaf3
make requested changes
suneettipirneni e176e69
Merge branch 'main' into feat/application-edit
suneettipirneni 642df21
update doc comment
suneettipirneni 41cc5c2
make the rest of the requested changes
suneettipirneni ff1bbf4
Merge branch 'main' of https://github.com/twilight-rs/twilight into f…
suneettipirneni 7dbaf71
fix doc formatting
suneettipirneni 5e5ad4f
Merge branch 'main' of https://github.com/twilight-rs/twilight into f…
suneettipirneni 10c34b3
Merge branch 'main' of https://github.com/twilight-rs/twilight into f…
suneettipirneni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| use std::future::IntoFuture; | ||
|
|
||
| use serde::Serialize; | ||
| use twilight_model::oauth::{Application, ApplicationFlags, InstallParams}; | ||
|
|
||
| use crate::{ | ||
| client::Client, | ||
| error::Error, | ||
| request::{Nullable, Request, TryIntoRequest}, | ||
| response::{Response, ResponseFuture}, | ||
| routing::Route, | ||
| }; | ||
|
|
||
| #[derive(Serialize)] | ||
| struct UpdateCurrentUserApplicationFields<'a> { | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| cover_image: Option<Nullable<&'a str>>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| custom_install_url: Option<&'a str>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| description: Option<&'a str>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| flags: Option<ApplicationFlags>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| icon: Option<Nullable<&'a str>>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| install_params: Option<InstallParams>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| interactions_endpoint_url: Option<&'a str>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| role_connections_verification_url: Option<&'a str>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| tags: Option<Vec<&'a str>>, | ||
| } | ||
|
|
||
| /// Update the current user's application. | ||
| /// | ||
| /// Returns the newly updated application. | ||
| /// | ||
| /// Refer to [Discord Docs/Update Current User Application][1]. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ```no_run | ||
| /// # #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
| /// use std::env; | ||
| /// use twilight_http::Client; | ||
| /// | ||
| /// let bearer_token = env::var("BEARER_TOKEN")?; | ||
| /// | ||
| /// let client = Client::new(bearer_token); | ||
| /// let response = client | ||
| /// .update_current_user_application() | ||
| /// .description("My cool application") | ||
| /// .await?; | ||
| /// let application = response.model().await?; | ||
| /// | ||
| /// println!("Application: {}", application.description); | ||
| /// | ||
| /// # Ok(()) } | ||
| /// ``` | ||
| /// | ||
| /// [1]: https://discord.com/developers/docs/resources/application#edit-current-application | ||
| #[must_use = "requests must be configured and executed"] | ||
| pub struct UpdateCurrentUserApplication<'a> { | ||
| fields: UpdateCurrentUserApplicationFields<'a>, | ||
| http: &'a Client, | ||
| } | ||
suneettipirneni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| impl<'a> UpdateCurrentUserApplication<'a> { | ||
| pub(crate) const fn new(http: &'a Client) -> Self { | ||
| Self { | ||
| fields: UpdateCurrentUserApplicationFields { | ||
| cover_image: None, | ||
| custom_install_url: None, | ||
| description: None, | ||
| flags: None, | ||
| icon: None, | ||
| install_params: None, | ||
| interactions_endpoint_url: None, | ||
| role_connections_verification_url: None, | ||
| tags: None, | ||
| }, | ||
| http, | ||
| } | ||
| } | ||
|
|
||
| /// Sets the cover image of the application. | ||
| pub const fn cover_image(mut self, cover_image: Option<&'a str>) -> Self { | ||
| self.fields.cover_image = Some(Nullable(cover_image)); | ||
|
|
||
| self | ||
| } | ||
|
|
||
| /// Sets the custom install URL of the application. | ||
| pub const fn custom_install_url(mut self, custom_install_url: &'a str) -> Self { | ||
| self.fields.custom_install_url = Some(custom_install_url); | ||
|
|
||
| self | ||
| } | ||
|
|
||
| /// Sets the description of the application. | ||
| pub const fn description(mut self, description: &'a str) -> Self { | ||
| self.fields.description = Some(description); | ||
|
|
||
| self | ||
| } | ||
|
|
||
| /// Sets the flags of the application. | ||
| /// Only limited intent flags (`GATEWAY_PRESENCE_LIMITED`, `GATEWAY_GUILD_MEMBERS_LIMITED`, | ||
| /// and `GATEWAY_MESSAGE_CONTENT_LIMITED`) can be updated via the API. | ||
| pub const fn flags(mut self, flags: ApplicationFlags) -> Self { | ||
| self.fields.flags = Some(flags); | ||
|
|
||
| self | ||
| } | ||
|
|
||
| /// Sets the icon of the application. | ||
| pub const fn icon(mut self, icon: Option<&'a str>) -> Self { | ||
| self.fields.icon = Some(Nullable(icon)); | ||
|
|
||
| self | ||
| } | ||
|
|
||
| /// Sets the install params of the application. | ||
| pub fn install_params(mut self, install_params: InstallParams) -> Self { | ||
| self.fields.install_params = Some(install_params); | ||
|
|
||
| self | ||
| } | ||
|
|
||
| /// Sets the interactions endpoint URL of the application. | ||
| pub const fn interactions_endpoint_url(mut self, interactions_endpoint_url: &'a str) -> Self { | ||
| self.fields.interactions_endpoint_url = Some(interactions_endpoint_url); | ||
|
|
||
| self | ||
| } | ||
|
|
||
| /// Sets the role connections verification URL of the application. | ||
| pub const fn role_connections_verification_url( | ||
| mut self, | ||
| role_connections_verification_url: &'a str, | ||
| ) -> Self { | ||
| self.fields.role_connections_verification_url = Some(role_connections_verification_url); | ||
|
|
||
| self | ||
| } | ||
|
|
||
| /// Sets the tags of the application. | ||
| pub fn tags(mut self, tags: Vec<&'a str>) -> Self { | ||
| self.fields.tags = Some(tags); | ||
|
|
||
| self | ||
| } | ||
| } | ||
|
|
||
| impl IntoFuture for UpdateCurrentUserApplication<'_> { | ||
| type Output = Result<Response<Application>, Error>; | ||
|
|
||
| type IntoFuture = ResponseFuture<Application>; | ||
|
|
||
| fn into_future(self) -> Self::IntoFuture { | ||
| let http = self.http; | ||
|
|
||
| match self.try_into_request() { | ||
| Ok(request) => http.request(request), | ||
| Err(source) => ResponseFuture::error(source), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl TryIntoRequest for UpdateCurrentUserApplication<'_> { | ||
| fn try_into_request(self) -> Result<Request, Error> { | ||
| let mut request = Request::builder(&Route::UpdateCurrentUserApplication); | ||
|
|
||
| request = request.json(&self.fields)?; | ||
|
|
||
| Ok(request.build()) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.