api: Rename SendAccessToken methods to be clearer
Co-authored-by: Johannes Becker <j.becker@famedly.com>
This commit is contained in:
parent
1e005f576e
commit
12ec0fb168
@ -141,14 +141,14 @@ impl Request {
|
||||
::std::convert::TryFrom::<_>::try_from(::std::format!(
|
||||
"Bearer {}",
|
||||
access_token
|
||||
.get_required()
|
||||
.get_required_for_endpoint()
|
||||
.ok_or(#ruma_api::error::IntoHttpError::NeedsAuthentication)?,
|
||||
))?,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
if let Some(access_token) = access_token.get_optional() {
|
||||
if let Some(access_token) = access_token.get_not_required_for_endpoint() {
|
||||
#( #attrs )*
|
||||
req_headers.insert(
|
||||
#http::header::AUTHORIZATION,
|
||||
|
@ -229,25 +229,25 @@ pub enum SendAccessToken<'a> {
|
||||
}
|
||||
|
||||
impl<'a> SendAccessToken<'a> {
|
||||
/// Get the access token for an endpoint that should not require one.
|
||||
///
|
||||
/// Returns `Some(_)` only if `self` is `SendAccessToken::Always(_)`.
|
||||
pub fn get_optional(self) -> Option<&'a str> {
|
||||
match self {
|
||||
Self::Always(tok) => Some(tok),
|
||||
Self::IfRequired(_) | Self::None => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the access token for an endpoint that requires one.
|
||||
///
|
||||
/// Returns `Some(_)` if `self` contains an access token.
|
||||
pub fn get_required(self) -> Option<&'a str> {
|
||||
pub fn get_required_for_endpoint(self) -> Option<&'a str> {
|
||||
match self {
|
||||
Self::IfRequired(tok) | Self::Always(tok) => Some(tok),
|
||||
Self::None => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the access token for an endpoint that should not require one.
|
||||
///
|
||||
/// Returns `Some(_)` only if `self` is `SendAccessToken::Always(_)`.
|
||||
pub fn get_not_required_for_endpoint(self) -> Option<&'a str> {
|
||||
match self {
|
||||
Self::Always(tok) => Some(tok),
|
||||
Self::IfRequired(_) | Self::None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A request type for a Matrix API endpoint, used for sending requests.
|
||||
|
@ -97,7 +97,7 @@ impl<'a> ruma_api::OutgoingRequest for Request<'a> {
|
||||
format!(
|
||||
"Bearer {}",
|
||||
access_token
|
||||
.get_required()
|
||||
.get_required_for_endpoint()
|
||||
.ok_or(ruma_api::error::IntoHttpError::NeedsAuthentication)?,
|
||||
),
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user