Skip to main content

data_for_seo/api/serp/google/
news.rs

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