matrix-sdk: Add Client::whoami()
parent
df42ef68a2
commit
ba0cc3d45f
|
@ -100,7 +100,7 @@ use ruma::{
|
||||||
api::{
|
api::{
|
||||||
client::{
|
client::{
|
||||||
r0::{
|
r0::{
|
||||||
account::register,
|
account::{register, whoami},
|
||||||
device::{delete_devices, get_devices},
|
device::{delete_devices, get_devices},
|
||||||
directory::{get_public_rooms, get_public_rooms_filtered},
|
directory::{get_public_rooms, get_public_rooms_filtered},
|
||||||
filter::{create_filter::Request as FilterUploadRequest, FilterDefinition},
|
filter::{create_filter::Request as FilterUploadRequest, FilterDefinition},
|
||||||
|
@ -2686,6 +2686,12 @@ impl Client {
|
||||||
|
|
||||||
Ok(())
|
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)]
|
#[cfg(test)]
|
||||||
|
@ -3862,4 +3868,19 @@ mod test {
|
||||||
.is_ok());
|
.is_ok());
|
||||||
m.assert();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,3 +68,9 @@ lazy_static! {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
pub static ref WHOAMI: JsonValue = json!({
|
||||||
|
"user_id": "@joe:example.org"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue