diff options
Diffstat (limited to 'src/strava.rs')
-rw-r--r-- | src/strava.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/strava.rs b/src/strava.rs index 7df728c..6be5466 100644 --- a/src/strava.rs +++ b/src/strava.rs @@ -8,6 +8,38 @@ use serde::Serialize; use serde_json::from_value; use serde_json::Value; +pub trait StravaApi { + fn get<T: Serialize + ?Sized>(&self, method: &str, access_token: &str, parasm: &T) -> Result<Value, Error>; +} + +pub struct StravaImpl { + client: reqwest::blocking::Client, + base_url: String, +} + +impl StravaImpl { + pub fn new() -> StravaImpl { + StravaImpl { + client: reqwest::blocking::Client::new(), + base_url: "https://www.strava.com/api/v3".to_string(), + } + } +} + +impl StravaApi for StravaImpl { + fn get<T: Serialize + ?Sized>(&self, method: &str, access_token: &str, + params: &T) -> Result<Value, Error> { + let uri = format!("{}{}", self.base_url, method); + let response = self.client.get(&uri) + .bearer_auth(access_token) + .query(params) + .send()?; + info!("StravaApi::get({}) returned {:?}", method, response); + let json = response.json()?; + Ok(json) + } +} + #[derive(Serialize, Deserialize, Debug)] pub struct AthleteSummary { id: i64, |