1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
pub trait ExpirableToken: Send + Sync {
  // fn is_expired(&self) -> bool;
  fn get_token(&self) -> Option<String>;
}

#[cfg(any(feature = "full", feature = "apps"))]
impl ExpirableToken for octocrate_types::InstallationToken {
  fn get_token(&self) -> Option<String> {
    let is_expired = self.expires_at < chrono::Utc::now().to_rfc3339();

    if is_expired {
      None
    } else {
      Some(self.token.clone())
    }
  }
}