1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct Countries {
6 pub client: Client,
7}
8
9impl Countries {
10 #[doc(hidden)]
11 pub fn new(client: Client) -> Self {
12 Self { client }
13 }
14
15 #[doc = "List countries\n\nReturns a list of all countries that are supported by Remote API alphabetically ordered.\n\n```rust,no_run\nasync fn example_countries_get_supported_country() -> anyhow::Result<()> {\n let client = remote_api::Client::new_from_env();\n let result: remote_api::types::CountriesResponse =\n client.countries().get_supported_country().await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
16 #[tracing::instrument]
17 pub async fn get_supported_country<'a>(
18 &'a self,
19 ) -> Result<crate::types::CountriesResponse, crate::types::error::Error> {
20 let mut req = self.client.client.request(
21 http::Method::GET,
22 format!("{}/{}", self.client.base_url, "v1/countries"),
23 );
24 req = req.bearer_auth(&self.client.token);
25 let resp = req.send().await?;
26 let status = resp.status();
27 if status.is_success() {
28 let text = resp.text().await.unwrap_or_default();
29 serde_json::from_str(&text).map_err(|err| {
30 crate::types::error::Error::from_serde_error(
31 format_serde_error::SerdeError::new(text.to_string(), err),
32 status,
33 )
34 })
35 } else {
36 let text = resp.text().await.unwrap_or_default();
37 Err(crate::types::error::Error::Server {
38 body: text.to_string(),
39 status,
40 })
41 }
42 }
43
44 #[doc = "List all holidays of a country\n\nList all holidays of a country for a specific year. \
45 Optionally, it can be filtered by country subdivision.\n\n**Parameters:**\n\n- \
46 `country_code: &'astr`: Country code according to ISO 3166-1 3-digit alphabetic codes \
47 (required)\n- `country_subdivision_code: Option<String>`: Country subdivision code \
48 according to ISO 3166-2 codes\n- `year: &'astr`: Year for the holidays \
49 (required)\n\n```rust,no_run\nasync fn example_countries_get_index_holiday() -> \
50 anyhow::Result<()> {\n let client = remote_api::Client::new_from_env();\n let \
51 result: remote_api::types::HolidaysResponse = client\n .countries()\n \
52 .get_index_holiday(\n \"some-string\",\n \
53 Some(\"some-string\".to_string()),\n \"some-string\",\n )\n \
54 .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
55 #[tracing::instrument]
56 pub async fn get_index_holiday<'a>(
57 &'a self,
58 country_code: &'a str,
59 country_subdivision_code: Option<String>,
60 year: &'a str,
61 ) -> Result<crate::types::HolidaysResponse, crate::types::error::Error> {
62 let mut req = self.client.client.request(
63 http::Method::GET,
64 format!(
65 "{}/{}",
66 self.client.base_url,
67 "v1/countries/{country_code}/holidays/{year}"
68 .replace("{country_code}", country_code)
69 .replace("{year}", year)
70 ),
71 );
72 req = req.bearer_auth(&self.client.token);
73 let mut query_params = vec![];
74 if let Some(p) = country_subdivision_code {
75 query_params.push(("country_subdivision_code", p));
76 }
77
78 req = req.query(&query_params);
79 let resp = req.send().await?;
80 let status = resp.status();
81 if status.is_success() {
82 let text = resp.text().await.unwrap_or_default();
83 serde_json::from_str(&text).map_err(|err| {
84 crate::types::error::Error::from_serde_error(
85 format_serde_error::SerdeError::new(text.to_string(), err),
86 status,
87 )
88 })
89 } else {
90 let text = resp.text().await.unwrap_or_default();
91 Err(crate::types::error::Error::Server {
92 body: text.to_string(),
93 status,
94 })
95 }
96 }
97
98 #[doc = "Show form schema\n\nReturns the json schema of a supported form. Possible form names \
99 are:\n\n- address_details\n- administrative_details\n- bank_account_details\n- \
100 billing_address_details\n- contract_details\n- emergency_contact_details\n- \
101 employment_document_details\n- personal_details\n- \
102 pricing_plan_details\n\n\n\n**Parameters:**\n\n- `country_code: &'astr`: Country code \
103 according to ISO 3-digit alphabetic codes (required)\n- `form: &'astr`: Name of the \
104 desired form (required)\n\n```rust,no_run\nasync fn \
105 example_countries_get_show_form_country() -> anyhow::Result<()> {\n let client = \
106 remote_api::Client::new_from_env();\n let result: \
107 remote_api::types::CountryFormResponse = client\n .countries()\n \
108 .get_show_form_country(\"some-string\", \"some-string\")\n .await?;\n \
109 println!(\"{:?}\", result);\n Ok(())\n}\n```"]
110 #[tracing::instrument]
111 pub async fn get_show_form_country<'a>(
112 &'a self,
113 country_code: &'a str,
114 form: &'a str,
115 ) -> Result<crate::types::CountryFormResponse, crate::types::error::Error> {
116 let mut req = self.client.client.request(
117 http::Method::GET,
118 format!(
119 "{}/{}",
120 self.client.base_url,
121 "v1/countries/{country_code}/{form}"
122 .replace("{country_code}", country_code)
123 .replace("{form}", form)
124 ),
125 );
126 req = req.bearer_auth(&self.client.token);
127 let resp = req.send().await?;
128 let status = resp.status();
129 if status.is_success() {
130 let text = resp.text().await.unwrap_or_default();
131 serde_json::from_str(&text).map_err(|err| {
132 crate::types::error::Error::from_serde_error(
133 format_serde_error::SerdeError::new(text.to_string(), err),
134 status,
135 )
136 })
137 } else {
138 let text = resp.text().await.unwrap_or_default();
139 Err(crate::types::error::Error::Server {
140 body: text.to_string(),
141 status,
142 })
143 }
144 }
145}