1mod error;
5pub use error::Error;
6
7pub mod prefix_list;
8
9use crate::credentials::CredentialsProvider;
10use bon::bon;
11use std::sync::Arc;
12use u_sdk_common::open_api_sign::OpenApiStyle;
13
14pub(crate) const OPENAPI_STYLE: OpenApiStyle = OpenApiStyle::RPC;
15pub(crate) const OPENAPI_VERSION: &str = "2014-05-26";
16
17pub struct Client {
18 credentials_provider: Arc<dyn CredentialsProvider>,
19 http_client: reqwest::Client,
20 host: String,
21}
22
23#[bon]
24impl Client {
25 #[builder(on(String, into))]
26 pub fn new(credentials_provider: Arc<dyn CredentialsProvider>, host: String) -> Self {
27 Self {
28 credentials_provider,
29 http_client: reqwest::Client::new(),
30 host,
31 }
32 }
33}
34
35pub(crate) async fn parse_json_response<T: serde::de::DeserializeOwned>(
36 resp: reqwest::Response,
37) -> Result<T, Error> {
38 let status = resp.status();
39
40 if !status.is_success() {
41 return Err(Error::RequestAPIFailed {
42 code: status.to_string(),
43 message: resp.text().await?,
44 });
45 }
46
47 let data = resp.json().await?;
48 Ok(data)
49}