ft_api/
sync_status.rs

1#[derive(serde_derive::Deserialize, Debug)]
2pub struct Status {
3    pub last_synced_hash: String,
4    #[serde(deserialize_with = "deserialize_datetime")]
5    pub last_updated_on: chrono::DateTime<chrono::Utc>,
6}
7
8fn deserialize_datetime<'de, D>(deserializer: D) -> Result<chrono::DateTime<chrono::Utc>, D::Error>
9where
10    D: serde::de::Deserializer<'de>,
11{
12    use chrono::TimeZone;
13
14    // use our visitor to deserialize an `ActualValue`
15    let v: i64 = serde::de::Deserialize::deserialize(deserializer)?;
16
17    Ok(chrono::Utc.timestamp_millis(v))
18}
19
20// TODO: define ActionError here and return actual errors that sync status can throw.
21
22pub fn sync_status(
23    collection: &str,
24    auth_code: &str,
25    platform: &str,
26    client_version: &str,
27) -> realm_client::Result<Status> {
28    realm_client::page(
29        &format!("/{}/~/sync-status/", collection),
30        maplit::hashmap! {"auth_code" => auth_code, "platform" => platform, "client_version" => client_version},
31        Some("sync_status".to_string()),
32    )
33}