From cba191855de88e2996685b1bb78c9c7b5aa0a32d Mon Sep 17 00:00:00 2001 From: Nicolas Polomack Date: Tue, 24 Sep 2024 00:44:17 +0200 Subject: [PATCH] fix: fixed issues with incomplete profiles --- src/lib.rs | 40 +++++++++++++++++++++++++++------------- src/protocol/commands.rs | 12 ++++++------ 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index dd510b2..383936e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -424,25 +424,39 @@ impl Client { String::from_utf8(decoded)? }, email: response.email.clone(), - country_code: { - let decoded = BASE64_URL_SAFE_NO_PAD.decode(&response.country)?; - String::from_utf8(decoded)? + country_code: 'result: { + let Some(country) = &response.country else { + break 'result None; + }; + let decoded = BASE64_URL_SAFE_NO_PAD.decode(&country)?; + let country = String::from_utf8(decoded)?; + Some(country) }, - birth_date: { + birth_date: 'result: { + let Some(day) = &response.birthday else { + break 'result None; + }; + let Some(month) = &response.birthmonth else { + break 'result None; + }; + let Some(year) = &response.birthyear else { + break 'result None; + }; + let day: u32 = { - let decoded = BASE64_URL_SAFE_NO_PAD.decode(&response.birthday)?; - String::from_utf8(decoded)?.parse()? + let decoded = BASE64_URL_SAFE_NO_PAD.decode(&day)?; + String::from_utf8(decoded)?.parse::()? }; let month: u32 = { - let decoded = BASE64_URL_SAFE_NO_PAD.decode(&response.birthmonth)?; - String::from_utf8(decoded)?.parse()? + let decoded = BASE64_URL_SAFE_NO_PAD.decode(&month)?; + String::from_utf8(decoded)?.parse::()? }; let year: i32 = { - let decoded = BASE64_URL_SAFE_NO_PAD.decode(&response.birthyear)?; - String::from_utf8(decoded)?.parse()? + let decoded = BASE64_URL_SAFE_NO_PAD.decode(&year)?; + String::from_utf8(decoded)?.parse::()? }; - NaiveDate::from_ymd_opt(year, month, day).unwrap_or_default() + NaiveDate::from_ymd_opt(year, month, day) }, }) } @@ -2744,7 +2758,7 @@ pub struct UserInfo { /// The main email of the user. pub email: String, /// The birth date of the user. - pub birth_date: NaiveDate, + pub birth_date: Option, /// The country code of the user. - pub country_code: String, + pub country_code: Option, } diff --git a/src/protocol/commands.rs b/src/protocol/commands.rs index 4667209..0bdb88d 100644 --- a/src/protocol/commands.rs +++ b/src/protocol/commands.rs @@ -370,18 +370,18 @@ pub struct UserInfoResponse { pub s: i32, #[serde(rename = "email")] pub email: String, - #[serde(rename = "firstname")] + #[serde(rename = "firstname", default)] pub firstname: String, - #[serde(rename = "lastname")] + #[serde(rename = "lastname", default)] pub lastname: String, #[serde(rename = "country")] - pub country: String, + pub country: Option, #[serde(rename = "birthday")] - pub birthday: String, + pub birthday: Option, #[serde(rename = "birthmonth")] - pub birthmonth: String, + pub birthmonth: Option, #[serde(rename = "birthyear")] - pub birthyear: String, + pub birthyear: Option, #[serde(rename = "name")] pub name: String, #[serde(rename = "k")]