noah_sdk/api/
customers.rs

1//! Customers API
2
3use crate::client::NoahClient;
4use crate::error::Result;
5use crate::models::common::*;
6use crate::models::customers::{Customer, CustomerInput, GetCustomersResponse};
7
8impl NoahClient {
9    /// Get customer by ID (async)
10    #[cfg(feature = "async")]
11    pub async fn get_customer(&self, customer_id: &CustomerID) -> Result<Customer> {
12        let path = format!("/customers/{customer_id}");
13        self.get(&path).await
14    }
15
16    /// Get customer by ID (blocking)
17    #[cfg(feature = "sync")]
18    pub fn get_customer_blocking(&self, customer_id: &CustomerID) -> Result<Customer> {
19        let path = format!("/customers/{customer_id}");
20        self.get_blocking(&path)
21    }
22
23    /// Create or update customer (async)
24    #[cfg(feature = "async")]
25    pub async fn create_or_update_customer(
26        &self,
27        customer_id: &CustomerID,
28        customer: &CustomerInput,
29    ) -> Result<()> {
30        let path = format!("/customers/{customer_id}");
31        let _response: Option<serde_json::Value> = self.put(&path, customer).await?;
32        Ok(())
33    }
34
35    /// Create or update customer (blocking)
36    #[cfg(feature = "sync")]
37    pub fn create_or_update_customer_blocking(
38        &self,
39        customer_id: &CustomerID,
40        customer: &CustomerInput,
41    ) -> Result<()> {
42        let path = format!("/customers/{customer_id}");
43        let _response: Option<serde_json::Value> = self.put_blocking(&path, customer)?;
44        Ok(())
45    }
46
47    /// Get customers (async)
48    #[cfg(feature = "async")]
49    pub async fn get_customers(
50        &self,
51        page_size: Option<u32>,
52        page_token: Option<&str>,
53        sort_direction: Option<&SortDirection>,
54    ) -> Result<GetCustomersResponse> {
55        let mut path = "/customers".to_string();
56        let mut query_params = Vec::new();
57
58        if let Some(size) = page_size {
59            query_params.push(format!("PageSize={size}"));
60        }
61        if let Some(token) = page_token {
62            query_params.push(format!("PageToken={token}"));
63        }
64        if let Some(sort) = sort_direction {
65            query_params.push(format!("SortDirection={sort:?}"));
66        }
67
68        if !query_params.is_empty() {
69            path.push('?');
70            path.push_str(&query_params.join("&"));
71        }
72
73        self.get(&path).await
74    }
75
76    /// Get customers (blocking)
77    #[cfg(feature = "sync")]
78    pub fn get_customers_blocking(
79        &self,
80        page_size: Option<u32>,
81        page_token: Option<&str>,
82        sort_direction: Option<&SortDirection>,
83    ) -> Result<GetCustomersResponse> {
84        let mut path = "/customers".to_string();
85        let mut query_params = Vec::new();
86
87        if let Some(size) = page_size {
88            query_params.push(format!("PageSize={size}"));
89        }
90        if let Some(token) = page_token {
91            query_params.push(format!("PageToken={token}"));
92        }
93        if let Some(sort) = sort_direction {
94            query_params.push(format!("SortDirection={sort:?}"));
95        }
96
97        if !query_params.is_empty() {
98            path.push('?');
99            path.push_str(&query_params.join("&"));
100        }
101
102        self.get_blocking(&path)
103    }
104}