google_analytics_api_ga4/
lib.rs

1mod error;
2mod http;
3mod check_compatibility;
4mod run_report;
5pub mod types;
6mod run_realtime_report;
7mod get_metadata;
8mod batch_run_pivot_reports;
9mod batch_run_reports;
10mod run_pivot_reports;
11
12use serde_json::json;
13use crate::{GoogleApiError};
14pub use run_report::*;
15pub use error::*;
16pub use check_compatibility::*;
17pub use run_realtime_report::*;
18pub use get_metadata::*;
19use crate::batch_run_pivot_reports::{BatchRunPivotReportRequest, BatchRunPivotReportRequestBody, BatchRunPivotReportResponse};
20use crate::batch_run_reports::{BatchRunReportRequestBody};
21use crate::http::HttpClient;
22use crate::types::RunReportResponse;
23
24
25pub struct AnalyticsDataApi {}
26
27impl AnalyticsDataApi {
28    /// https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/batchRunPivotReports
29    pub async fn batch_run_pivot_reports(token: &str, property: &str, requests: Vec<BatchRunPivotReportRequest>) -> Result<BatchRunPivotReportResponse, GoogleApiError> {
30        Ok(HttpClient::post(
31            token,
32            format!(r#"https://analyticsdata.googleapis.com/v1beta/properties/{}:batchRunPivotReports"#, property, ).as_str(),
33            BatchRunPivotReportRequestBody {
34                requests
35            },
36        ).await?)
37    }
38    /// https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/batchRunReports
39    pub async fn batch_run_reports(token: &str, property: &str, requests: Vec<RunReportRequest>) -> Result<RunReportResponse, GoogleApiError> {
40        Ok(HttpClient::post(
41            token,
42            format!(r#"https://analyticsdata.googleapis.com/v1beta/properties/{}:batchRunReports"#, property, ).as_str(),
43            BatchRunReportRequestBody {
44                requests
45            },
46        ).await?)
47    }
48    /// https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/checkCompatibility
49    pub async fn check_compatibility(token: &str, property: &str, request: CheckCompatibilityRequest) -> Result<CheckCompatibilityResponse, GoogleApiError> {
50        Ok(HttpClient::post(
51            token,
52            format!(r#"https://analyticsdata.googleapis.com/v1beta/properties/{}:checkCompatibility"#, property, ).as_str(),
53            request,
54        ).await?)
55    }
56    /// https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/getMetadata
57    pub async fn get_metadata(token: &str, property: &str) -> Result<GetMetadataResponse, GoogleApiError> {
58        let data = HttpClient::get(
59            token,
60            format!(r#"https://analyticsdata.googleapis.com/v1beta/properties/{}:metadata"#, property).as_str(),
61            json!({}),
62        ).await?;
63        Ok(data)
64    }
65    /// https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runPivotReport
66    pub async fn run_pivot_report(token: &str, property: &str, request: CheckCompatibilityRequest) -> Result<CheckCompatibilityResponse, GoogleApiError> {
67        let data = HttpClient::post(
68            token,
69            format!(r#"https://analyticsdata.googleapis.com/v1beta/properties/{}:runPivotReport"#, property).as_str(),
70            request,
71        ).await?;
72        Ok(data)
73    }
74    /// https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runRealtimeReport
75    pub async fn run_realtime_report(token: &str, property: &str, request: RunRealtimeReportRequest) -> Result<RunReportResponse, GoogleApiError> {
76        let data = HttpClient::post(
77            token,
78            format!(r#"https://analyticsdata.googleapis.com/v1beta/properties/{}:runRealtimeReport"#, property).as_str(),
79            request,
80        ).await?;
81        Ok(data)
82    }
83    /// https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport
84    pub async fn run_report(token: &str, property: &str, request: RunReportRequest) -> Result<RunReportResponse, GoogleApiError> {
85        let data = HttpClient::post(
86            token,
87            format!(r#"https://analyticsdata.googleapis.com/v1beta/properties/{}:runReport"#, property).as_str(),
88            request,
89        ).await?;
90        Ok(data)
91    }
92}
93
94
95pub struct BatchRunReportsRequestBody {}
96
97