dceapi_rs/services/
delivery.rs

1//! Delivery service for delivery data APIs.
2
3use crate::error::{Error, Result};
4use crate::http::{BaseClient, RequestOptions};
5use crate::models::{
6    DeliveryCost, DeliveryData, DeliveryDataRequest, DeliveryMatch, DeliveryMatchRequest,
7    WarehousePremium, WarehouseReceipt, WarehouseReceiptRequest,
8};
9
10/// API endpoint for delivery data.
11const PATH_GET_DELIVERY_DATA: &str = "/dceapi/forward/publicweb/deliverystat/delivery";
12
13/// API endpoint for delivery match data.
14const PATH_GET_DELIVERY_MATCH: &str = "/dceapi/forward/publicweb/deliverystat/deliveryMatch";
15
16/// API endpoint for warehouse receipt data.
17const PATH_GET_WAREHOUSE_RECEIPT: &str = "/dceapi/forward/publicweb/deliverystat/warehouseReceipt";
18
19/// API endpoint for delivery costs.
20const PATH_GET_DELIVERY_COST: &str = "/dceapi/forward/publicweb/deliverypara/deliveryCosts";
21
22/// API endpoint for warehouse premium.
23const PATH_GET_WAREHOUSE_PREMIUM: &str = "/dceapi/forward/publicweb/deliverypara/floatingAgio";
24
25/// Delivery service for accessing delivery-related data.
26#[derive(Debug, Clone)]
27pub struct DeliveryService {
28    client: BaseClient,
29}
30
31impl DeliveryService {
32    /// Create a new delivery service.
33    pub fn new(client: BaseClient) -> Self {
34        DeliveryService { client }
35    }
36
37    /// Get delivery data.
38    ///
39    /// # Arguments
40    /// * `req` - Request with variety code and trade date
41    /// * `opts` - Optional request options
42    pub async fn get_delivery_data(
43        &self,
44        req: &DeliveryDataRequest,
45        opts: Option<RequestOptions>,
46    ) -> Result<Vec<DeliveryData>> {
47        self.client.do_post(PATH_GET_DELIVERY_DATA, req, opts).await
48    }
49
50    /// Get delivery match data.
51    ///
52    /// # Arguments
53    /// * `req` - Request with variety code and trade date
54    /// * `opts` - Optional request options
55    pub async fn get_delivery_match(
56        &self,
57        req: &DeliveryMatchRequest,
58        opts: Option<RequestOptions>,
59    ) -> Result<Vec<DeliveryMatch>> {
60        self.client.do_post(PATH_GET_DELIVERY_MATCH, req, opts).await
61    }
62
63    /// Get warehouse receipt data.
64    ///
65    /// # Arguments
66    /// * `req` - Request with variety code and trade date
67    /// * `opts` - Optional request options
68    pub async fn get_warehouse_receipt(
69        &self,
70        req: &WarehouseReceiptRequest,
71        opts: Option<RequestOptions>,
72    ) -> Result<Vec<WarehouseReceipt>> {
73        self.client.do_post(PATH_GET_WAREHOUSE_RECEIPT, req, opts).await
74    }
75
76    /// Get delivery cost for a variety.
77    ///
78    /// # Arguments
79    /// * `variety` - Variety code
80    /// * `opts` - Optional request options
81    pub async fn get_delivery_cost(
82        &self,
83        variety: &str,
84        opts: Option<RequestOptions>,
85    ) -> Result<DeliveryCost> {
86        if variety.is_empty() {
87            return Err(Error::validation("variety", "variety is required"));
88        }
89
90        #[derive(serde::Serialize)]
91        #[serde(rename_all = "camelCase")]
92        struct Request<'a> {
93            variety_code: &'a str,
94        }
95
96        let req = Request { variety_code: variety };
97        self.client.do_post(PATH_GET_DELIVERY_COST, &req, opts).await
98    }
99
100    /// Get warehouse premium for a variety.
101    ///
102    /// # Arguments
103    /// * `variety` - Variety code
104    /// * `opts` - Optional request options
105    pub async fn get_warehouse_premium(
106        &self,
107        variety: &str,
108        opts: Option<RequestOptions>,
109    ) -> Result<Vec<WarehousePremium>> {
110        if variety.is_empty() {
111            return Err(Error::validation("variety", "variety is required"));
112        }
113
114        #[derive(serde::Serialize)]
115        #[serde(rename_all = "camelCase")]
116        struct Request<'a> {
117            variety_code: &'a str,
118        }
119
120        let req = Request { variety_code: variety };
121        self.client.do_post(PATH_GET_WAREHOUSE_PREMIUM, &req, opts).await
122    }
123}