Skip to main content

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