Sync your own workout data from your "Strong" app
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

builder pattern for DataTransformer

+34 -10
+1
Cargo.toml
··· 1 1 [workspace] 2 + resolver = "3" 2 3 members = [ 3 4 "strong-api-lib", 4 5 "strong-api-dump"
+5 -2
strong-api-dump/src/main.rs
··· 44 44 let response_text = std::fs::read_to_string("response.json")?; 45 45 let user: UserResponse = serde_json::from_str(&response_text)?; 46 46 47 - let workouts = DataTransformer 48 - .get_measurements_from_logs(&user.embedded.log, &Some(measurements_response)) 47 + let data_transformer = DataTransformer::new() 48 + .with_measurements_response(measurements_response); 49 + 50 + let workouts = data_transformer 51 + .get_measurements_from_logs(&user.embedded.log) 49 52 .expect("Couldn't read workouts"); 50 53 51 54 println!("Workout count: {}", workouts.len());
+16 -4
strong-api-lib/src/data_transformer.rs
··· 26 26 pub exercises: Vec<Exercise>, 27 27 } 28 28 29 - pub struct DataTransformer; 29 + pub struct DataTransformer { 30 + measurements_response: Option<MeasurementsResponse> 31 + } 30 32 31 33 impl DataTransformer { 34 + pub fn new() -> Self { 35 + Self { 36 + measurements_response: None 37 + } 38 + } 39 + 40 + pub fn with_measurements_response(mut self, with_measurements_response: MeasurementsResponse) -> Self { 41 + self.measurements_response = Some(with_measurements_response); 42 + self 43 + } 44 + 32 45 pub fn get_measurements_from_logs( 33 46 &self, 34 - logs_option: &Option<Vec<Log>>, 35 - measurements_response: &Option<MeasurementsResponse>, 47 + logs_option: &Option<Vec<Log>> 36 48 ) -> Result<Vec<Workout>, serde_json::Error> { 37 49 let logs = match logs_option { 38 50 Some(logs) => logs, ··· 41 53 42 54 //if measurements set, create lookup table 43 55 let mut lookup: HashMap<String, Measurement> = HashMap::new(); 44 - if let Some(measurements) = measurements_response { 56 + if let Some(measurements) = &self.measurements_response { 45 57 println!( 46 58 "Measurements count: {}/{}", 47 59 measurements.embedded.measurements.len(),
+12 -4
strong-api-lib/src/strong_api.rs
··· 103 103 } 104 104 } 105 105 106 - /// Logs in to the Strong backend using the provided username and password. 106 + /// Logs in to the Strong backend using the provided username/e-mail and password. 107 107 pub async fn login( 108 108 &mut self, 109 109 username: &str, ··· 163 163 Ok(()) 164 164 } 165 165 166 + /// Refreshes the access token using tokens passed as parameters. 166 167 #[cfg(feature = "full")] 167 168 pub async fn refresh_by_tokens( 168 169 &mut self, ··· 192 193 Ok(()) 193 194 } 194 195 196 + /// Gets the user data for the currently logged-in user. 197 + /// The `continuation` parameter is used to paginate the results. 198 + /// The `limit` parameter specifies the number of results to return. 199 + /// The `includes` parameter specifies which related entities to include in the response. See the `Includes` enum for possible values. 195 200 pub async fn get_user( 196 201 &self, 197 202 continuation: &str, ··· 234 239 Ok(parsed) 235 240 } 236 241 242 + /// Measurements are exercises that are available in the Strong app. 243 + /// This function retrieves a list of measurements. 244 + /// The `page` parameter is used to paginate the results. 245 + /// Check the measurements.total and the length of measurements.embedded.measurements to determine if there are more pages. 237 246 pub async fn get_measurements( 238 247 &self, 239 248 page: i8, ··· 276 285 Ok(response) 277 286 } 278 287 279 - pub async fn get_logs(&self) -> Result<(), Box<dyn std::error::Error>> { 288 + pub async fn get_logs_raw(&self) -> Result<String, Box<dyn std::error::Error>> { 280 289 let user_id = self.user_id.as_ref().ok_or("Missing user id")?; 281 290 let url = self.url.join(&format!("api/logs/{user_id}"))?; 282 291 let response = self ··· 288 297 .await?; 289 298 let response_text = response.text().await?; 290 299 291 - eprintln!("Logs response: {}", response_text); 292 - Ok(()) 300 + Ok(response_text) 293 301 } 294 302 }