use crate::client::ZtkClient;
use crate::common::http::build_params_with_appkey;
use crate::error::ZtkResult;
use super::request::{
KaolaConvertRequest, KaolaGoodsDetailRequest, KaolaGoodsListRequest, KaolaOrderQueryRequest,
KaolaSearchGoodsRequest,
};
use super::response::{
KaolaConvertResponse, KaolaGoodsDetailResponse, KaolaGoodsListResponse, KaolaOrderResponse,
KaolaSearchGoodsResponse,
};
pub struct KaolaApi<'a> {
client: &'a ZtkClient,
}
impl<'a> KaolaApi<'a> {
pub fn new(client: &'a ZtkClient) -> Self {
Self { client }
}
#[allow(dead_code)]
pub(crate) fn client(&self) -> &ZtkClient {
self.client
}
pub async fn convert(&self, request: KaolaConvertRequest) -> ZtkResult<KaolaConvertResponse> {
let params = build_params_with_appkey(self.client.appkey(), &request)?;
self.client
.http_client()
.get("/api/open_kaola_zhuanke_api_zhuanlian.ashx", ¶ms)
.await
}
pub async fn goods_list(
&self,
request: KaolaGoodsListRequest,
) -> ZtkResult<KaolaGoodsListResponse> {
let params = build_params_with_appkey(self.client.appkey(), &request)?;
self.client
.http_client()
.get(
"/api/open_kaola_zhuanke_api_querySelectedGoods.ashx",
¶ms,
)
.await
}
pub async fn search_goods(
&self,
request: KaolaSearchGoodsRequest,
) -> ZtkResult<KaolaSearchGoodsResponse> {
let params = build_params_with_appkey(self.client.appkey(), &request)?;
self.client
.http_client()
.get("/api/open_kaola_zhuanke_api_searchGoods.ashx", ¶ms)
.await
}
pub async fn goods_detail(
&self,
request: KaolaGoodsDetailRequest,
) -> ZtkResult<KaolaGoodsDetailResponse> {
let params = build_params_with_appkey(self.client.appkey(), &request)?;
self.client
.http_client()
.get("/api/open_kaola_zhuanke_api_queryGoodsInfo.ashx", ¶ms)
.await
}
pub async fn query_orders(
&self,
request: KaolaOrderQueryRequest,
) -> ZtkResult<KaolaOrderResponse> {
let params = build_params_with_appkey(self.client.appkey(), &request)?;
self.client
.http_client()
.get("/api/open_lianmeng_orderList.ashx", ¶ms)
.await
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_kaola_api_creation() {
let client = ZtkClient::new("test_appkey").build().unwrap();
let kaola = client.kaola();
assert_eq!(kaola.client().appkey(), "test_appkey");
}
}