iop_client/
product_country.rs1use log::info;
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4
5use crate::{
6 constants::{methods, urls},
7 IopClient,
8};
9
10#[derive(Serialize, Deserialize, Debug)]
11struct ProductCountryGetCountryListResponse {
12 #[serde(rename = "alibaba_icbu_product_country_getcountrylist_response")]
13 response: ProductCountryGetCountryList,
14}
15
16#[derive(Serialize, Deserialize, Debug)]
17struct ProductCountryGetCountryList {
18 request_id: Option<String>,
19 _trace_id_: Option<String>,
20 biz_success: bool,
21 trace_id: Option<String>,
22 data: ProductCountryDto,
23}
24
25#[derive(Serialize, Deserialize, Debug)]
26pub struct ProductCountryDto {
27 #[serde(rename = "continent_d_t_o")]
28 pub items: Vec<ProductCountryItem>,
29}
30
31#[derive(Serialize, Deserialize, Debug)]
32pub struct ProductCountryItem {
33 pub continent_name: String,
34 pub continent_code: String,
35
36 #[serde(rename = "country_list")]
37 pub countries: CountryList,
38}
39
40#[derive(Serialize, Deserialize, Debug)]
41pub struct CountryList {
42 #[serde(rename = "country_d_t_o")]
43 pub data: Vec<CountryItem>,
44}
45
46#[derive(Serialize, Deserialize, Debug)]
47pub struct CountryItem {
48 pub country_code: String,
49 pub country_name: String,
50}
51
52impl IopClient {
53 pub async fn list_product_countries(
74 &self,
75 _language: Option<String>,
76 ) -> Result<ProductCountryDto, Box<dyn std::error::Error>> {
77 let mut map = HashMap::new();
78 map.insert("country_request".to_string(), "{}".to_string());
79 map.insert(
80 "method".to_string(),
81 methods::ALIBABA_ICBU_PRODUCT_COUNTRY_GETCOUNTRYLIST.to_string(),
82 );
83 let params = self.build_request_params(map).await;
84
85 let hash = self.generate_sign(None, params.clone());
86 let url = self.generate_url(urls::BASE_SYNC_URL.to_string(), params.clone(), hash);
87 info!("--------list_product_countries-------- url: {:#?}", url);
88
89 let response = self.client.get(&url).send().await?;
90 let result = response
91 .json::<ProductCountryGetCountryListResponse>()
92 .await?;
93
94 Ok(result.response.data)
95 }
96}