itchio_api/
credentials_info.rs1use chrono::{DateTime, Utc};
2use serde::Deserialize;
3
4use crate::{Itchio, ItchioError};
5
6#[derive(Clone, Debug, Deserialize)] #[allow(dead_code)]
7pub struct Info {
8 r#type: Option<String>,
9 scopes: Option<Vec<String>>,
10 expires_at: Option<DateTime<Utc>>,
11}
12
13impl Itchio {
14 pub async fn get_credentials_info(&self) -> Result<Info, ItchioError> {
16 Ok(self.request::<Info>("credentials/info".to_string()).await?)
17 }
18}
19
20#[cfg(test)]
21mod tests {
22 use super::*;
23 use std::env;
24 use dotenv::dotenv;
25
26 #[tokio::test]
27 async fn good() {
28 dotenv().ok();
29 let client_secret = env::var("KEY").expect("KEY has to be set");
30 let api = Itchio::new(client_secret);
31 let credentials = api.get_credentials_info().await.inspect_err(|err| eprintln!("Error spotted: {}", err));
32 assert!(credentials.is_ok())
33 }
34
35 #[tokio::test]
36 async fn bad_key() {
37 let api = Itchio::new("bad_key".to_string());
38 let credentials = api.get_credentials_info().await;
39 assert!(credentials.is_err_and(|err| matches!(err, ItchioError::BadKey)))
40 }
41}