google_analytics_api_ga4/
lib.rs1#![doc = include_str!("../README.md")]
2
3mod batch_run_pivot_reports;
4mod batch_run_reports;
5mod check_compatibility;
6mod error;
7mod get_metadata;
8mod http;
9mod run_pivot_reports;
10mod run_realtime_report;
11mod run_report;
12pub mod types;
13
14pub use batch_run_pivot_reports::BatchRunPivotReportsResponse;
15pub use batch_run_reports::BatchRunReportsResponse;
16pub use check_compatibility::*;
17pub use error::*;
18pub use get_metadata::*;
19pub use run_pivot_reports::*;
20pub use run_realtime_report::*;
21pub use run_report::*;
22
23use crate::batch_run_pivot_reports::BatchRunPivotReportsRequestBody;
24use crate::batch_run_reports::BatchRunReportsRequestBody;
25use crate::http::HttpClient;
26use crate::types::{RunPivotReportResponse, RunReportResponse};
27
28const ENDPOINT: &str = "https://analyticsdata.googleapis.com/v1beta";
29
30pub struct AnalyticsDataApi {}
35
36impl AnalyticsDataApi {
37 pub async fn batch_run_pivot_reports(
41 token: &str,
42 property: &str,
43 requests: Vec<RunPivotReportRequest>,
44 ) -> Result<BatchRunPivotReportsResponse, GoogleApiError> {
45 HttpClient::post(
46 token,
47 format!("{}/properties/{}:batchRunPivotReports", ENDPOINT, property).as_str(),
48 BatchRunPivotReportsRequestBody { requests },
49 )
50 .await
51 }
52 pub async fn batch_run_reports(
56 token: &str,
57 property: &str,
58 requests: Vec<RunReportRequest>,
59 ) -> Result<BatchRunReportsResponse, GoogleApiError> {
60 HttpClient::post(
61 token,
62 format!("{}/properties/{}:batchRunReports", ENDPOINT, property).as_str(),
63 BatchRunReportsRequestBody { requests },
64 )
65 .await
66 }
67 pub async fn check_compatibility(
71 token: &str,
72 property: &str,
73 request: CheckCompatibilityRequest,
74 ) -> Result<CheckCompatibilityResponse, GoogleApiError> {
75 HttpClient::post(
76 token,
77 format!("{}/properties/{}:checkCompatibility", ENDPOINT, property).as_str(),
78 request,
79 )
80 .await
81 }
82 pub async fn get_metadata(
86 token: &str,
87 property: &str,
88 ) -> Result<GetMetadataResponse, GoogleApiError> {
89 HttpClient::get(
90 token,
91 format!("{}/properties/{}/metadata", ENDPOINT, property).as_str(),
92 )
93 .await
94 }
95 pub async fn run_pivot_report(
99 token: &str,
100 property: &str,
101 request: RunPivotReportRequest,
102 ) -> Result<RunPivotReportResponse, GoogleApiError> {
103 HttpClient::post(
104 token,
105 format!("{}/properties/{}:runPivotReport", ENDPOINT, property).as_str(),
106 request,
107 )
108 .await
109 }
110 pub async fn run_realtime_report(
114 token: &str,
115 property: &str,
116 request: RunRealtimeReportRequest,
117 ) -> Result<RunReportResponse, GoogleApiError> {
118 HttpClient::post(
119 token,
120 format!("{}/properties/{}:runRealtimeReport", ENDPOINT, property).as_str(),
121 request,
122 )
123 .await
124 }
125 pub async fn run_report(
129 token: &str,
130 property: &str,
131 request: RunReportRequest,
132 ) -> Result<RunReportResponse, GoogleApiError> {
133 HttpClient::post(
134 token,
135 format!("{}/properties/{}:runReport", ENDPOINT, property).as_str(),
136 request,
137 )
138 .await
139 }
140}