diff --git a/Cargo.toml b/Cargo.toml index 2234e32..2df04c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] +resolver = "3" members = [ "strong-api-lib", "strong-api-dump" diff --git a/strong-api-dump/src/main.rs b/strong-api-dump/src/main.rs index ac833e5..042ad2e 100644 --- a/strong-api-dump/src/main.rs +++ b/strong-api-dump/src/main.rs @@ -44,8 +44,11 @@ async fn main() -> Result<(), Box> { let response_text = std::fs::read_to_string("response.json")?; let user: UserResponse = serde_json::from_str(&response_text)?; - let workouts = DataTransformer - .get_measurements_from_logs(&user.embedded.log, &Some(measurements_response)) + let data_transformer = DataTransformer::new() + .with_measurements_response(measurements_response); + + let workouts = data_transformer + .get_measurements_from_logs(&user.embedded.log) .expect("Couldn't read workouts"); println!("Workout count: {}", workouts.len()); diff --git a/strong-api-lib/src/data_transformer.rs b/strong-api-lib/src/data_transformer.rs index 5060005..502ba7e 100644 --- a/strong-api-lib/src/data_transformer.rs +++ b/strong-api-lib/src/data_transformer.rs @@ -26,13 +26,25 @@ pub struct Workout { pub exercises: Vec, } -pub struct DataTransformer; +pub struct DataTransformer { + measurements_response: Option +} impl DataTransformer { + pub fn new() -> Self { + Self { + measurements_response: None + } + } + + pub fn with_measurements_response(mut self, with_measurements_response: MeasurementsResponse) -> Self { + self.measurements_response = Some(with_measurements_response); + self + } + pub fn get_measurements_from_logs( &self, - logs_option: &Option>, - measurements_response: &Option, + logs_option: &Option> ) -> Result, serde_json::Error> { let logs = match logs_option { Some(logs) => logs, @@ -41,7 +53,7 @@ impl DataTransformer { //if measurements set, create lookup table let mut lookup: HashMap = HashMap::new(); - if let Some(measurements) = measurements_response { + if let Some(measurements) = &self.measurements_response { println!( "Measurements count: {}/{}", measurements.embedded.measurements.len(), diff --git a/strong-api-lib/src/strong_api.rs b/strong-api-lib/src/strong_api.rs index f7476c6..55f2b42 100644 --- a/strong-api-lib/src/strong_api.rs +++ b/strong-api-lib/src/strong_api.rs @@ -103,7 +103,7 @@ impl StrongApi { } } - /// Logs in to the Strong backend using the provided username and password. + /// Logs in to the Strong backend using the provided username/e-mail and password. pub async fn login( &mut self, username: &str, @@ -163,6 +163,7 @@ impl StrongApi { Ok(()) } + /// Refreshes the access token using tokens passed as parameters. #[cfg(feature = "full")] pub async fn refresh_by_tokens( &mut self, @@ -192,6 +193,10 @@ impl StrongApi { Ok(()) } + /// Gets the user data for the currently logged-in user. + /// The `continuation` parameter is used to paginate the results. + /// The `limit` parameter specifies the number of results to return. + /// The `includes` parameter specifies which related entities to include in the response. See the `Includes` enum for possible values. pub async fn get_user( &self, continuation: &str, @@ -234,6 +239,10 @@ impl StrongApi { Ok(parsed) } + /// Measurements are exercises that are available in the Strong app. + /// This function retrieves a list of measurements. + /// The `page` parameter is used to paginate the results. + /// Check the measurements.total and the length of measurements.embedded.measurements to determine if there are more pages. pub async fn get_measurements( &self, page: i8, @@ -276,7 +285,7 @@ impl StrongApi { Ok(response) } - pub async fn get_logs(&self) -> Result<(), Box> { + pub async fn get_logs_raw(&self) -> Result> { let user_id = self.user_id.as_ref().ok_or("Missing user id")?; let url = self.url.join(&format!("api/logs/{user_id}"))?; let response = self @@ -288,7 +297,6 @@ impl StrongApi { .await?; let response_text = response.text().await?; - eprintln!("Logs response: {}", response_text); - Ok(()) + Ok(response_text) } }