Skip to main content

data_for_seo/api/serp/
mod.rs

1use crate::{DataForSeoApiResponse, DataForSeoClient};
2use serde::{Deserialize, Serialize};
3
4mod baidu;
5mod bing;
6mod google;
7mod naver;
8mod seznam;
9mod yahoo;
10mod youtube;
11
12pub use baidu::*;
13pub use bing::*;
14pub use google::*;
15pub use naver::*;
16pub use seznam::*;
17pub use yahoo::*;
18pub use youtube::*;
19
20/// SERP data model.
21pub struct SerpApi<'a> {
22    client: &'a DataForSeoClient,
23}
24
25impl DataForSeoClient {
26    /// Returns the SERP API domain entry point.
27    /// See <https://docs.dataforseo.com/v3/serp/overview/>.
28    pub fn serp(&self) -> SerpApi<'_> {
29        SerpApi { client: self }
30    }
31}
32
33impl SerpApi<'_> {
34    /// Lists all locations supported across the SERP engines.
35    pub async fn locations(&self) -> DataForSeoApiResponse<SerpApiLocation> {
36        self.client.http_get("/v3/serp/locations").await
37    }
38    /// Lists locations supported by the given search engine.
39    pub async fn locations_se(&self, se: &str) -> DataForSeoApiResponse<SerpApiLocation> {
40        self.client
41            .http_get(format!("/v3/serp/{}/locations", se).as_str())
42            .await
43    }
44    /// Lists supported locations within the given country.
45    pub async fn locations_country(&self, country: &str) -> DataForSeoApiResponse<SerpApiLocation> {
46        self.client
47            .http_get(format!("/v3/serp/locations/{}", country).as_str())
48            .await
49    }
50    /// Lists locations within a country for the given search engine.
51    pub async fn locations_country_se(
52        &self,
53        se: &str,
54        country: &str,
55    ) -> DataForSeoApiResponse<SerpApiLocation> {
56        self.client
57            .http_get(format!("/v3/serp/{}/locations/{}", se, country).as_str())
58            .await
59    }
60    /// Lists completed tasks that are ready to be collected.
61    pub async fn task_ready(&self) -> DataForSeoApiResponse<SerpApiTaskReadyResult> {
62        self.client.http_get("/v3/serp/tasks_ready").await
63    }
64    /// Lists completed tasks for the given search engine.
65    pub async fn task_ready_se(&self, se: &str) -> DataForSeoApiResponse<SerpApiTaskReadyResult> {
66        self.client
67            .http_get(format!("/v3/serp/{}/tasks_ready", se).as_str())
68            .await
69    }
70    /// Lists tasks that were force-fixed by DataForSEO.
71    pub async fn task_fixed(&self) -> DataForSeoApiResponse<SerpApiTaskReadyResult> {
72        self.client.http_get("/v3/serp/tasks_fixed").await
73    }
74    /// Lists force-fixed tasks for the given search engine.
75    pub async fn task_fixed_se(&self, se: &str) -> DataForSeoApiResponse<SerpApiTaskReadyResult> {
76        self.client
77            .http_get(format!("/v3/serp/{}/tasks_fixed", se).as_str())
78            .await
79    }
80}
81
82/// A completed task listed by the Tasks Ready endpoint.
83/// See <https://docs.dataforseo.com/v3/serp/google/organic/tasks_ready/>.
84#[derive(Debug, Default, Serialize, Deserialize, Clone)]
85pub struct SerpApiTaskReadyResult {
86    /// Identifier of the completed task, UUID format.
87    pub id: Option<String>,
88    /// Search engine the task was posted for (e.g. `google`).
89    pub se: Option<String>,
90    /// Search engine type (e.g. `organic`, `maps`).
91    pub se_type: Option<String>,
92    /// Date and time when the task was posted, UTC.
93    pub date_posted: Option<String>,
94    /// User-defined tag echoed from the task request.
95    pub tag: Option<String>,
96    /// URL for collecting the results in the regular format, if available.
97    pub endpoint_regular: Option<String>,
98    /// URL for collecting the results in the advanced format, if available.
99    pub endpoint_advanced: Option<String>,
100    /// URL for collecting the results in the HTML format, if available.
101    pub endpoint_html: Option<String>,
102}
103
104/// Location SERP data model.
105#[derive(Debug, Default, Serialize, Deserialize, Clone)]
106pub struct SerpApiLocation {
107    /// DataForSEO location code the search was run for.
108    pub location_code: Option<i32>,
109    /// Full location name (e.g. "London,England,United Kingdom").
110    pub location_name: Option<String>,
111    /// Location code of the parent region, if any.
112    pub location_code_parent: Option<i32>,
113    /// ISO country code of the location.
114    pub country_iso_code: Option<String>,
115    /// Type of the location (e.g. City, Region, Country).
116    pub location_type: Option<String>,
117}