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.

- added params to the users route

+53 -5
+53 -5
src/strong_api.rs
··· 1 - use std::fmt::format; 1 + use std::fmt; 2 2 use reqwest::{Client, header::{HeaderMap, HeaderName, HeaderValue}, Url}; 3 3 use serde::Deserialize; 4 4 use serde_json::json; ··· 21 21 refresh_token: Option<String>, 22 22 #[serde(rename = "userId")] 23 23 user_id: Option<String>, 24 + } 25 + 26 + pub enum Includes { 27 + Log, 28 + Measurement, 29 + Tag, 30 + Widget, 31 + Template, 32 + Folder, 33 + MeasuredValue 34 + } 35 + 36 + impl fmt::Display for Includes { 37 + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 38 + let value = match self { 39 + Includes::Log => "log", 40 + Includes::Measurement => "measurement", 41 + Includes::Tag => "tag", 42 + Includes::Widget => "widget", 43 + Includes::Template => "template", 44 + Includes::Folder => "folder", 45 + Includes::MeasuredValue => "measuredValue", 46 + }; 47 + write!(f, "{}", value) 48 + } 24 49 } 25 50 26 51 impl StrongApi { ··· 121 146 .send() 122 147 .await?; 123 148 124 - dbg!(response.status()); 125 149 126 150 let response_text = response.text().await?; 127 151 ··· 133 157 Ok(()) 134 158 } 135 159 136 - pub async fn get_user(&self) -> Result<(), Box<dyn std::error::Error>> { 160 + pub async fn get_user(&self, continuation: &str, limit: i16, includes: Vec<Includes>) -> Result<(), Box<dyn std::error::Error>> { 137 161 let user_id = &*self.user_id.clone().unwrap(); 138 - let url = self.url.join(format!("api/users/{user_id}").as_str()).unwrap(); 162 + let mut url = self.url.join(format!("api/users/{user_id}").as_str()).unwrap(); 163 + 164 + url.set_query(Some(&format!("limit={}&continuation={}", limit, continuation))); 165 + 166 + for include in includes { 167 + url.set_query(Some(&format!("{}&include={}", url.query().unwrap(), include))); 168 + } 169 + 170 + dbg!(&url.to_string()); 139 171 140 172 let response = self.client 141 173 .get(url) ··· 144 176 .send() 145 177 .await?; 146 178 147 - dbg!(response.status()); 179 + let response_text = response.text().await?; 180 + 181 + dbg!(response_text); 182 + 183 + Ok(()) 184 + } 185 + 186 + pub async fn get_measurements(&self) -> Result<(), Box<dyn std::error::Error>> { 187 + let user_id = &*self.user_id.clone().unwrap(); 188 + let url = self.url.join(format!("api/measurements/{user_id}").as_str()).unwrap(); 189 + 190 + let response = self.client 191 + .get(url) 192 + .bearer_auth(self.access_token.clone().unwrap()) 193 + .headers(self.headers.clone()) 194 + .send() 195 + .await?; 148 196 149 197 let response_text = response.text().await?; 150 198