data_for_seo/api/on_page/
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
use crate::entity::{
    OnPageDataApiKeywordDensity, OnPageDataApiMicrodata, OnPageDataApiPage, OnPageDataApiRawHtml,
    OnPageDataApiWaterfall,
};
use crate::{DataForSeoApiResponse, DataForSeoClient};
use serde::{Deserialize, Serialize};
use serde_json::Value;

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

impl DataForSeoClient {
    pub fn on_page(&self) -> OnPageApi {
        OnPageApi { client: self }
    }
}

impl OnPageApi<'_> {
    pub async fn task_post(&self, data: Vec<OnPageApiTaskPost>) -> DataForSeoApiResponse<Value> {
        self.client
            .http_post("https://api.dataforseo.com/v3/on_page/task_post", &data)
            .await
    }
    pub async fn summary(&self, id: &str) -> DataForSeoApiResponse<Value> {
        self.client
            .http_get(
                ("https://api.dataforseo.com/v3/on_page/summary/".to_string() + id).as_str(),
                &{},
            )
            .await
    }
    pub async fn pages(
        &self,
        data: Vec<OnPageApiPagesPost>,
    ) -> DataForSeoApiResponse<OnPageDataApiPage> {
        self.client
            .http_post("https://api.dataforseo.com/v3/on_page/pages", &data)
            .await
    }
    pub async fn pages_by_resource(
        &self,
        data: Vec<OnPageApiPagesByResourcePost>,
    ) -> DataForSeoApiResponse<Value> {
        self.client
            .http_post(
                "https://api.dataforseo.com/v3/on_page/pages_by_resource",
                &data,
            )
            .await
    }
    pub async fn waterfall(
        &self,
        data: Vec<OnPageApiWaterfallPost>,
    ) -> DataForSeoApiResponse<OnPageDataApiWaterfall> {
        self.client
            .http_post("https://api.dataforseo.com/v3/on_page/waterfall", &data)
            .await
    }
    pub async fn keyword_density(
        &self,
        data: Vec<OnPageApiKeywordDensityPost>,
    ) -> DataForSeoApiResponse<OnPageDataApiKeywordDensity> {
        self.client
            .http_post(
                "https://api.dataforseo.com/v3/on_page/keyword_density",
                &data,
            )
            .await
    }
    pub async fn microdata(
        &self,
        data: Vec<OnPageApiMicrodataPost>,
    ) -> DataForSeoApiResponse<OnPageDataApiMicrodata> {
        self.client
            .http_post("https://api.dataforseo.com/v3/on_page/microdata", &data)
            .await
    }
    pub async fn raw_html(
        &self,
        data: Vec<OnPageApiRawHtmlPost>,
    ) -> DataForSeoApiResponse<OnPageDataApiRawHtml> {
        self.client
            .http_post("https://api.dataforseo.com/v3/on_page/raw_html", &data)
            .await
    }
}

#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiWaterfallPost {
    pub id: String,
    pub url: String,
    pub tag: Option<String>,
}

impl OnPageApiWaterfallPost {
    pub fn new(id: String, url: String) -> OnPageApiWaterfallPost {
        OnPageApiWaterfallPost { id, url, tag: None }
    }
}
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiKeywordDensityPost {
    pub id: String,
    pub keyword_length: i32,
    pub url: Option<String>,
    pub filters: Option<Vec<Vec<String>>>,
    pub order_by: Option<Vec<String>>,
    pub tag: Option<String>,
}

impl OnPageApiKeywordDensityPost {
    pub fn new(id: String, keyword_length: i32) -> OnPageApiKeywordDensityPost {
        OnPageApiKeywordDensityPost {
            id,
            keyword_length,
            url: None,
            filters: None,
            order_by: None,
            tag: None,
        }
    }
}
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiMicrodataPost {
    pub id: String,
    pub url: String,
    pub tag: Option<String>,
}

impl OnPageApiMicrodataPost {
    pub fn new(id: String, url: String) -> OnPageApiMicrodataPost {
        OnPageApiMicrodataPost { id, url, tag: None }
    }
}
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiTaskPost {
    pub target: String,
    pub max_crawl_pages: i32,
    pub start_url: Option<String>,
    pub force_sitewide_checks: Option<bool>,
    pub priority_urls: Option<Vec<String>>,
    pub max_crawl_depth: Option<i32>,
    pub crawl_delay: Option<i32>,
    pub store_raw_html: Option<bool>,
    pub enable_content_parsing: Option<bool>,
    pub support_cookies: Option<bool>,
    pub accept_language: Option<String>,
    pub custom_robots_txt: Option<String>,
    pub robots_txt_merge_mode: Option<String>,
    pub custom_user_agent: Option<String>,
    pub browser_preset: Option<String>,
    pub browser_screen_width: Option<i32>,
    pub browser_screen_height: Option<i32>,
    pub browser_screen_scale_factor: Option<f32>,
    pub respect_sitemap: Option<bool>,
    pub custom_sitemap: Option<String>,
    pub crawl_sitemap_only: Option<bool>,
    pub load_resources: Option<bool>,
    pub enable_www_redirect_check: Option<bool>,
    pub enable_javascript: Option<bool>,
    pub enable_xhr: Option<bool>,
    pub enable_browser_rendering: Option<bool>,
    pub disable_cookie_popup: Option<bool>,
    pub custom_js: Option<String>,
    pub validate_micromarkup: Option<bool>,
    pub allow_subdomains: Option<bool>,
    pub allowed_subdomains: Option<Vec<String>>,
    pub disallowed_subdomains: Option<Vec<String>>,
    pub check_spell: Option<String>,
    pub check_spell_language: Option<String>,
    pub check_spell_exceptions: Option<Vec<String>>,
    pub calculate_keyword_density: Option<bool>,
    // pub checks_threshold: Option<Value>,
    pub disable_sitewide_checks: Option<Vec<String>>,
    pub disable_page_checks: Option<Vec<String>>,
    pub switch_pool: Option<bool>,
    pub return_despite_timeout: Option<bool>,
    pub tag: Option<String>,
    pub pingback_url: Option<String>,
}
impl OnPageApiTaskPost {
    pub fn new(target: String, max_crawl_pages: i32) -> Self {
        let request = OnPageApiTaskPost {
            target,
            max_crawl_pages,
            ..OnPageApiTaskPost::default()
        };
        request
    }
}

#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiPagesPost {
    pub id: String,
    pub limit: Option<i32>,
    pub offset: Option<i32>,
    pub filters: Option<Vec<Vec<String>>>,
    pub order_by: Option<Vec<String>>,
    pub tag: Option<String>,
}

impl OnPageApiPagesPost {
    pub fn new(id: String) -> Self {
        OnPageApiPagesPost {
            id,
            ..OnPageApiPagesPost::default()
        }
    }
}
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiPagesByResourcePost {
    pub id: String,
    pub url: String,
    pub limit: Option<i32>,
    pub offset: Option<i32>,
    pub filters: Option<Vec<Vec<String>>>,
    pub order_by: Option<Vec<String>>,
    pub tag: Option<String>,
}

impl OnPageApiPagesByResourcePost {
    pub fn new(id: String, url: String) -> Self {
        OnPageApiPagesByResourcePost {
            id,
            url,
            ..OnPageApiPagesByResourcePost::default()
        }
    }
}
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiRawHtmlPost {
    pub id: String,
    pub url: String,
}

impl OnPageApiRawHtmlPost {
    pub fn new(id: String, url: String) -> Self {
        OnPageApiRawHtmlPost { id, url }
    }
}