Skip to content

Commit

Permalink
fix: fixed issues with incomplete profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Hirevo committed Sep 23, 2024
1 parent df55ab6 commit cba1918
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
40 changes: 27 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u32>()?
};
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::<u32>()?
};
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::<i32>()?
};

NaiveDate::from_ymd_opt(year, month, day).unwrap_or_default()
NaiveDate::from_ymd_opt(year, month, day)
},
})
}
Expand Down Expand Up @@ -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<NaiveDate>,
/// The country code of the user.
pub country_code: String,
pub country_code: Option<String>,
}
12 changes: 6 additions & 6 deletions src/protocol/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
#[serde(rename = "birthday")]
pub birthday: String,
pub birthday: Option<String>,
#[serde(rename = "birthmonth")]
pub birthmonth: String,
pub birthmonth: Option<String>,
#[serde(rename = "birthyear")]
pub birthyear: String,
pub birthyear: Option<String>,
#[serde(rename = "name")]
pub name: String,
#[serde(rename = "k")]
Expand Down

0 comments on commit cba1918

Please sign in to comment.