digitalocean_api/api/region.rs
1use super::{ApiLinks, ApiMeta};
2use super::{HasPagination, HasResponse, HasValue};
3use crate::method::List;
4use crate::request::RegionRequest;
5use crate::request::Request;
6use crate::{ROOT_URL, STATIC_URL_ERROR};
7use getset::{Getters, Setters};
8use serde::Deserialize;
9use serde::Serialize;
10use url::Url;
11
12const REGIONS_SEGMENT: &str = "regions";
13
14/// A region in DigitalOcean represents a datacenter where Droplets can be
15/// deployed and images can be transferred.
16///
17/// Each region represents a specific datacenter in a geographic location. Some
18/// geographical locations may have multiple "regions" available. This means
19/// that there are multiple datacenters available within that area.
20///
21/// [Digital Ocean Documentation.](https://developers.digitalocean.com/documentation/v2/#regions)
22#[derive(Deserialize, Serialize, Debug, Clone, Getters, Setters)]
23#[get = "pub"]
24pub struct Region {
25 /// A human-readable string that is used as a unique identifier for each
26 /// region.
27 name: String,
28
29 /// The display name of the region. This will be a full name that is used
30 /// in the control panel and other interfaces.
31 slug: String,
32
33 /// This attribute is set to an array which contains the identifying slugs
34 /// for the sizes available in this region.
35 sizes: Vec<String>,
36
37 /// This is a boolean value that represents whether new Droplets can be
38 /// created in this region.
39 available: bool,
40
41 /// This attribute is set to an array which contains features available in
42 /// this region
43 features: Vec<String>,
44}
45
46impl Region {
47 /// [Digital Ocean Documentation.](https://developers.digitalocean.com/documentation/v2/#list-all-regions)
48 pub fn list() -> RegionRequest<List, Vec<Region>> {
49 let mut url = ROOT_URL.clone();
50 url.path_segments_mut()
51 .expect(STATIC_URL_ERROR)
52 .push(REGIONS_SEGMENT);
53
54 Request::new(url)
55 }
56}
57
58/// Response type returned from Digital Ocean.
59#[derive(Deserialize, Serialize, Debug, Clone)]
60pub struct RegionListResponse {
61 regions: Vec<Region>,
62 links: ApiLinks,
63 meta: ApiMeta,
64}
65
66impl HasResponse for Vec<Region> {
67 type Response = RegionListResponse;
68}
69
70impl HasPagination for RegionListResponse {
71 fn next_page(&self) -> Option<Url> {
72 self.links.next()
73 }
74}
75
76impl HasValue for RegionListResponse {
77 type Value = Vec<Region>;
78
79 fn value(self) -> Vec<Region> {
80 self.regions
81 }
82}