dhan_rs/api/ip.rs
1//! Static IP management endpoints.
2
3use crate::client::DhanClient;
4use crate::error::Result;
5use crate::types::auth::{IpInfo, IpSetResponse, SetIpRequest};
6
7impl DhanClient {
8 /// Set a primary or secondary static IP for the account.
9 ///
10 /// Once set, the IP cannot be modified for the next 7 days.
11 ///
12 /// **Endpoint:** `POST /v2/ip/setIP`
13 ///
14 /// # Example
15 ///
16 /// ```no_run
17 /// # use dhan_rs::client::DhanClient;
18 /// # use dhan_rs::types::auth::SetIpRequest;
19 /// # use dhan_rs::types::enums::IpFlag;
20 /// # #[tokio::main]
21 /// # async fn main() -> dhan_rs::error::Result<()> {
22 /// let client = DhanClient::new("1000000001", "your-access-token");
23 /// let req = SetIpRequest {
24 /// dhan_client_id: "1000000001".into(),
25 /// ip: "10.200.10.10".into(),
26 /// ip_flag: IpFlag::PRIMARY,
27 /// };
28 /// let resp = client.set_ip(&req).await?;
29 /// println!("{}: {}", resp.status, resp.message);
30 /// # Ok(())
31 /// # }
32 /// ```
33 pub async fn set_ip(&self, req: &SetIpRequest) -> Result<IpSetResponse> {
34 self.post("/v2/ip/setIP", req).await
35 }
36
37 /// Modify a previously set primary or secondary static IP.
38 ///
39 /// Can only be used when IP modification is allowed (once every 7 days).
40 ///
41 /// **Endpoint:** `PUT /v2/ip/modifyIP`
42 pub async fn modify_ip(&self, req: &SetIpRequest) -> Result<IpSetResponse> {
43 self.put("/v2/ip/modifyIP", req).await
44 }
45
46 /// Get the currently configured static IPs and their modification dates.
47 ///
48 /// **Endpoint:** `GET /v2/ip/getIP`
49 ///
50 /// # Example
51 ///
52 /// ```no_run
53 /// # use dhan_rs::client::DhanClient;
54 /// # #[tokio::main]
55 /// # async fn main() -> dhan_rs::error::Result<()> {
56 /// let client = DhanClient::new("1000000001", "your-access-token");
57 /// let info = client.get_ip().await?;
58 /// if let Some(ip) = &info.primary_ip {
59 /// println!("Primary IP: {ip}");
60 /// }
61 /// # Ok(())
62 /// # }
63 /// ```
64 pub async fn get_ip(&self) -> Result<IpInfo> {
65 self.get("/v2/ip/getIP").await
66 }
67}