Skip to main content

data_for_seo/api/serp/google/
maps.rs

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