1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
mod error;
mod http;
mod check_compatibility;
mod run_report;
pub mod types;
mod run_realtime_report;
mod get_metadata;
mod batch_run_pivot_reports;
mod batch_run_reports;
mod run_pivot_reports;

use serde_json::json;
use crate::{GoogleApiError};
pub use run_report::*;
pub use error::*;
pub use check_compatibility::*;
pub use run_realtime_report::*;
pub use get_metadata::*;
use crate::batch_run_pivot_reports::{BatchRunPivotReportRequest, BatchRunPivotReportRequestBody, BatchRunPivotReportResponse};
use crate::batch_run_reports::{BatchRunReportRequestBody};
use crate::http::HttpClient;
use crate::types::RunReportResponse;


pub struct AnalyticsDataApi {}

impl AnalyticsDataApi {
    /// https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/batchRunPivotReports
    pub async fn batch_run_pivot_reports(token: &str, property: &str, requests: Vec<BatchRunPivotReportRequest>) -> Result<BatchRunPivotReportResponse, GoogleApiError> {
        Ok(HttpClient::post(
            token,
            format!(r#"https://analyticsdata.googleapis.com/v1beta/properties/{}:batchRunPivotReports"#, property, ).as_str(),
            BatchRunPivotReportRequestBody {
                requests
            },
        ).await?)
    }
    /// https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/batchRunReports
    pub async fn batch_run_reports(token: &str, property: &str, requests: Vec<RunReportRequest>) -> Result<RunReportResponse, GoogleApiError> {
        Ok(HttpClient::post(
            token,
            format!(r#"https://analyticsdata.googleapis.com/v1beta/properties/{}:batchRunReports"#, property, ).as_str(),
            BatchRunReportRequestBody {
                requests
            },
        ).await?)
    }
    /// https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/checkCompatibility
    pub async fn check_compatibility(token: &str, property: &str, request: CheckCompatibilityRequest) -> Result<CheckCompatibilityResponse, GoogleApiError> {
        Ok(HttpClient::post(
            token,
            format!(r#"https://analyticsdata.googleapis.com/v1beta/properties/{}:checkCompatibility"#, property, ).as_str(),
            request,
        ).await?)
    }
    /// https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/getMetadata
    pub async fn get_metadata(token: &str, property: &str) -> Result<GetMetadataResponse, GoogleApiError> {
        let data = HttpClient::get(
            token,
            format!(r#"https://analyticsdata.googleapis.com/v1beta/properties/{}:metadata"#, property).as_str(),
            json!({}),
        ).await?;
        Ok(data)
    }
    /// https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runPivotReport
    pub async fn run_pivot_report(token: &str, property: &str, request: CheckCompatibilityRequest) -> Result<CheckCompatibilityResponse, GoogleApiError> {
        let data = HttpClient::post(
            token,
            format!(r#"https://analyticsdata.googleapis.com/v1beta/properties/{}:runPivotReport"#, property).as_str(),
            request,
        ).await?;
        Ok(data)
    }
    /// https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runRealtimeReport
    pub async fn run_realtime_report(token: &str, property: &str, request: RunRealtimeReportRequest) -> Result<RunReportResponse, GoogleApiError> {
        let data = HttpClient::post(
            token,
            format!(r#"https://analyticsdata.googleapis.com/v1beta/properties/{}:runRealtimeReport"#, property).as_str(),
            request,
        ).await?;
        Ok(data)
    }
    /// https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport
    pub async fn run_report(token: &str, property: &str, request: RunReportRequest) -> Result<RunReportResponse, GoogleApiError> {
        let data = HttpClient::post(
            token,
            format!(r#"https://analyticsdata.googleapis.com/v1beta/properties/{}:runReport"#, property).as_str(),
            request,
        ).await?;
        Ok(data)
    }
}


pub struct BatchRunReportsRequestBody {}