itchio-api 0.3.0

Easily interact with the itch.io server-side API
Documentation
use serde::Deserialize;

use crate::{Itchio, ItchioError};

/// A representation of the status of the wharf infrastructure.
#[derive(Clone, Debug, Deserialize)]
pub struct WharfStatus {
  pub success: bool
}

impl Itchio {
  /// Request the status of the wharf infrastructure.
  pub async fn get_wharf_status(&self) -> Result<WharfStatus, ItchioError> {
    Ok(self.request::<WharfStatus>("wharf/status".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 wharf = api.get_wharf_status().await.inspect_err(|err| eprintln!("Error spotted: {}", err));
    assert!(wharf.is_ok())
  }

  #[tokio::test]
  async fn bad_key() {
    let api = Itchio::new("bad_key".to_string()).unwrap();
    let wharf = api.get_wharf_status().await;
    assert!(wharf.is_err_and(|err| matches!(err, ItchioError::BadKey)))
  }
}