dinio_sdk/api/geo.rs
1//! `/api/v1/geo` (`../core/src/api/geo.ts`): the country table geo bans are checked against.
2
3use reqwest::Method;
4
5use crate::client::Client;
6use crate::error::Result;
7use crate::models::GeoCatalog;
8
9/// Geo route, from [`Client::geo`].
10pub struct Geo<'a> {
11 client: &'a Client,
12}
13
14impl<'a> Geo<'a> {
15 pub(crate) fn new(client: &'a Client) -> Self {
16 Self { client }
17 }
18
19 /// Every region, sub-region and country, with the codes a geo ban takes. Any key may
20 /// read it, a zone key too. Core marks the answer cacheable for a day
21 /// (`Cache-Control: private, max-age=86400`).
22 ///
23 /// `GET /api/v1/geo`
24 ///
25 /// # Examples
26 ///
27 /// ```no_run
28 /// # async fn example(client: &dinio_sdk::Client) -> dinio_sdk::Result<()> {
29 /// let catalog = client.geo().catalog().await?;
30 /// let hr = catalog.parse_area("HR")?;
31 /// println!("{}", catalog.describe(hr)); // Country Croatia (191)
32 /// # Ok(())
33 /// # }
34 /// ```
35 pub async fn catalog(&self) -> Result<GeoCatalog> {
36 let request = self.client.request(Method::GET, &["geo"])?;
37 Ok(self.client.send(request).await?.0)
38 }
39}