data_for_seo/api/serp/
mod.rs

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
98
99
100
101
102
103
104
105
106
use crate::{DataForSeoApiResponse, DataForSeoClient};
use serde::{Deserialize, Serialize};

mod bing;
mod google;

pub use bing::*;
pub use google::*;

pub struct SerpApi<'a> {
    client: &'a DataForSeoClient,
}

impl DataForSeoClient {
    /// https://developers.line.biz/ja/reference/messaging-api/#get-bot-info
    pub fn serp(&self) -> SerpApi {
        SerpApi { client: self }
    }
}

impl SerpApi<'_> {
    pub async fn locations(&self) -> DataForSeoApiResponse<SerpApiLocation> {
        self.client
            .http_get("https://api.dataforseo.com/v3/serp/locations", &{})
            .await
    }
    pub async fn locations_se(&self, se: &str) -> DataForSeoApiResponse<SerpApiLocation> {
        self.client
            .http_get(
                format!("https://api.dataforseo.com/v3/serp/{}/locations", se).as_str(),
                &{},
            )
            .await
    }
    pub async fn locations_country(&self, country: &str) -> DataForSeoApiResponse<SerpApiLocation> {
        self.client
            .http_get(
                format!("https://api.dataforseo.com/v3/serp/locations/{}", country).as_str(),
                &{},
            )
            .await
    }
    pub async fn locations_country_se(
        &self,
        se: &str,
        country: &str,
    ) -> DataForSeoApiResponse<SerpApiLocation> {
        self.client
            .http_get(
                format!(
                    "https://api.dataforseo.com/v3/serp/{}/locations/{}",
                    se, country
                )
                .as_str(),
                &{},
            )
            .await
    }
    pub async fn task_ready(&self) -> DataForSeoApiResponse<SerpApiTaskReadyResult> {
        self.client
            .http_get("https://api.dataforseo.com/v3/serp/tasks_ready", &{})
            .await
    }
    pub async fn task_ready_se(&self, se: &str) -> DataForSeoApiResponse<SerpApiTaskReadyResult> {
        self.client
            .http_get(
                format!("https://api.dataforseo.com/v3/serp/{}/tasks_ready", se).as_str(),
                &{},
            )
            .await
    }
    pub async fn task_fixed(&self) -> DataForSeoApiResponse<SerpApiTaskReadyResult> {
        self.client
            .http_get("https://api.dataforseo.com/v3/serp/tasks_fixed", &{})
            .await
    }
    pub async fn task_fixed_se(&self, se: &str) -> DataForSeoApiResponse<SerpApiTaskReadyResult> {
        self.client
            .http_get(
                format!("https://api.dataforseo.com/v3/serp/{}/tasks_fixed", se).as_str(),
                &{},
            )
            .await
    }
}

#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct SerpApiTaskReadyResult {
    id: Option<String>,
    se: Option<String>,
    se_type: Option<String>,
    date_posted: Option<String>,
    tag: Option<String>,
    endpoint_regular: Option<String>,
    endpoint_advanced: Option<String>,
    endpoint_html: Option<String>,
}

#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct SerpApiLocation {
    pub location_code: Option<i32>,
    pub location_name: Option<String>,
    pub location_code_parent: Option<i32>,
    pub country_iso_code: Option<String>,
    pub location_type: Option<String>,
}