Skip to content

Commit

Permalink
Fix time types to i64, as chrono does.
Browse files Browse the repository at this point in the history
  • Loading branch information
Celeo committed Jan 30, 2024
1 parent 5ea333d commit de5a845
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rfesi"
version = "0.41.0"
version = "0.41.1"
authors = ["Celeo <mattboulanger@fastmail.com>"]
edition = "2021"
description = "Rust API for EVE Online's ESI"
Expand Down
4 changes: 2 additions & 2 deletions src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub struct EsiBuilder {
pub(crate) callback_url: Option<String>,
pub(crate) scope: Option<String>,
pub(crate) access_token: Option<String>,
pub(crate) access_expiration: Option<u128>,
pub(crate) access_expiration: Option<i64>,
pub(crate) refresh_token: Option<String>,
pub(crate) user_agent: Option<String>,
pub(crate) http_timeout: Option<u64>,
Expand Down Expand Up @@ -131,7 +131,7 @@ impl EsiBuilder {
}

/// Set the access_expiration.
pub fn access_expiration(mut self, val: Option<u128>) -> Self {
pub fn access_expiration(mut self, val: Option<i64>) -> Self {
self.access_expiration = val;
self
}
Expand Down
16 changes: 10 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct AuthenticateResponse {
#[derive(Debug, Deserialize)]
struct RefreshTokenAuthenticateResponse {
access_token: String,
expires_in: u16,
expires_in: u64,
refresh_token: String,
}

Expand Down Expand Up @@ -93,7 +93,7 @@ pub struct Esi {
/// The access token from ESI, if set.
pub access_token: Option<String>,
/// The millisecond unix timestamp after which the access token expires, if present.
pub access_expiration: Option<u128>,
pub access_expiration: Option<i64>,
/// The refresh token from ESI, if set.
pub refresh_token: Option<String>,
/// HTTP client
Expand Down Expand Up @@ -350,7 +350,7 @@ impl Esi {
);
self.access_token = Some(data.access_token);
// the response's "expires_in" field is seconds but need millis
self.access_expiration = Some((data.expires_in as u128 * 1_000) + current_time_millis()?);
self.access_expiration = Some((data.expires_in as i64 * 1_000) + current_time_millis()?);
self.refresh_token = data.refresh_token;
Ok(claim_data)
}
Expand Down Expand Up @@ -445,7 +445,7 @@ impl Esi {
let data: RefreshTokenAuthenticateResponse = resp.json().await?;
self.access_token = Some(data.access_token);
// the response's "expires_in" field is seconds, need millis
self.access_expiration = Some((data.expires_in as u128 * 1_000) + current_time_millis()?);
self.access_expiration = Some((data.expires_in as i64 * 1_000) + current_time_millis()?);
self.refresh_token = Some(data.refresh_token);
Ok(())
}
Expand Down Expand Up @@ -792,8 +792,12 @@ impl Esi {
}

/// Get the current system timestamp since the epoch.
fn current_time_millis() -> Result<u128, EsiError> {
Ok(SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis())
fn current_time_millis() -> Result<i64, EsiError> {
Ok(SystemTime::now()
.duration_since(UNIX_EPOCH)?
.as_millis()
.try_into()
.expect("i64 overflow for time"))
}

#[cfg(test)]
Expand Down

0 comments on commit de5a845

Please sign in to comment.