digitalocean_api/api/
image_action.rs

1use super::action::Action;
2use super::image::Image;
3use crate::method::{Create, Get, List};
4use crate::request::{ImageActionRequest, ImageRequest};
5use crate::STATIC_URL_ERROR;
6use serde::Serialize;
7use std::fmt::Display;
8
9const IMAGE_ACTIONS_SEGMENT: &str = "actions";
10
11impl ImageRequest<Get, Image> {
12    /// [Digital Ocean Documentation.](https://developers.digitalocean.com/documentation/v2/#list-all-actions-for-an-image)
13    pub fn actions(mut self) -> ImageActionRequest<List, Vec<Action>> {
14        self.url_mut()
15            .path_segments_mut()
16            .expect(STATIC_URL_ERROR)
17            .push(IMAGE_ACTIONS_SEGMENT);
18
19        self.transmute()
20    }
21
22    /// [Digital Ocean Documentation.](https://developers.digitalocean.com/documentation/v2/#transfer-an-image)
23    pub fn transfer<S>(mut self, region: S) -> ImageActionRequest<Create, Action>
24    where
25        S: AsRef<str> + Display + Serialize,
26    {
27        self.url_mut()
28            .path_segments_mut()
29            .expect(STATIC_URL_ERROR)
30            .push(IMAGE_ACTIONS_SEGMENT);
31
32        self.set_body(json!({
33            "type": "transfer",
34            "region": region,
35        }));
36
37        self.transmute()
38    }
39
40    /// [Digital Ocean Documentation.](https://developers.digitalocean.com/documentation/v2/#convert-an-image-to-a-snapshot)
41    pub fn convert(mut self) -> ImageActionRequest<Create, Action> {
42        self.url_mut()
43            .path_segments_mut()
44            .expect(STATIC_URL_ERROR)
45            .push(IMAGE_ACTIONS_SEGMENT);
46
47        self.set_body(json!({
48            "type": "convert",
49        }));
50
51        self.transmute()
52    }
53
54    /// [Digital Ocean Documentation.](https://developers.digitalocean.com/documentation/v2/#retrieve-an-existing-image-action)
55    pub fn action(mut self, id: usize) -> ImageActionRequest<Get, Action> {
56        self.url_mut()
57            .path_segments_mut()
58            .expect(STATIC_URL_ERROR)
59            .push(IMAGE_ACTIONS_SEGMENT)
60            .push(&id.to_string());
61
62        self.transmute()
63    }
64}