From 92cd3ccf97029c32632b23f4037feec3d6e1b75d Mon Sep 17 00:00:00 2001 From: Dominic Grimm Date: Sun, 26 Feb 2023 15:14:04 +0100 Subject: [PATCH] Add support for 'getLatestImportTime' --- src/lib.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 8329daa..53256ec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -696,6 +696,33 @@ impl Client { } } + pub async fn last_import_time(&self) -> Result { + let resp: RpcResponse = reqwest::Client::new() + .get(self.rpc_url.as_str()) + .header(reqwest::header::USER_AGENT, &self.user_agent) + .header(reqwest::header::CONTENT_TYPE, "application/json") + .header(reqwest::header::ACCEPT, "application/json") + .json(&json!({ + "id": "ID", + "method": "getLatestImportTime", + "jsonrpc": "2.0" + })) + .send() + .await? + .json() + .await?; + if let Some(e) = resp.error { + bail!("RPC error: {:?}", e); + } + + if let Some(x) = resp.result { + Ok(chrono::NaiveDateTime::from_timestamp_opt(x, 0) + .context("Could not convert Unix timestamp to NaiveDateTime")?) + } else { + bail!("RPC result is null"); + } + } + pub fn construct_bearer(auth: &str) -> String { format!("Bearer {}", auth) }