Skip to content

Commit 4e50f30

Browse files
authored
support fetching user insights reports (#84)
* support fetching user insights reports * support fetching chart data, rename reports -> user_insights * validate *_date params pre-fetch * add Debug to few types
1 parent e83ad7a commit 4e50f30

9 files changed

Lines changed: 775 additions & 48 deletions

File tree

‎src/apis/mod.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ pub fn urlencode<T: AsRef<str>>(s: T) -> String {
7272
pub mod access_token_service_api;
7373
pub mod api_key_service_api;
7474
pub mod auth_service_api;
75-
pub mod org_service_api;
76-
pub mod user_service_api;
7775
pub mod employee_service_api;
7876
pub mod mfa_service_api;
77+
pub mod org_service_api;
78+
pub(crate) mod user_insights_service_api;
79+
pub mod user_service_api;
7980

8081
pub mod configuration;
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
/*
2+
* propelauth
3+
*
4+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5+
*
6+
* The version of the OpenAPI document: 0.1.0
7+
*
8+
* Generated by: https://openapi-generator.tech
9+
*/
10+
11+
use reqwest;
12+
13+
use super::{configuration, Error};
14+
use crate::apis::ResponseContent;
15+
use crate::models::user_insights::{
16+
ChartData, ChartMetric, FetchChartDataQuery, FetchReportQuery, OrgReport, OrgReportType,
17+
UserReportPage, UserReportType,
18+
};
19+
use crate::propelauth::auth::AUTH_HOSTNAME_HEADER;
20+
21+
/// struct for typed errors of methods [`fetch_user_report`] or [`fetch_org_report`]
22+
#[derive(Debug, Clone, Serialize, Deserialize)]
23+
#[serde(untagged)]
24+
pub enum FetchUserInsightsDataRequestError {
25+
Status401(serde_json::Value),
26+
Status400(serde_json::Value),
27+
Status429(serde_json::Value),
28+
UnknownValue(serde_json::Value),
29+
}
30+
31+
pub(crate) async fn fetch_user_report(
32+
configuration: &configuration::Configuration,
33+
report_key: UserReportType,
34+
params: FetchReportQuery,
35+
) -> Result<UserReportPage, Error<FetchUserInsightsDataRequestError>> {
36+
let local_var_configuration = configuration;
37+
38+
let local_var_client = &local_var_configuration.client;
39+
40+
let local_var_uri_str = format!(
41+
"{}/api/backend/v1/user_report/{report_key}",
42+
local_var_configuration.base_path,
43+
report_key = report_key.as_str(),
44+
);
45+
let mut local_var_req_builder =
46+
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
47+
48+
local_var_req_builder = local_var_req_builder.query(&params);
49+
50+
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
51+
local_var_req_builder =
52+
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
53+
}
54+
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
55+
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
56+
};
57+
local_var_req_builder = local_var_req_builder.header(
58+
AUTH_HOSTNAME_HEADER,
59+
local_var_configuration.auth_hostname.to_owned(),
60+
);
61+
62+
let local_var_req = local_var_req_builder.build()?;
63+
let local_var_resp = local_var_client.execute(local_var_req).await?;
64+
65+
let local_var_status = local_var_resp.status();
66+
let local_var_content = local_var_resp.text().await?;
67+
68+
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
69+
serde_json::from_str(&local_var_content).map_err(Error::from)
70+
} else {
71+
let local_var_entity: Option<FetchUserInsightsDataRequestError> =
72+
serde_json::from_str(&local_var_content).ok();
73+
let local_var_error: crate::apis::ResponseContent<FetchUserInsightsDataRequestError> =
74+
ResponseContent {
75+
status: local_var_status,
76+
content: local_var_content,
77+
entity: local_var_entity,
78+
};
79+
Err(Error::ResponseError(local_var_error))
80+
}
81+
}
82+
83+
pub(crate) async fn fetch_org_report(
84+
configuration: &configuration::Configuration,
85+
report_key: OrgReportType,
86+
params: FetchReportQuery,
87+
) -> Result<OrgReport, Error<FetchUserInsightsDataRequestError>> {
88+
let local_var_configuration = configuration;
89+
90+
let local_var_client = &local_var_configuration.client;
91+
92+
let local_var_uri_str = format!(
93+
"{}/api/backend/v1/org_report/{report_key}",
94+
local_var_configuration.base_path,
95+
report_key = report_key.as_str(),
96+
);
97+
let mut local_var_req_builder =
98+
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
99+
100+
local_var_req_builder = local_var_req_builder.query(&params);
101+
102+
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
103+
local_var_req_builder =
104+
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
105+
}
106+
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
107+
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
108+
};
109+
local_var_req_builder = local_var_req_builder.header(
110+
AUTH_HOSTNAME_HEADER,
111+
local_var_configuration.auth_hostname.to_owned(),
112+
);
113+
114+
let local_var_req = local_var_req_builder.build()?;
115+
let local_var_resp = local_var_client.execute(local_var_req).await?;
116+
117+
let local_var_status = local_var_resp.status();
118+
let local_var_content = local_var_resp.text().await?;
119+
120+
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
121+
serde_json::from_str(&local_var_content).map_err(Error::from)
122+
} else {
123+
let local_var_entity: Option<FetchUserInsightsDataRequestError> =
124+
serde_json::from_str(&local_var_content).ok();
125+
let local_var_error: crate::apis::ResponseContent<FetchUserInsightsDataRequestError> =
126+
ResponseContent {
127+
status: local_var_status,
128+
content: local_var_content,
129+
entity: local_var_entity,
130+
};
131+
Err(Error::ResponseError(local_var_error))
132+
}
133+
}
134+
135+
pub(crate) async fn fetch_chart_metric_data(
136+
configuration: &configuration::Configuration,
137+
chart_metric: ChartMetric,
138+
params: FetchChartDataQuery,
139+
) -> Result<ChartData, Error<FetchUserInsightsDataRequestError>> {
140+
let local_var_configuration = configuration;
141+
142+
let local_var_client = &local_var_configuration.client;
143+
144+
let local_var_uri_str = format!(
145+
"{}/api/backend/v1/chart_metrics/{chart_metric}",
146+
local_var_configuration.base_path,
147+
chart_metric = chart_metric.as_str(),
148+
);
149+
let mut local_var_req_builder =
150+
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
151+
152+
local_var_req_builder = local_var_req_builder.query(&params);
153+
154+
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
155+
local_var_req_builder =
156+
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
157+
}
158+
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
159+
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
160+
};
161+
local_var_req_builder = local_var_req_builder.header(
162+
AUTH_HOSTNAME_HEADER,
163+
local_var_configuration.auth_hostname.to_owned(),
164+
);
165+
166+
let local_var_req = local_var_req_builder.build()?;
167+
let local_var_resp = local_var_client.execute(local_var_req).await?;
168+
169+
let local_var_status = local_var_resp.status();
170+
let local_var_content = local_var_resp.text().await?;
171+
172+
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
173+
serde_json::from_str(&local_var_content).map_err(Error::from)
174+
} else {
175+
let local_var_entity: Option<FetchUserInsightsDataRequestError> =
176+
serde_json::from_str(&local_var_content).ok();
177+
let local_var_error: crate::apis::ResponseContent<FetchUserInsightsDataRequestError> =
178+
ResponseContent {
179+
status: local_var_status,
180+
content: local_var_content,
181+
entity: local_var_entity,
182+
};
183+
Err(Error::ResponseError(local_var_error))
184+
}
185+
}

‎src/models/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ pub mod user_ids_query;
8989
pub use self::user_ids_query::UserIdsQuery;
9090
pub mod user_in_org;
9191
pub use self::user_in_org::UserInOrg;
92+
pub mod user_insights;
9293
pub mod user_metadata;
9394
pub use self::user_metadata::UserMetadata;
9495
pub mod user_paged_response;

0 commit comments

Comments
 (0)