matrix-sdk: Add Client::whoami()

master
Johannes Becker 2021-06-11 09:37:30 +02:00
parent df42ef68a2
commit ba0cc3d45f
2 changed files with 28 additions and 1 deletions

View File

@ -100,7 +100,7 @@ use ruma::{
api::{
client::{
r0::{
account::register,
account::{register, whoami},
device::{delete_devices, get_devices},
directory::{get_public_rooms, get_public_rooms_filtered},
filter::{create_filter::Request as FilterUploadRequest, FilterDefinition},
@ -2686,6 +2686,12 @@ impl Client {
Ok(())
}
/// Gets information about the owner of a given access token.
pub async fn whoami(&self) -> Result<whoami::Response> {
let request = whoami::Request::new();
self.send(request, None).await
}
}
#[cfg(test)]
@ -3862,4 +3868,19 @@ mod test {
.is_ok());
m.assert();
}
#[tokio::test]
async fn whoami() {
let client = logged_in_client().await;
let _m = mock("GET", "/_matrix/client/r0/account/whoami")
.with_status(200)
.with_body(test_json::WHOAMI.to_string())
.match_header("authorization", "Bearer 1234")
.create();
let user_id = user_id!("@joe:example.org");
assert_eq!(client.whoami().await.unwrap().user_id, user_id);
}
}

View File

@ -68,3 +68,9 @@ lazy_static! {
}
});
}
lazy_static! {
pub static ref WHOAMI: JsonValue = json!({
"user_id": "@joe:example.org"
});
}