use crate::{ApiResult, Error, FakeYou};
use reqwest::StatusCode;
use serde::{Deserialize, Serialize};
use super::TTS_VOICES;
#[derive(Debug, Serialize, Deserialize)]
pub struct TtsListResult {
pub success: bool,
pub models: Vec<TtsModel>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct TtsModel {
pub model_token: String,
pub tts_model_type: String,
pub creator_user_token: String,
pub creator_username: String,
pub creator_display_name: String,
pub creator_gravatar_hash: String,
pub title: String,
pub ietf_language_tag: String,
pub ietf_primary_language_subtag: String,
pub is_front_page_featured: bool,
pub is_twitch_featured: bool,
pub maybe_suggested_unique_bot_command: Option<String>,
pub category_tokens: Vec<String>,
pub created_at: String,
pub updated_at: String,
}
pub trait VoicesApi {
fn tts_voices(&self) -> ApiResult<TtsListResult>;
}
impl VoicesApi for FakeYou {
fn tts_voices(&self) -> ApiResult<TtsListResult> {
let url = format!("{}/{}", &self.api_url, TTS_VOICES);
let response = self
.client
.get(url.as_str())
.header("Accept", "application/json")
.send()
.map_err(|e| Error::RequestFailed(e.to_string()))?;
match response.status() {
StatusCode::OK => response
.json::<TtsListResult>()
.map_err(|e| Error::ParseError(e.to_string())),
code => Err(Error::Unknown(code.as_u16())),
}
}
}