zai-rs 0.1.15

一个 Rust SDK, 用于调用 智普AI API
Documentation
use validator::Validate;

use super::request::VoiceDeleteBody;
use crate::client::http::HttpClient;

/// Voice delete request using JSON body
pub struct VoiceDeleteRequest {
    pub key: String,
    body: VoiceDeleteBody,
}

impl VoiceDeleteRequest {
    pub fn new(key: String, voice: impl Into<String>) -> Self {
        let body = VoiceDeleteBody::new(voice);
        Self { key, body }
    }

    pub fn with_request_id(mut self, request_id: impl Into<String>) -> Self {
        self.body = self.body.with_request_id(request_id);
        self
    }

    pub fn validate(&self) -> crate::ZaiResult<()> {
        self.body
            .validate()
            .map_err(|e| crate::client::error::ZaiError::ApiError {
                code: 1200,
                message: format!("Validation error: {:?}", e),
            })?;
        Ok(())
    }

    pub async fn send(&self) -> crate::ZaiResult<super::response::VoiceDeleteResponse> {
        self.validate()?;
        let resp = self.post().await?;
        let parsed = resp.json::<super::response::VoiceDeleteResponse>().await?;
        Ok(parsed)
    }
}

impl HttpClient for VoiceDeleteRequest {
    type Body = VoiceDeleteBody;
    type ApiUrl = &'static str;
    type ApiKey = String;

    fn api_url(&self) -> &Self::ApiUrl {
        &"https://open.bigmodel.cn/api/paas/v4/voice/delete"
    }
    fn api_key(&self) -> &Self::ApiKey {
        &self.key
    }
    fn body(&self) -> &Self::Body {
        &self.body
    }
}