use chrono::{DateTime, Utc};
use serde::Deserialize;
use crate::{Itchio, ItchioError};
#[derive(Clone, Debug, Deserialize)]
pub struct CredentialInfo {
pub r#type: Option<String>,
pub scopes: Option<Vec<String>>,
pub expires_at: Option<DateTime<Utc>>,
}
impl Itchio {
pub async fn get_credentials_info(&self) -> Result<CredentialInfo, ItchioError> {
Ok(self.request::<CredentialInfo>("credentials/info".to_string()).await?)
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::env;
use dotenv::dotenv;
#[tokio::test]
async fn good() {
dotenv().ok();
let client_secret = env::var("KEY").expect("KEY has to be set");
let api = Itchio::new(client_secret).unwrap();
let credentials = api.get_credentials_info().await.inspect_err(|err| eprintln!("Error spotted: {}", err));
assert!(credentials.is_ok())
}
#[tokio::test]
async fn bad_key() {
let api = Itchio::new("bad_key".to_string()).unwrap();
let credentials = api.get_credentials_info().await;
assert!(credentials.is_err_and(|err| matches!(err, ItchioError::BadKey)))
}
}