akahu_client/client/me.rs
1//! User profile endpoint implementations.
2//!
3//! This module contains methods for retrieving authenticated user information.
4
5use crate::{ItemResponse, User, UserToken};
6
7use super::AkahuClient;
8use reqwest::Method;
9
10impl AkahuClient {
11 /// Get the authenticated user's profile information.
12 ///
13 /// This endpoint retrieves information about the user who authorized your application,
14 /// including their unique identifier and basic profile data. The visibility of certain
15 /// fields depends on the permissions granted to your application.
16 ///
17 /// # Arguments
18 ///
19 /// * `user_token` - The user's access token obtained through OAuth
20 ///
21 /// # Returns
22 ///
23 /// The user's profile information, including:
24 /// - User ID
25 /// - Account creation timestamp
26 /// - First name (if available)
27 /// - Last name (if available)
28 /// - Email address (requires `AKAHU` scope)
29 /// - Access granted timestamp (when the user authorized your app)
30 ///
31 /// # Scopes
32 ///
33 /// This endpoint requires user-scoped authentication. The `AKAHU` scope is needed
34 /// to access the user's email address and other profile information.
35 ///
36 /// [<https://developers.akahu.nz/reference/get_me>]
37 pub async fn get_me(
38 &self,
39 user_token: &UserToken,
40 ) -> crate::error::AkahuResult<crate::models::User> {
41 const URI: &str = "me";
42
43 let headers = self.build_user_headers(user_token)?;
44
45 let req = self
46 .client
47 .request(Method::GET, format!("{}/{}", self.base_url, URI))
48 .headers(headers)
49 .build()?;
50
51 let user_response: ItemResponse<User> = self.execute_request(req).await?;
52
53 Ok(user_response.item)
54 }
55}