Skip to main content

nil_client/client/
city.rs

1// Copyright (C) Call of Nil contributors
2// SPDX-License-Identifier: AGPL-3.0-only
3
4use super::Client;
5use crate::error::Result;
6use crate::http;
7use nil_core::city::{City, PublicCity};
8use nil_core::ranking::score::Score;
9use nil_payload::city::*;
10
11impl Client {
12  pub async fn get_city(&self, req: GetCityRequest) -> Result<City> {
13    http::json_post("get-city")
14      .body(req)
15      .server(self.server)
16      .maybe_authorization(self.authorization.as_ref())
17      .user_agent(&self.user_agent)
18      .send()
19      .await
20  }
21
22  pub async fn get_city_score(&self, req: GetCityScoreRequest) -> Result<Score> {
23    http::json_post("get-city-score")
24      .body(req)
25      .server(self.server)
26      .user_agent(&self.user_agent)
27      .send()
28      .await
29  }
30
31  pub async fn get_public_cities(
32    &self,
33    req: GetPublicCitiesRequest,
34  ) -> Result<Vec<GetPublicCityResponse>> {
35    http::json_post("get-public-cities")
36      .body(req)
37      .server(self.server)
38      .user_agent(&self.user_agent)
39      .send()
40      .await
41  }
42
43  pub async fn get_public_city(&self, req: GetPublicCityRequest) -> Result<GetPublicCityResponse> {
44    http::json_post("get-public-city")
45      .body(req)
46      .server(self.server)
47      .user_agent(&self.user_agent)
48      .send()
49      .await
50  }
51
52  pub async fn rename_city(&self, req: RenameCityRequest) -> Result<()> {
53    http::post("rename-city")
54      .body(req)
55      .server(self.server)
56      .maybe_authorization(self.authorization.as_ref())
57      .user_agent(&self.user_agent)
58      .send()
59      .await
60  }
61
62  pub async fn search_city(&self, req: SearchCityRequest) -> Result<Vec<City>> {
63    http::json_post("search-city")
64      .body(req)
65      .server(self.server)
66      .maybe_authorization(self.authorization.as_ref())
67      .user_agent(&self.user_agent)
68      .send()
69      .await
70  }
71
72  pub async fn search_public_city(&self, req: SearchPublicCityRequest) -> Result<Vec<PublicCity>> {
73    http::json_post("search-public-city")
74      .body(req)
75      .server(self.server)
76      .user_agent(&self.user_agent)
77      .send()
78      .await
79  }
80}