digitalocean_api/api/
floating_ip_action.rs

1use super::floating_ip::FloatingIp;
2use super::Action;
3use crate::method::{Create, Get, List};
4use crate::request::{FloatingIpActionRequest, FloatingIpRequest};
5use crate::STATIC_URL_ERROR;
6
7const FLOATING_IP_ACTIONS_SEGMENT: &str = "actions";
8
9impl FloatingIpRequest<Get, FloatingIp> {
10    /// [Digital Ocean Documentation.](https://developers.digitalocean.com/documentation/v2/#list-all-actions-for-a-floating-ip)
11    pub fn actions(mut self) -> FloatingIpActionRequest<List, Vec<Action>> {
12        self.url_mut()
13            .path_segments_mut()
14            .expect(STATIC_URL_ERROR)
15            .push(FLOATING_IP_ACTIONS_SEGMENT);
16
17        self.transmute()
18    }
19
20    /// [Digital Ocean Documentation.](https://developers.digitalocean.com/documentation/v2/#retrieve-an-existing-floating-ip-action)
21    pub fn action(mut self, id: usize) -> FloatingIpActionRequest<Get, Action> {
22        self.url_mut()
23            .path_segments_mut()
24            .expect(STATIC_URL_ERROR)
25            .push(FLOATING_IP_ACTIONS_SEGMENT)
26            .push(&id.to_string());
27
28        self.transmute()
29    }
30
31    /// [Digital Ocean Documentation.](https://developers.digitalocean.com/documentation/v2/#unassign-a-floating-ip)
32    pub fn unassign(mut self) -> FloatingIpActionRequest<Create, Action> {
33        self.url_mut()
34            .path_segments_mut()
35            .expect(STATIC_URL_ERROR)
36            .push(FLOATING_IP_ACTIONS_SEGMENT);
37
38        self.set_body(json!({
39            "type": "unassign",
40        }));
41
42        self.transmute()
43    }
44
45    /// [Digital Ocean Documentation.](https://developers.digitalocean.com/documentation/v2/#assign-a-floating-ip-to-a-droplet)
46    pub fn assign(mut self, id: usize) -> FloatingIpActionRequest<Create, Action> {
47        self.url_mut()
48            .path_segments_mut()
49            .expect(STATIC_URL_ERROR)
50            .push(FLOATING_IP_ACTIONS_SEGMENT);
51
52        self.set_body(json!({
53            "type": "assign",
54            "droplet_id": id,
55        }));
56
57        self.transmute()
58    }
59}