front_api/
token_identity.rs1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct TokenIdentity {
6 pub client: Client,
7}
8
9impl TokenIdentity {
10 #[doc(hidden)]
11 pub fn new(client: Client) -> Self {
12 Self { client }
13 }
14
15 #[doc = "API Token details\n\nFetch the details of the API token.\n\n```rust,no_run\nasync fn \
16 example_token_identity_get() -> anyhow::Result<()> {\n let client = \
17 front_api::Client::new_from_env();\n let result: \
18 front_api::types::IdentityResponse = client.token_identity().get().await?;\n \
19 println!(\"{:?}\", result);\n Ok(())\n}\n```"]
20 #[tracing::instrument]
21 pub async fn get<'a>(
22 &'a self,
23 ) -> Result<crate::types::IdentityResponse, crate::types::error::Error> {
24 let mut req = self.client.client.request(
25 http::Method::GET,
26 &format!("{}/{}", self.client.base_url, "me"),
27 );
28 req = req.bearer_auth(&self.client.token);
29 let resp = req.send().await?;
30 let status = resp.status();
31 if status.is_success() {
32 let text = resp.text().await.unwrap_or_default();
33 serde_json::from_str(&text).map_err(|err| {
34 crate::types::error::Error::from_serde_error(
35 format_serde_error::SerdeError::new(text.to_string(), err),
36 status,
37 )
38 })
39 } else {
40 Err(crate::types::error::Error::UnexpectedResponse(resp))
41 }
42 }
43}