strava_client/apis/
segment_efforts_api.rs

1/*
2 * Strava API v3
3 *
4 * The [Swagger Playground](https://developers.strava.com/playground) is the easiest way to familiarize yourself with the Strava API by submitting HTTP requests and observing the responses before you write any client code. It will show what a response will look like with different endpoints depending on the authorization scope you receive from your athletes. To use the Playground, go to https://www.strava.com/settings/api and change your “Authorization Callback Domain” to developers.strava.com. Please note, we only support Swagger 2.0. There is a known issue where you can only select one scope at a time. For more information, please check the section “client code” at https://developers.strava.com/docs.
5 *
6 * The version of the OpenAPI document: 3.0.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17/// struct for passing parameters to the method [`get_efforts_by_segment_id`]
18#[derive(Clone, Debug, Default)]
19pub struct GetEffortsBySegmentIdParams {
20    /// The identifier of the segment.
21    pub segment_id: i32,
22    /// ISO 8601 formatted date time.
23    pub start_date_local: Option<String>,
24    /// ISO 8601 formatted date time.
25    pub end_date_local: Option<String>,
26    /// Number of items per page. Defaults to 30.
27    pub per_page: Option<i32>
28}
29
30/// struct for passing parameters to the method [`get_segment_effort_by_id`]
31#[derive(Clone, Debug, Default)]
32pub struct GetSegmentEffortByIdParams {
33    /// The identifier of the segment effort.
34    pub id: i64
35}
36
37
38/// struct for typed successes of method [`get_efforts_by_segment_id`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum GetEffortsBySegmentIdSuccess {
42    Status200(Vec<crate::models::DetailedSegmentEffort>),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed successes of method [`get_segment_effort_by_id`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetSegmentEffortByIdSuccess {
50    Status200(crate::models::DetailedSegmentEffort),
51    UnknownValue(serde_json::Value),
52}
53
54/// struct for typed errors of method [`get_efforts_by_segment_id`]
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum GetEffortsBySegmentIdError {
58    DefaultResponse(crate::models::Fault),
59    UnknownValue(serde_json::Value),
60}
61
62/// struct for typed errors of method [`get_segment_effort_by_id`]
63#[derive(Debug, Clone, Serialize, Deserialize)]
64#[serde(untagged)]
65pub enum GetSegmentEffortByIdError {
66    DefaultResponse(crate::models::Fault),
67    UnknownValue(serde_json::Value),
68}
69
70
71/// Returns a set of the authenticated athlete's segment efforts for a given segment.  Requires subscription.
72pub async fn get_efforts_by_segment_id(configuration: &configuration::Configuration, params: GetEffortsBySegmentIdParams) -> Result<ResponseContent<GetEffortsBySegmentIdSuccess>, Error<GetEffortsBySegmentIdError>> {
73    let local_var_configuration = configuration;
74
75    // unbox the parameters
76    let segment_id = params.segment_id;
77    let start_date_local = params.start_date_local;
78    let end_date_local = params.end_date_local;
79    let per_page = params.per_page;
80
81
82    let local_var_client = &local_var_configuration.client;
83
84    let local_var_uri_str = format!("{}/segment_efforts", local_var_configuration.base_path);
85    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
86
87    local_var_req_builder = local_var_req_builder.query(&[("segment_id", &segment_id.to_string())]);
88    if let Some(ref local_var_str) = start_date_local {
89        local_var_req_builder = local_var_req_builder.query(&[("start_date_local", &local_var_str.to_string())]);
90    }
91    if let Some(ref local_var_str) = end_date_local {
92        local_var_req_builder = local_var_req_builder.query(&[("end_date_local", &local_var_str.to_string())]);
93    }
94    if let Some(ref local_var_str) = per_page {
95        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
96    }
97    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
98        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
99    }
100    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
101        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
102    };
103
104    let local_var_req = local_var_req_builder.build()?;
105    let local_var_resp = local_var_client.execute(local_var_req).await?;
106
107    let local_var_status = local_var_resp.status();
108    let local_var_content = local_var_resp.text().await?;
109
110    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
111        let local_var_entity: Option<GetEffortsBySegmentIdSuccess> = serde_json::from_str(&local_var_content).ok();
112        let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
113        Ok(local_var_result)
114    } else {
115        let local_var_entity: Option<GetEffortsBySegmentIdError> = serde_json::from_str(&local_var_content).ok();
116        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
117        Err(Error::ResponseError(local_var_error))
118    }
119}
120
121/// Returns a segment effort from an activity that is owned by the authenticated athlete. Requires subscription.
122pub async fn get_segment_effort_by_id(configuration: &configuration::Configuration, params: GetSegmentEffortByIdParams) -> Result<ResponseContent<GetSegmentEffortByIdSuccess>, Error<GetSegmentEffortByIdError>> {
123    let local_var_configuration = configuration;
124
125    // unbox the parameters
126    let id = params.id;
127
128
129    let local_var_client = &local_var_configuration.client;
130
131    let local_var_uri_str = format!("{}/segment_efforts/{id}", local_var_configuration.base_path, id=id);
132    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
133
134    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
135        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
136    }
137    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
138        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
139    };
140
141    let local_var_req = local_var_req_builder.build()?;
142    let local_var_resp = local_var_client.execute(local_var_req).await?;
143
144    let local_var_status = local_var_resp.status();
145    let local_var_content = local_var_resp.text().await?;
146
147    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
148        let local_var_entity: Option<GetSegmentEffortByIdSuccess> = serde_json::from_str(&local_var_content).ok();
149        let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
150        Ok(local_var_result)
151    } else {
152        let local_var_entity: Option<GetSegmentEffortByIdError> = serde_json::from_str(&local_var_content).ok();
153        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
154        Err(Error::ResponseError(local_var_error))
155    }
156}
157