zai_rs/model/voice_list/
data.rs1use super::request::VoiceListQuery;
2use crate::client::http::HttpClient;
3use url::Url;
4
5pub struct VoiceListRequest {
7 pub key: String,
8 url: String,
9 _body: (),
11}
12
13impl VoiceListRequest {
14 pub fn new(key: String) -> Self {
15 let url = "https://open.bigmodel.cn/api/paas/v4/voice/list".to_string();
16 Self {
17 key,
18 url,
19 _body: (),
20 }
21 }
22
23 fn rebuild_url(&mut self, q: &VoiceListQuery) {
24 let mut url = Url::parse("https://open.bigmodel.cn/api/paas/v4/voice/list").unwrap();
25 {
26 let mut pairs = url.query_pairs_mut();
27 if let Some(ref n) = q.voice_name {
28 pairs.append_pair("voiceName", n);
29 }
30 if let Some(ref t) = q.voice_type {
31 pairs.append_pair("voiceType", t.as_str());
32 }
33 }
34 self.url = url.to_string();
35 }
36
37 pub fn validate(&self) -> anyhow::Result<()> {
38 Ok(())
40 }
41
42 pub async fn send(&self) -> anyhow::Result<super::response::VoiceListResponse> {
43 self.validate()?;
44 let resp = self.get().await?;
45 let parsed = resp.json::<super::response::VoiceListResponse>().await?;
46 Ok(parsed)
47 }
48
49 pub fn with_query(mut self, q: VoiceListQuery) -> Self {
50 self.rebuild_url(&q);
51 self
52 }
53}
54
55impl HttpClient for VoiceListRequest {
56 type Body = ();
57 type ApiUrl = String;
58 type ApiKey = String;
59
60 fn api_url(&self) -> &Self::ApiUrl {
61 &self.url
62 }
63 fn api_key(&self) -> &Self::ApiKey {
64 &self.key
65 }
66 fn body(&self) -> &Self::Body {
67 &self._body
68 }
69}