From 33549f249d0d8183f5fe41b619e83e7a2d0c0e38 Mon Sep 17 00:00:00 2001 From: felixm Date: Sun, 15 Dec 2024 14:19:45 -0500 Subject: [PATCH] Add safebuf attribute to goal --- src/lib.rs | 6 +++--- src/types.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ff474bc..6985709 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ pub mod types; -use crate::types::{CreateDatapoint, Datapoint, Goal, UserInfo, UserInfoDiff}; +use crate::types::{CreateDatapoint, Datapoint, GoalSummary, UserInfo, UserInfoDiff}; use reqwest::Client; use time::OffsetDateTime; @@ -157,7 +157,7 @@ impl BeeminderClient { /// /// # Errors /// Returns an error if the HTTP request fails or response cannot be parsed. - pub async fn get_goals(&self, username: &str) -> Result, Error> { + pub async fn get_goals(&self, username: &str) -> Result, Error> { self.request(&format!("users/{username}/goals.json"), None) .await } @@ -166,7 +166,7 @@ impl BeeminderClient { /// /// # Errors /// Returns an error if the HTTP request fails or response cannot be parsed. - pub async fn get_archived_goals(&self, username: &str) -> Result, Error> { + pub async fn get_archived_goals(&self, username: &str) -> Result, Error> { self.request(&format!("users/{username}/goals/archived.json"), None) .await } diff --git a/src/types.rs b/src/types.rs index c7e93f2..ef0126f 100644 --- a/src/types.rs +++ b/src/types.rs @@ -52,6 +52,49 @@ pub struct Goal { pub datapublic: bool, /// Amount pledged in USD on the goal pub pledge: f64, + /// Number of days until derailment (0 if in beemergency) + pub safebuf: i32, + /// Unix timestamp of the last (explicitly entered) datapoint + #[serde(with = "time::serde::timestamp")] + pub lastday: OffsetDateTime, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct GoalSummary { + /// Final part of goal URL, used as identifier (e.g., "weight" in beeminder.com/alice/weight) + pub slug: String, + /// User-specified title for the goal + pub title: String, + /// Type of goal (hustler/biker/fatloser/gainer/inboxer/drinker/custom) + pub goal_type: String, + /// Summary of what needs to be done by when, e.g., "+2 within 1 day". + pub limsum: String, + /// URL for the goal's graph SVG + pub svg_url: String, + /// URL for the goal's graph image + pub graph_url: String, + /// URL for the goal's graph thumbnail image + pub thumb_url: String, + /// Unix timestamp of derailment if nothing is reported + #[serde(with = "time::serde::timestamp")] + pub losedate: OffsetDateTime, + /// Unix timestamp of the goal date + #[serde(with = "time::serde::timestamp::option")] + pub goaldate: Option, + /// Goal value - the number the bright red line will eventually reach + pub goalval: Option, + /// Slope of the (final section of the) bright red line + pub rate: Option, + /// Unix timestamp of the last time this goal was updated + #[serde(with = "time::serde::timestamp")] + pub updated_at: OffsetDateTime, + /// Whether the graph is currently being updated + pub queued: bool, + /// Number of days until derailment (0 if in beemergency) + pub safebuf: i32, + /// Unix timestamp of the last (explicitly entered) datapoint + #[serde(with = "time::serde::timestamp")] + pub lastday: OffsetDateTime, } #[derive(Debug, Serialize, Deserialize)]