tinyhumans 0.1.0

Rust SDK for the TinyHumans backend
Documentation
//! Personal invite codes, redemption, and status checks.

use reqwest::Method;

use super::types::{CodeRequest, DynamicResponse};
use crate::{Error, HttpClient, QueryParam};

/// Typed client for the `/invite/*` routes.
pub struct InviteApi<'a> {
    http: &'a HttpClient,
}

impl<'a> InviteApi<'a> {
    pub fn new(http: &'a HttpClient) -> Self {
        Self { http }
    }

    /// List the current user's invite codes with usage info.
    pub async fn list_my_codes(&self) -> Result<DynamicResponse, Error> {
        self.http
            .send_typed(Method::GET, "/invite/my-codes", &[], None, true)
            .await
    }

    /// Redeem an invite code.
    pub async fn redeem_invite(&self, request: &CodeRequest) -> Result<DynamicResponse, Error> {
        let body = serde_json::to_value(request).expect("invite request is serializable");
        self.http
            .send_typed(Method::POST, "/invite/redeem", &[], Some(&body), true)
            .await
    }

    /// Check if an invite code is valid and available.
    pub async fn get_invite_status(&self, query: &[QueryParam]) -> Result<DynamicResponse, Error> {
        self.http
            .send_typed(Method::GET, "/invite/status", query, None, true)
            .await
    }
}