feat: more optional fields in stammdaten

This commit is contained in:
jane400 2024-09-17 11:54:36 +02:00 committed by jane400
parent 5b205ce1e0
commit b222695c16

View file

@ -1,8 +1,8 @@
use reqwest::{header::HeaderMap, Request, RequestBuilder}; use reqwest::{header::HeaderMap, Request, RequestBuilder};
use crate::www::authorized_credentials;
use crate::constants::{app_version, linux_android_version};
use crate::common::APIResult; use crate::common::APIResult;
use crate::constants::okhttp_user_agent;
use crate::www::authorized_credentials;
use crate::{login::DHLIdToken, LibraryResult}; use crate::{login::DHLIdToken, LibraryResult};
pub struct StammdatenClient { pub struct StammdatenClient {
@ -15,18 +15,19 @@ impl StammdatenClient {
StammdatenClient { StammdatenClient {
client: reqwest::ClientBuilder::new() client: reqwest::ClientBuilder::new()
.default_headers(headers()) .default_headers(headers())
.user_agent(user_agent()) .user_agent(okhttp_user_agent())
.build() .build()
.unwrap(), .unwrap(),
} }
} }
pub(crate) fn base_request(&self, request_builder: RequestBuilder, dhli: &DHLIdToken) -> Request { pub(crate) fn base_request(
&self,
request_builder: RequestBuilder,
dhli: &DHLIdToken,
) -> Request {
request_builder request_builder
.basic_auth( .basic_auth(authorized_credentials().0, Some(authorized_credentials().1))
authorized_credentials().0,
Some(authorized_credentials().1),
)
.headers(headers()) .headers(headers())
.header("cookie", format!("dhli={}", dhli.as_str())) .header("cookie", format!("dhli={}", dhli.as_str()))
.build() .build()
@ -68,16 +69,6 @@ impl StammdatenClient {
Err(err) => Err(err.into()), Err(err) => Err(err.into()),
} }
} }
}
fn user_agent() -> String {
format!(
"okhttp/4.11.0 Post & DHL/{} ({})",
app_version(),
linux_android_version()
)
} }
fn headers() -> HeaderMap { fn headers() -> HeaderMap {
@ -144,9 +135,13 @@ pub enum CustomerDataService {
} }
#[derive(serde::Deserialize, Debug)] #[derive(serde::Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct CustomerDataFull { pub struct CustomerDataFull {
#[serde(flatten)] #[serde(flatten)]
pub common: CustomerData, pub common: CustomerData,
pub requested_services: Option<Vec<CustomerDataService>>,
//pub customer_actions: Option,
pub address: CustomerAddress, pub address: CustomerAddress,
} }