rippling_base_api/
current_user.rs1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct CurrentUser {
6 pub client: Client,
7}
8
9impl CurrentUser {
10 #[doc(hidden)]
11 pub fn new(client: Client) -> Self {
12 Self { client }
13 }
14
15 #[doc = "GCurrent User\n\nRetrieves basic information about the Rippling user whose access \
16 token you're using. This is generally used for the SSO flow.\n\n```rust,no_run\nasync \
17 fn example_current_user_get_me() -> anyhow::Result<()> {\n let client = \
18 rippling_base_api::Client::new_from_env();\n let result: \
19 rippling_base_api::types::AuthenticatedUserMe = \
20 client.current_user().get_me().await?;\n println!(\"{:?}\", result);\n \
21 Ok(())\n}\n```"]
22 #[tracing::instrument]
23 pub async fn get_me<'a>(
24 &'a self,
25 ) -> Result<crate::types::AuthenticatedUserMe, crate::types::error::Error> {
26 let mut req = self.client.client.request(
27 http::Method::GET,
28 &format!("{}/{}", self.client.base_url, "platform/api/me"),
29 );
30 req = req.bearer_auth(&self.client.token);
31 let resp = req.send().await?;
32 let status = resp.status();
33 if status.is_success() {
34 let text = resp.text().await.unwrap_or_default();
35 serde_json::from_str(&text).map_err(|err| {
36 crate::types::error::Error::from_serde_error(
37 format_serde_error::SerdeError::new(text.to_string(), err),
38 status,
39 )
40 })
41 } else {
42 let text = resp.text().await.unwrap_or_default();
43 return Err(crate::types::error::Error::Server {
44 body: text.to_string(),
45 status,
46 });
47 }
48 }
49}