Skip to content

Commit

Permalink
update for api update from 2024/07/25
Browse files Browse the repository at this point in the history
  • Loading branch information
greaka committed Jul 26, 2024
1 parent 49740f5 commit dcdbef3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
17 changes: 11 additions & 6 deletions keys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,31 @@ pub enum ApiKeyPermissions {
}

mod timestamp_parser {
use chrono::NaiveDateTime;
use chrono::{DateTime, NaiveDateTime, Utc};
use serde::{Deserialize, Deserializer, Serializer};

pub fn deserialize<'de, D>(d: D) -> Result<NaiveDateTime, D::Error>
where
D: Deserializer<'de>,
{
let timestamp = i64::deserialize(d)?;
Ok(NaiveDateTime::from_timestamp_opt(timestamp, 0)
.expect("invalid or out-of-range datetime"))
Ok(DateTime::<Utc>::from_timestamp(timestamp, 0)
.expect("invalid or out-of-range datetime")
.naive_utc())
}

pub fn serialize<S>(dt: &NaiveDateTime, s: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
s.serialize_i64(dt.timestamp())
s.serialize_i64(dt.and_utc().timestamp())
}
}

#[cfg(test)]
mod tests {
use chrono::DateTime;

use super::*;

const VALID_MAIN_KEY: &str =
Expand All @@ -146,7 +149,9 @@ mod tests {
};
assert_eq!(
subkey.expires,
NaiveDateTime::from_timestamp_opt(1702136340, 0).unwrap()
DateTime::<Utc>::from_timestamp(1702136340, 0)
.unwrap()
.naive_utc()
);
assert_eq!(subkey.permissions, vec![ApiKeyPermissions::Account]);
assert_eq!(subkey.urls, Some(vec!["/v2/tokeninfo".to_string()]));
Expand All @@ -160,7 +165,7 @@ mod tests {
};
assert_eq!(
subkey.expires,
NaiveDateTime::from_timestamp_opt(1701599984, 0).unwrap()
DateTime::from_timestamp(1701599984, 0).unwrap().naive_utc()
);
assert_eq!(subkey.permissions, vec![ApiKeyPermissions::Account]);
assert_eq!(subkey.urls, None);
Expand Down
2 changes: 1 addition & 1 deletion model/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gw2lib-model"
version = "2.1.5"
version = "2.2.0"
authors = ["Greaka <[email protected]>"]
edition = "2021"
workspace = "../"
Expand Down
2 changes: 2 additions & 0 deletions model/src/authenticated/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub enum Access {
HeartOfThorns,
PathOfFire,
EndOfDragons,
SecretsOfTheObscure,
JanthirWilds,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down

0 comments on commit dcdbef3

Please sign in to comment.