Skip to main content

data_for_seo/api/serp/google/
images.rs

1use crate::entity::{SerpApiGoogleImagesAdvanced, SerpApiGoogleImagesHtml};
2use crate::{DataForSeoApiResponse, SerpApiGoogle, SerpApiTaskReadyResult};
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6/// Google Images SERP endpoint.
7/// <https://docs.dataforseo.com/v3/serp/google/images/overview/>
8impl SerpApiGoogle<'_> {
9    /// <https://docs.dataforseo.com/v3/serp/google/images/task_post/>
10    pub async fn images_task_post(
11        &self,
12        data: Vec<SerpApiGoogleImagesTaskPostRequest>,
13    ) -> DataForSeoApiResponse<Value> {
14        self.client
15            .http_post("/v3/serp/google/images/task_post", &data)
16            .await
17    }
18    /// <https://docs.dataforseo.com/v3/serp/google/images/tasks_ready/>
19    pub async fn images_tasks_ready(&self) -> DataForSeoApiResponse<SerpApiTaskReadyResult> {
20        self.client.serp().task_ready_se("google/images").await
21    }
22    /// <https://docs.dataforseo.com/v3/serp/google/images/tasks_fixed/>
23    pub async fn images_tasks_fixed(&self) -> DataForSeoApiResponse<SerpApiTaskReadyResult> {
24        self.client.serp().task_fixed_se("google/images").await
25    }
26    /// <https://docs.dataforseo.com/v3/serp/google/images/task_get/advanced/>
27    pub async fn images_task_get_advanced(
28        &self,
29        id: &str,
30    ) -> DataForSeoApiResponse<SerpApiGoogleImagesAdvanced> {
31        self.client
32            .http_get(format!("/v3/serp/google/images/task_get/advanced/{id}").as_str())
33            .await
34    }
35    /// <https://docs.dataforseo.com/v3/serp/google/images/task_get/html/>
36    pub async fn images_task_get_html(
37        &self,
38        id: &str,
39    ) -> DataForSeoApiResponse<SerpApiGoogleImagesHtml> {
40        self.client
41            .http_get(format!("/v3/serp/google/images/task_get/html/{id}").as_str())
42            .await
43    }
44    /// <https://docs.dataforseo.com/v3/serp/google/images/live/advanced/>
45    pub async fn images_live_advanced(
46        &self,
47        data: Vec<SerpApiGoogleImagesTaskPostRequest>,
48    ) -> DataForSeoApiResponse<SerpApiGoogleImagesAdvanced> {
49        self.client
50            .http_post("/v3/serp/google/images/live/advanced", &data)
51            .await
52    }
53}
54
55/// Request body for Google Images task_post / live.
56/// See <https://docs.dataforseo.com/v3/serp/google/images/task_post/>.
57#[derive(Debug, Default, Serialize, Deserialize, Clone)]
58pub struct SerpApiGoogleImagesTaskPostRequest {
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    /// GPS coordinates the search was run for ("lat,lng,zoom").
73    #[serde(skip_serializing_if = "Option::is_none")]
74    pub location_coordinate: Option<String>,
75    /// Full language name of the search.
76    #[serde(skip_serializing_if = "Option::is_none")]
77    pub language_name: Option<String>,
78    /// Language code the search was run for.
79    pub language_code: String,
80    /// Os.
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub os: Option<String>,
83    /// Search-engine domain the results were taken from.
84    #[serde(skip_serializing_if = "Option::is_none")]
85    pub se_domain: Option<String>,
86    /// Depth.
87    #[serde(skip_serializing_if = "Option::is_none")]
88    pub depth: Option<i32>,
89    /// Max crawl pages.
90    #[serde(skip_serializing_if = "Option::is_none")]
91    pub max_crawl_pages: Option<i32>,
92    /// Search param.
93    #[serde(skip_serializing_if = "Option::is_none")]
94    pub search_param: Option<String>,
95    /// User-defined identifier echoed back on the result.
96    #[serde(skip_serializing_if = "Option::is_none")]
97    pub tag: Option<String>,
98    /// URL of the postback.
99    #[serde(skip_serializing_if = "Option::is_none")]
100    pub postback_url: Option<String>,
101    /// Postback data.
102    #[serde(skip_serializing_if = "Option::is_none")]
103    pub postback_data: Option<String>,
104    /// URL of the pingback.
105    #[serde(skip_serializing_if = "Option::is_none")]
106    pub pingback_url: Option<String>,
107}
108
109impl SerpApiGoogleImagesTaskPostRequest {
110    /// Creates a request with the required language and location codes.
111    /// Set `keyword` and any optional fields before sending.
112    pub fn new(language_code: String, location_code: i32) -> Self {
113        SerpApiGoogleImagesTaskPostRequest {
114            language_code,
115            location_code,
116            ..SerpApiGoogleImagesTaskPostRequest::default()
117        }
118    }
119}