fns_api_client/models/
auth_response.rs1use yaserde::de::from_str;
2use crate::client::error::{OpenApiClientError, XmlDeserializationError};
3use crate::dto::auth_response::{Body, Envelope};
4
5#[derive(Clone)]
6pub struct AuthResponse {
7 pub result: AuthResponseResult,
8}
9
10impl AuthResponse {
11 pub(crate) fn new(xml_string: &String) -> Result<AuthResponse, OpenApiClientError> {
12 let auth_response = from_str::<Envelope>(xml_string);
13 match auth_response {
14 Ok(ok) => {
15 let body = ok.body;
16 let result = match body {
17 Body::Fault(fault) => {
18 AuthResponseResult::Error(AuthError{ message: fault.faultstring })
19 }
20 Body::GetMessageResponse(response) => {
21 AuthResponseResult::Ok(AuthResponseToken { value: response.message.auth_response.auth_app_info.token })
22 }
23 };
24 Ok(AuthResponse { result })
25 }
26 Err(message) => {
27 return Err(OpenApiClientError::DeserializationError(
28 XmlDeserializationError{
29 cause: message,
30 brief: "Ошибка десериализации ответа при авторизации".to_string(),
31 xml_string: xml_string.to_string()
32 }));
33 }
34 }
35 }
36}
37
38#[derive(Clone)]
39pub enum AuthResponseResult {
40 Ok(AuthResponseToken),
41 Error(AuthError),
42}
43
44#[derive(Clone)]
45pub struct AuthError{
46 pub message: String
47}
48
49#[derive(Clone)]
50pub struct AuthResponseToken {
51 pub value: String,
52}