noah_sdk/api/
channels.rs

1//! Channels API
2
3use crate::client::NoahClient;
4use crate::error::Result;
5use crate::models::channels::{Channel, ChannelsCountriesResponse, GetChannelsResponse};
6use crate::models::common::*;
7
8/// Parameters for getting channels for selling crypto
9#[derive(Debug, Clone)]
10pub struct GetChannelsSellParams<'a> {
11    /// Cryptocurrency code (required)
12    pub crypto_currency: &'a CryptoCurrencyCode,
13    /// Country code (optional)
14    pub country: Option<&'a CountryCode>,
15    /// Fiat currency code (optional)
16    pub fiat_currency: Option<&'a FiatCurrencyCode>,
17    /// Fiat amount (optional)
18    pub fiat_amount: Option<&'a PositiveDecimal>,
19    /// Customer ID (optional)
20    pub customer_id: Option<&'a CustomerID>,
21    /// Payment method ID (optional)
22    pub payment_method_id: Option<&'a PaymentMethodID>,
23    /// Page size (optional)
24    pub page_size: Option<u32>,
25    /// Page token (optional)
26    pub page_token: Option<&'a str>,
27}
28
29impl NoahClient {
30    /// Get channels for selling crypto (async)
31    #[cfg(feature = "async")]
32    pub async fn get_channels_sell(
33        &self,
34        params: GetChannelsSellParams<'_>,
35    ) -> Result<GetChannelsResponse> {
36        let mut path = "/channels/sell".to_string();
37        let mut query_params = vec![format!("CryptoCurrency={}", params.crypto_currency)];
38
39        if let Some(c) = params.country {
40            query_params.push(format!("Country={c}"));
41        }
42        if let Some(fc) = params.fiat_currency {
43            query_params.push(format!("FiatCurrency={fc}"));
44        }
45        if let Some(fa) = params.fiat_amount {
46            query_params.push(format!("FiatAmount={fa}"));
47        }
48        if let Some(cid) = params.customer_id {
49            query_params.push(format!("CustomerID={cid}"));
50        }
51        if let Some(pmid) = params.payment_method_id {
52            query_params.push(format!("PaymentMethodID={pmid}"));
53        }
54        if let Some(size) = params.page_size {
55            query_params.push(format!("PageSize={size}"));
56        }
57        if let Some(token) = params.page_token {
58            query_params.push(format!("PageToken={token}"));
59        }
60
61        path.push('?');
62        path.push_str(&query_params.join("&"));
63
64        self.get(&path).await
65    }
66
67    /// Get channels for selling crypto (blocking)
68    #[cfg(feature = "sync")]
69    pub fn get_channels_sell_blocking(
70        &self,
71        params: GetChannelsSellParams<'_>,
72    ) -> Result<GetChannelsResponse> {
73        let mut path = "/channels/sell".to_string();
74        let mut query_params = vec![format!("CryptoCurrency={}", params.crypto_currency)];
75
76        if let Some(c) = params.country {
77            query_params.push(format!("Country={c}"));
78        }
79        if let Some(fc) = params.fiat_currency {
80            query_params.push(format!("FiatCurrency={fc}"));
81        }
82        if let Some(fa) = params.fiat_amount {
83            query_params.push(format!("FiatAmount={fa}"));
84        }
85        if let Some(cid) = params.customer_id {
86            query_params.push(format!("CustomerID={cid}"));
87        }
88        if let Some(pmid) = params.payment_method_id {
89            query_params.push(format!("PaymentMethodID={pmid}"));
90        }
91        if let Some(size) = params.page_size {
92            query_params.push(format!("PageSize={size}"));
93        }
94        if let Some(token) = params.page_token {
95            query_params.push(format!("PageToken={token}"));
96        }
97
98        path.push('?');
99        path.push_str(&query_params.join("&"));
100
101        self.get_blocking(&path)
102    }
103
104    /// Get channel by ID (async)
105    #[cfg(feature = "async")]
106    pub async fn get_channel(
107        &self,
108        channel_id: &ChannelID,
109        crypto_currency: &CryptoCurrencyCode,
110        fiat_amount: Option<&PositiveDecimal>,
111        customer_id: Option<&CustomerID>,
112    ) -> Result<Channel> {
113        let mut path = format!("/channels/{channel_id}");
114        let mut query_params = vec![format!("CryptoCurrency={crypto_currency}")];
115
116        if let Some(fa) = fiat_amount {
117            query_params.push(format!("FiatAmount={fa}"));
118        }
119        if let Some(cid) = customer_id {
120            query_params.push(format!("CustomerID={cid}"));
121        }
122
123        path.push('?');
124        path.push_str(&query_params.join("&"));
125
126        self.get(&path).await
127    }
128
129    /// Get channel by ID (blocking)
130    #[cfg(feature = "sync")]
131    pub fn get_channel_blocking(
132        &self,
133        channel_id: &ChannelID,
134        crypto_currency: &CryptoCurrencyCode,
135        fiat_amount: Option<&PositiveDecimal>,
136        customer_id: Option<&CustomerID>,
137    ) -> Result<Channel> {
138        let mut path = format!("/channels/{channel_id}");
139        let mut query_params = vec![format!("CryptoCurrency={crypto_currency}")];
140
141        if let Some(fa) = fiat_amount {
142            query_params.push(format!("FiatAmount={fa}"));
143        }
144        if let Some(cid) = customer_id {
145            query_params.push(format!("CustomerID={cid}"));
146        }
147
148        path.push('?');
149        path.push_str(&query_params.join("&"));
150
151        self.get_blocking(&path)
152    }
153
154    /// Get countries for sell channels (async)
155    #[cfg(feature = "async")]
156    pub async fn get_channels_sell_countries(
157        &self,
158        customer_id: Option<&CustomerID>,
159    ) -> Result<ChannelsCountriesResponse> {
160        let mut path = "/channels/sell/countries".to_string();
161
162        if let Some(cid) = customer_id {
163            path.push_str(&format!("?CustomerID={cid}"));
164        }
165
166        self.get(&path).await
167    }
168
169    /// Get countries for sell channels (blocking)
170    #[cfg(feature = "sync")]
171    pub fn get_channels_sell_countries_blocking(
172        &self,
173        customer_id: Option<&CustomerID>,
174    ) -> Result<ChannelsCountriesResponse> {
175        let mut path = "/channels/sell/countries".to_string();
176
177        if let Some(cid) = customer_id {
178            path.push_str(&format!("?CustomerID={cid}"));
179        }
180
181        self.get_blocking(&path)
182    }
183}