use crate::client::{Client, ParamType};
use std::collections::HashMap;
use crate::services::AppwriteException;
use crate::models;
use serde_json::json;
use std::io::Read;
#[derive(Clone)]
pub struct Locale {
client: Client
}
impl Locale {
pub fn new(client: &Client) -> Self {
Self {
client: client.clone()
}
}
pub fn get(&self) -> Result<models::Locale, AppwriteException> {
let path = "/locale";
let headers: HashMap<String, String> = [
("content-type".to_string(), "application/json".to_string()),
].iter().cloned().collect();
let params: HashMap<String, ParamType> = [
].iter().cloned().collect();
let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
let processedResponse:models::Locale = match response {
Ok(r) => {
match r.json() {
Ok(json) => json,
Err(e) => {
return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
}
}
}
Err(e) => {
return Err(e);
}
};
Ok(processedResponse)
}
pub fn get_continents(&self) -> Result<models::ContinentList, AppwriteException> {
let path = "/locale/continents";
let headers: HashMap<String, String> = [
("content-type".to_string(), "application/json".to_string()),
].iter().cloned().collect();
let params: HashMap<String, ParamType> = [
].iter().cloned().collect();
let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
let processedResponse:models::ContinentList = match response {
Ok(r) => {
match r.json() {
Ok(json) => json,
Err(e) => {
return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
}
}
}
Err(e) => {
return Err(e);
}
};
Ok(processedResponse)
}
pub fn get_countries(&self) -> Result<models::CountryList, AppwriteException> {
let path = "/locale/countries";
let headers: HashMap<String, String> = [
("content-type".to_string(), "application/json".to_string()),
].iter().cloned().collect();
let params: HashMap<String, ParamType> = [
].iter().cloned().collect();
let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
let processedResponse:models::CountryList = match response {
Ok(r) => {
match r.json() {
Ok(json) => json,
Err(e) => {
return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
}
}
}
Err(e) => {
return Err(e);
}
};
Ok(processedResponse)
}
pub fn get_countries_eu(&self) -> Result<models::CountryList, AppwriteException> {
let path = "/locale/countries/eu";
let headers: HashMap<String, String> = [
("content-type".to_string(), "application/json".to_string()),
].iter().cloned().collect();
let params: HashMap<String, ParamType> = [
].iter().cloned().collect();
let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
let processedResponse:models::CountryList = match response {
Ok(r) => {
match r.json() {
Ok(json) => json,
Err(e) => {
return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
}
}
}
Err(e) => {
return Err(e);
}
};
Ok(processedResponse)
}
pub fn get_countries_phones(&self) -> Result<models::PhoneList, AppwriteException> {
let path = "/locale/countries/phones";
let headers: HashMap<String, String> = [
("content-type".to_string(), "application/json".to_string()),
].iter().cloned().collect();
let params: HashMap<String, ParamType> = [
].iter().cloned().collect();
let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
let processedResponse:models::PhoneList = match response {
Ok(r) => {
match r.json() {
Ok(json) => json,
Err(e) => {
return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
}
}
}
Err(e) => {
return Err(e);
}
};
Ok(processedResponse)
}
pub fn get_currencies(&self) -> Result<models::CurrencyList, AppwriteException> {
let path = "/locale/currencies";
let headers: HashMap<String, String> = [
("content-type".to_string(), "application/json".to_string()),
].iter().cloned().collect();
let params: HashMap<String, ParamType> = [
].iter().cloned().collect();
let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
let processedResponse:models::CurrencyList = match response {
Ok(r) => {
match r.json() {
Ok(json) => json,
Err(e) => {
return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
}
}
}
Err(e) => {
return Err(e);
}
};
Ok(processedResponse)
}
pub fn get_languages(&self) -> Result<models::LanguageList, AppwriteException> {
let path = "/locale/languages";
let headers: HashMap<String, String> = [
("content-type".to_string(), "application/json".to_string()),
].iter().cloned().collect();
let params: HashMap<String, ParamType> = [
].iter().cloned().collect();
let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
let processedResponse:models::LanguageList = match response {
Ok(r) => {
match r.json() {
Ok(json) => json,
Err(e) => {
return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
}
}
}
Err(e) => {
return Err(e);
}
};
Ok(processedResponse)
}
}