#![cfg(feature = "cloudflare_resources")]
#![allow(clippy::too_many_arguments, clippy::type_complexity)]
#![allow(clippy::missing_errors_doc, clippy::doc_markdown, clippy::useless_format)]
#![allow(unused_imports)]
use foundation_netio::{DynNetClient, PreparedRequestBuilder};
use foundation_netio::shared::client::http_client::HttpClient;
use serde::{Deserialize, Serialize};
use foundation_macros::JsonHash;
use super::shared::ApiResponse;
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaApiResponseCommon {
pub errors: Vec<std::collections::HashMap<String, serde_json::Value>>,
pub messages: Vec<std::collections::HashMap<String, serde_json::Value>>,
pub success: bool,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaCategories {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaCategory {
pub created_at: AlexandriaCategoryCreatedAt,
pub description: AlexandriaCategoryDescription,
pub id: AlexandriaCategoryId,
pub name: AlexandriaCategoryName,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaCategoryCreatedAt {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaCategoryDescription {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaCategoryId {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaCategoryName {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaGetCategoriesResponse {
pub result: Option<Vec<AlexandriaCategory>>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaGetCategoryResponse {
pub result: Option<AlexandriaCategory>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaMessages {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct GetCategoriesArgs {
pub account_id: String,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct GetCategoryByIdArgs {
pub account_id: String,
pub id: String,
}
pub async fn get_categories_request<F>(
client: DynNetClient,
args: &GetCategoriesArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<AlexandriaGetCategoriesResponse>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/accounts/{}/resource-library/categories",
args.account_id,
);
let endpoint_url = format!("{}{}", base_url, path);
let mut builder = PreparedRequestBuilder::get(&endpoint_url)
.map_err(|e| super::shared::ApiError::RequestBuildFailed(e.to_string()))?;
if let Some(f) = builder_mod {
f(&mut builder);
}
let response = client.send_async(builder.build()).await
.map_err(|e| super::shared::ApiError::RequestSendFailed(e.to_string()))?;
let status: usize = response.get_status().into();
let headers = response.get_headers_ref().clone();
if status < 200 || status >= 300 {
let error_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
let body = (!error_bytes.is_empty())
.then(|| String::from_utf8_lossy(&error_bytes).into_owned());
return Err(super::shared::ApiError::HttpStatus { code: status as u16, headers, body });
}
let body_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
let parsed: AlexandriaGetCategoriesResponse = serde_json::from_slice(&body_bytes).map_err(|e: serde_json::Error| super::shared::ApiError::ParseFailed(e.to_string()))?;
Ok(ApiResponse { status: status as u16, headers, body: parsed })
}
pub async fn get_category_by_id_request<F>(
client: DynNetClient,
args: &GetCategoryByIdArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<AlexandriaGetCategoryResponse>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/accounts/{}/resource-library/categories/{}",
args.account_id,
args.id,
);
let endpoint_url = format!("{}{}", base_url, path);
let mut builder = PreparedRequestBuilder::get(&endpoint_url)
.map_err(|e| super::shared::ApiError::RequestBuildFailed(e.to_string()))?;
if let Some(f) = builder_mod {
f(&mut builder);
}
let response = client.send_async(builder.build()).await
.map_err(|e| super::shared::ApiError::RequestSendFailed(e.to_string()))?;
let status: usize = response.get_status().into();
let headers = response.get_headers_ref().clone();
if status < 200 || status >= 300 {
let error_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
let body = (!error_bytes.is_empty())
.then(|| String::from_utf8_lossy(&error_bytes).into_owned());
return Err(super::shared::ApiError::HttpStatus { code: status as u16, headers, body });
}
let body_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
let parsed: AlexandriaGetCategoryResponse = serde_json::from_slice(&body_bytes).map_err(|e: serde_json::Error| super::shared::ApiError::ParseFailed(e.to_string()))?;
Ok(ApiResponse { status: status as u16, headers, body: parsed })
}