Skip to main content

data_for_seo/api/serp/google/
event.rs

1use crate::entity::SerpApiGoogleEventAdvance;
2use crate::{DataForSeoApiResponse, SerpApiGoogle, SerpApiLocation, SerpApiTaskReadyResult};
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6/// Google Events SERP endpoint.
7/// <https://docs.dataforseo.com/v3/serp/google/events/overview/>
8impl SerpApiGoogle<'_> {
9    /// <https://docs.dataforseo.com/v3/serp/google/events/locations/>
10    pub async fn events_locations(&self) -> DataForSeoApiResponse<SerpApiLocation> {
11        self.client.serp().locations_se("google/events").await
12    }
13    /// <https://docs.dataforseo.com/v3/serp/google/events/task_post/>
14    pub async fn events_task_post(
15        &self,
16        data: Vec<SerpApiGoogleEventsTaskPostRequest>,
17    ) -> DataForSeoApiResponse<Value> {
18        self.client
19            .http_post("/v3/serp/google/events/task_post", &data)
20            .await
21    }
22    /// <https://docs.dataforseo.com/v3/serp/google/events/tasks_ready/>
23    pub async fn events_tasks_ready(&self) -> DataForSeoApiResponse<SerpApiTaskReadyResult> {
24        self.client.serp().task_ready_se("google/events").await
25    }
26    /// <https://docs.dataforseo.com/v3/serp/google/events/tasks_fixed/>
27    pub async fn events_tasks_fixed(&self) -> DataForSeoApiResponse<SerpApiTaskReadyResult> {
28        self.client.serp().task_fixed_se("google/events").await
29    }
30    /// <https://docs.dataforseo.com/v3/serp/google/events/task_get/advanced/>
31    pub async fn events_task_get_advanced(
32        &self,
33        id: &str,
34    ) -> DataForSeoApiResponse<SerpApiGoogleEventAdvance> {
35        self.client
36            .http_get(format!("/v3/serp/google/events/task_get/advanced/{id}").as_str())
37            .await
38    }
39    /// <https://docs.dataforseo.com/v3/serp/google/events/live/advanced/>
40    pub async fn events_live_advanced(
41        &self,
42        data: Vec<SerpApiGoogleEventsTaskPostRequest>,
43    ) -> DataForSeoApiResponse<SerpApiGoogleEventAdvance> {
44        self.client
45            .http_post("/v3/serp/google/events/live/advanced", &data)
46            .await
47    }
48}
49
50/// Request body for Google Events task_post / live.
51/// See <https://docs.dataforseo.com/v3/serp/google/events/task_post/>.
52#[derive(Debug, Default, Serialize, Deserialize, Clone)]
53pub struct SerpApiGoogleEventsTaskPostRequest {
54    /// Search term the result was returned for.
55    pub keyword: String,
56    /// Task execution priority: 1 (normal) or 2 (high).
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub priority: Option<i32>,
59    /// Full location name (e.g. "London,England,United Kingdom").
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub location_name: Option<String>,
62    /// DataForSEO location code the search was run for.
63    pub location_code: i32,
64    /// GPS coordinates the search was run for ("lat,lng,zoom").
65    #[serde(skip_serializing_if = "Option::is_none")]
66    pub location_coordinate: Option<String>,
67    /// Full language name of the search.
68    #[serde(skip_serializing_if = "Option::is_none")]
69    pub language_name: Option<String>,
70    /// Language code the search was run for.
71    pub language_code: String,
72    /// Date range.
73    #[serde(skip_serializing_if = "Option::is_none")]
74    pub date_range: Option<String>,
75    /// Os.
76    #[serde(skip_serializing_if = "Option::is_none")]
77    pub os: Option<String>,
78    /// Search-engine domain the results were taken from.
79    #[serde(skip_serializing_if = "Option::is_none")]
80    pub se_domain: Option<String>,
81    /// Depth.
82    #[serde(skip_serializing_if = "Option::is_none")]
83    pub depth: Option<i32>,
84    /// Max crawl pages.
85    #[serde(skip_serializing_if = "Option::is_none")]
86    pub max_crawl_pages: Option<i32>,
87    /// User-defined identifier echoed back on the result.
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub tag: Option<String>,
90    /// URL of the postback.
91    #[serde(skip_serializing_if = "Option::is_none")]
92    pub postback_url: Option<String>,
93    /// Postback data.
94    #[serde(skip_serializing_if = "Option::is_none")]
95    pub postback_data: Option<String>,
96    /// URL of the pingback.
97    #[serde(skip_serializing_if = "Option::is_none")]
98    pub pingback_url: Option<String>,
99}
100
101impl SerpApiGoogleEventsTaskPostRequest {
102    /// Creates a request with the required language and location codes.
103    /// Set `keyword` and any optional fields before sending.
104    pub fn new(language_code: String, location_code: i32) -> Self {
105        SerpApiGoogleEventsTaskPostRequest {
106            language_code,
107            location_code,
108            ..SerpApiGoogleEventsTaskPostRequest::default()
109        }
110    }
111}