use crate::client::ZtkClient;
use crate::common::http::build_params_with_appkey;
use crate::error::ZtkResult;
use super::request::{
PddAuthorizeQueryRequest, PddAuthorizeRequest, PddConvertRequest, PddGoodsDetailFullRequest,
PddGoodsDetailSimpleRequest, PddOrderQueryRequest,
};
use super::response::{
PddAuthorizeQueryResponse, PddAuthorizeResponse, PddConvertResponse,
PddGoodsDetailFullResponse, PddGoodsDetailSimpleResponse, PddOrderResponse,
};
pub struct PddApi<'a> {
client: &'a ZtkClient,
}
impl<'a> PddApi<'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: PddConvertRequest) -> ZtkResult<PddConvertResponse> {
let params = build_params_with_appkey(self.client.appkey(), &request)?;
self.client
.http_client()
.get("/api/open_pdd_zhuanlian_new.ashx", ¶ms)
.await
}
pub async fn goods_detail_simple(
&self,
request: PddGoodsDetailSimpleRequest,
) -> ZtkResult<PddGoodsDetailSimpleResponse> {
let params = build_params_with_appkey(self.client.appkey(), &request)?;
self.client
.http_client()
.get("/api/open_pdd_goods_detail_get_new.ashx", ¶ms)
.await
}
pub async fn goods_detail_full(
&self,
request: PddGoodsDetailFullRequest,
) -> ZtkResult<PddGoodsDetailFullResponse> {
let params = build_params_with_appkey(self.client.appkey(), &request)?;
self.client
.http_client()
.get("/api/open_pdd_goods_detail_search_new.ashx", ¶ms)
.await
}
pub async fn query_orders(&self, request: PddOrderQueryRequest) -> ZtkResult<PddOrderResponse> {
let params = build_params_with_appkey(self.client.appkey(), &request)?;
self.client
.http_client()
.get("/api/open_pdd_dingdan_new.ashx", ¶ms)
.await
}
pub async fn authorize(&self, request: PddAuthorizeRequest) -> ZtkResult<PddAuthorizeResponse> {
let params = build_params_with_appkey(self.client.appkey(), &request)?;
self.client
.http_client()
.get("/api/open_pdd_shouquan_new.ashx", ¶ms)
.await
}
pub async fn authorize_query(
&self,
request: PddAuthorizeQueryRequest,
) -> ZtkResult<PddAuthorizeQueryResponse> {
let params = build_params_with_appkey(self.client.appkey(), &request)?;
self.client
.http_client()
.get("/api/open_pdd_shouquan_query_new.ashx", ¶ms)
.await
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_pdd_api_creation() {
let client = ZtkClient::new("test_appkey").build().unwrap();
let pdd = client.pdd();
assert_eq!(pdd.client().appkey(), "test_appkey");
}
}