-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for application role connections metadata get/set operations
- Loading branch information
Showing
11 changed files
with
271 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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,44 @@ | ||
use crate::{ | ||
request::application::role_connections::{GetMetadata, SetMetadata}, | ||
Client, | ||
}; | ||
use twilight_model::{ | ||
application::role_connection::Metadata, | ||
id::{marker::ApplicationMarker, Id}, | ||
}; | ||
|
||
/// Client interface for application role connections. | ||
#[derive(Debug)] | ||
pub struct RoleConnectionsClient<'a> { | ||
application_id: Id<ApplicationMarker>, | ||
client: &'a Client, | ||
} | ||
|
||
impl<'a> RoleConnectionsClient<'a> { | ||
/// Create a new interface for using interactions. | ||
pub(super) const fn new(client: &'a Client, application_id: Id<ApplicationMarker>) -> Self { | ||
Self { | ||
application_id, | ||
client, | ||
} | ||
} | ||
|
||
/// Get application role connections metadata. | ||
pub const fn metadata(&'a self) -> GetMetadata<'a> { | ||
GetMetadata::new(self.client, self.application_id) | ||
} | ||
|
||
/// Set the application role connections metadata. | ||
pub const fn set_metadata(&'a self, records: &'a [Metadata]) -> SetMetadata<'a> { | ||
SetMetadata::new(self.client, self.application_id, records) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::RoleConnectionsClient; | ||
use static_assertions::assert_impl_all; | ||
use std::fmt::Debug; | ||
|
||
assert_impl_all!(RoleConnectionsClient<'_>: Debug, Send, Sync); | ||
} |
This file contains 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod command; | ||
pub mod interaction; | ||
pub mod role_connections; |
60 changes: 60 additions & 0 deletions
60
twilight-http/src/request/application/role_connections/get_metadata.rs
This file contains 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,60 @@ | ||
use crate::{ | ||
client::Client, | ||
error::Error, | ||
request::{Request, TryIntoRequest}, | ||
response::{marker::ListBody, Response, ResponseFuture}, | ||
routing::Route, | ||
}; | ||
use std::future::IntoFuture; | ||
use twilight_model::{ | ||
application::role_connection::Metadata, | ||
id::{marker::ApplicationMarker, Id}, | ||
}; | ||
|
||
/// Get Application Role Connection Metadata Records. | ||
#[must_use = "requests must be configured and executed"] | ||
pub struct GetMetadata<'a> { | ||
application_id: Id<ApplicationMarker>, | ||
http: &'a Client, | ||
} | ||
|
||
impl<'a> GetMetadata<'a> { | ||
pub(crate) const fn new(http: &'a Client, application_id: Id<ApplicationMarker>) -> Self { | ||
Self { | ||
application_id, | ||
http, | ||
} | ||
} | ||
|
||
/// Execute the request, returning a future resolving to a [`Response`]. | ||
#[deprecated(since = "0.14.0", note = "use `.await` or `into_future` instead")] | ||
pub fn exec(self) -> ResponseFuture<ListBody<Metadata>> { | ||
self.into_future() | ||
} | ||
} | ||
|
||
impl IntoFuture for GetMetadata<'_> { | ||
type Output = Result<Response<ListBody<Metadata>>, Error>; | ||
|
||
type IntoFuture = ResponseFuture<ListBody<Metadata>>; | ||
|
||
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 GetMetadata<'_> { | ||
fn try_into_request(self) -> Result<Request, Error> { | ||
Ok( | ||
Request::builder(&Route::GetApplicationRoleConnectionMetadataRecords { | ||
application_id: self.application_id.get(), | ||
}) | ||
.build(), | ||
) | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
twilight-http/src/request/application/role_connections/mod.rs
This file contains 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,4 @@ | ||
mod get_metadata; | ||
mod set_metadata; | ||
|
||
pub use self::{get_metadata::GetMetadata, set_metadata::SetMetadata}; |
65 changes: 65 additions & 0 deletions
65
twilight-http/src/request/application/role_connections/set_metadata.rs
This file contains 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,65 @@ | ||
use crate::{ | ||
client::Client, | ||
error::Error, | ||
request::{Request, RequestBuilder, TryIntoRequest}, | ||
response::{marker::ListBody, Response, ResponseFuture}, | ||
routing::Route, | ||
}; | ||
use std::future::IntoFuture; | ||
use twilight_model::{ | ||
application::role_connection::Metadata, | ||
id::{marker::ApplicationMarker, Id}, | ||
}; | ||
|
||
/// Set a user's linked roles metadata for the given application. | ||
#[must_use = "requests must be configured and executed"] | ||
pub struct SetMetadata<'a> { | ||
application_id: Id<ApplicationMarker>, | ||
http: &'a Client, | ||
records: &'a [Metadata], | ||
} | ||
|
||
impl<'a> SetMetadata<'a> { | ||
pub(crate) const fn new( | ||
http: &'a Client, | ||
application_id: Id<ApplicationMarker>, | ||
records: &'a [Metadata], | ||
) -> Self { | ||
Self { | ||
application_id, | ||
http, | ||
records, | ||
} | ||
} | ||
|
||
/// Execute the request, returning a future resolving to a [`Response`]. | ||
#[deprecated(since = "0.14.0", note = "use `.await` or `into_future` instead")] | ||
pub fn exec(self) -> ResponseFuture<ListBody<Metadata>> { | ||
self.into_future() | ||
} | ||
} | ||
|
||
impl IntoFuture for SetMetadata<'_> { | ||
type Output = Result<Response<ListBody<Metadata>>, Error>; | ||
|
||
type IntoFuture = ResponseFuture<ListBody<Metadata>>; | ||
|
||
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 SetMetadata<'_> { | ||
fn try_into_request(self) -> Result<Request, Error> { | ||
Request::builder(&Route::SetApplicationRoleConnectionMetadataRecords { | ||
application_id: self.application_id.get(), | ||
}) | ||
.json(&self.records) | ||
.map(RequestBuilder::build) | ||
} | ||
} |
This file contains 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 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 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod command; | ||
pub mod interaction; | ||
pub mod role_connection; |
This file contains 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,54 @@ | ||
//! Application role connections models. | ||
|
||
use std::collections::HashMap; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
use serde_repr::{Deserialize_repr, Serialize_repr}; | ||
|
||
/// Application Role Connection Metadata Type. | ||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize_repr, Serialize_repr)] | ||
#[repr(u8)] | ||
pub enum MetadataType { | ||
/// the metadata value (integer) is less than or equal to the guild's | ||
/// configured value (integer) | ||
IntegerLessThanOrEqual = 1, | ||
/// the metadata value (integer) is greater than or equal to the guild's | ||
/// configured value (integer) | ||
IntegerGreaterThanOrEqual = 2, | ||
/// the metadata value (integer) is equal to the guild's configured value | ||
/// (integer) | ||
IntegerEqual = 3, | ||
/// the metadata value (integer) is not equal to the guild's configured | ||
/// value (integer) | ||
IntegerNotEqual = 4, | ||
/// the metadata value (ISO8601 string) is less than or equal to | ||
/// the guild's configured value (integer; days before current date) | ||
DatetimeLessThanOrEqual = 5, | ||
/// the metadata value (ISO8601 string) is greater than or equal to | ||
/// the guild's configured value (integer; days before current date) | ||
DatetimeGreaterThanOrEqual = 6, | ||
/// the metadata value (integer) is equal to the guild's configured value | ||
/// (integer; 1) | ||
BooleanEqual = 7, | ||
/// the metadata value (integer) is not equal to the guild's configured | ||
/// value (integer; 1) | ||
BooleanNotEqual = 8, | ||
} | ||
|
||
/// Application Role Connection Metadata Structure. | ||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] | ||
pub struct Metadata { | ||
/// type of metadata value | ||
pub r#type: MetadataType, | ||
/// dictionary key for the metadata field | ||
/// (must be a-z, 0-9, or _ characters; max 50 characters) | ||
pub key: String, | ||
/// name of the metadata field (max 100 characters) | ||
pub name: String, | ||
/// translations of the name | ||
pub name_localizations: HashMap<String, String>, | ||
/// description of the metadata field (max 200 characters) | ||
pub description: String, | ||
/// translations of the description | ||
pub description_localizations: HashMap<String, String>, | ||
} |