Skip to main content

itchio_api/
me.rs

1use serde::Deserialize;
2
3use crate::{Itchio, ItchioError, User};
4
5/// The original response this crate gets from the server, useless to crate users.
6#[derive(Clone, Debug, Deserialize)]
7struct WrappedUser {
8  user: User
9}
10
11impl Itchio {
12  /// Get your profile: <https://itch.io/docs/api/serverside#reference/profileme-httpsitchioapi1keyme>
13  pub async fn get_me(&self) -> Result<User, ItchioError> {
14    let response = self.request::<WrappedUser>("me".to_string()).await?;
15    Ok(response.user)
16  }
17}
18
19#[cfg(test)]
20mod tests {
21  use super::*;
22  use std::env;
23  use dotenv::dotenv;
24
25  #[tokio::test]
26  async fn good() {
27    dotenv().ok();
28    let client_secret = env::var("KEY").expect("KEY has to be set");
29    let api = Itchio::new(client_secret);
30    let me = api.get_my_games().await.inspect_err(|err| eprintln!("Error spotted: {}", err));
31    assert!(me.is_ok())
32  }
33
34  #[tokio::test]
35  async fn bad_key() {
36    let api = Itchio::new("bad_key".to_string());
37    let me = api.get_me().await;
38    assert!(me.is_err_and(|err| matches!(err, ItchioError::BadKey)))
39  }
40}