Skip to main content

data_for_seo/entity/business_data/
trustpilot.rs

1//! Entities for the Trustpilot Search and Reviews endpoints.
2//! See <https://docs.dataforseo.com/v3/business_data/trustpilot/overview/>.
3
4use crate::entity::BusinessDataApiRating;
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
7
8/// Task request for the Trustpilot Search `task_post` endpoint.
9/// See <https://docs.dataforseo.com/v3/business_data/trustpilot/search/task_post/>.
10#[derive(Debug, Default, Serialize, Deserialize, Clone)]
11pub struct BusinessDataApiTrustpilotSearchTaskPost {
12    /// Business name to search for on Trustpilot.
13    pub keyword: String,
14    /// Task priority: `1` (normal, default) or `2` (high, extra cost).
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub priority: Option<i32>,
17    /// User-defined task identifier (max 255 characters).
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub tag: Option<String>,
20    /// URL that receives the finished results via POST.
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub postback_url: Option<String>,
23    /// URL notified via GET when the task completes.
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub pingback_url: Option<String>,
26}
27
28impl BusinessDataApiTrustpilotSearchTaskPost {
29    /// Builds a Trustpilot search task request for the given business name.
30    pub fn new<T: Into<String>>(keyword: T) -> Self {
31        BusinessDataApiTrustpilotSearchTaskPost {
32            keyword: keyword.into(),
33            ..BusinessDataApiTrustpilotSearchTaskPost::default()
34        }
35    }
36}
37
38/// Task request for the Trustpilot Reviews `task_post` endpoint.
39/// See <https://docs.dataforseo.com/v3/business_data/trustpilot/reviews/task_post/>.
40#[derive(Debug, Default, Serialize, Deserialize, Clone)]
41pub struct BusinessDataApiTrustpilotReviewsTaskPost {
42    /// Business domain whose Trustpilot reviews to collect.
43    pub domain: String,
44    /// Number of reviews to parse (default `20`).
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub depth: Option<i32>,
47    /// Review ordering, e.g. `"recency"` or `"relevance"`.
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub sort_by: Option<String>,
50    /// Task priority: `1` (normal, default) or `2` (high, extra cost).
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub priority: Option<i32>,
53    /// User-defined task identifier (max 255 characters).
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub tag: Option<String>,
56    /// URL that receives the finished results via POST.
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub postback_url: Option<String>,
59    /// URL notified via GET when the task completes.
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub pingback_url: Option<String>,
62}
63
64impl BusinessDataApiTrustpilotReviewsTaskPost {
65    /// Builds a Trustpilot reviews task request for the given business domain.
66    pub fn new<T: Into<String>>(domain: T) -> Self {
67        BusinessDataApiTrustpilotReviewsTaskPost {
68            domain: domain.into(),
69            ..BusinessDataApiTrustpilotReviewsTaskPost::default()
70        }
71    }
72}
73
74/// Result of a Trustpilot Search request: metadata plus matched businesses.
75#[derive(Debug, Default, Serialize, Deserialize, Clone)]
76pub struct BusinessDataApiTrustpilotSearchResult {
77    /// Business name the task was set for.
78    pub keyword: Option<String>,
79    /// Result type, e.g. `"trustpilot_search"`.
80    #[serde(rename = "type")]
81    pub result_type: Option<String>,
82    /// Source domain the data was collected from (e.g. `"trustpilot.com"`).
83    pub se_domain: Option<String>,
84    /// URL of the Trustpilot results page the data was parsed from.
85    pub check_url: Option<String>,
86    /// UTC time the result was collected.
87    pub datetime: Option<String>,
88    /// Number of businesses in `items`.
89    pub items_count: Option<i64>,
90    /// Parsed business profiles.
91    pub items: Option<Vec<BusinessDataApiTrustpilotSearchItem>>,
92}
93
94impl BusinessDataApiTrustpilotSearchResult {
95    /// Items of this result (empty slice when the API returned none).
96    pub fn items(&self) -> &[BusinessDataApiTrustpilotSearchItem] {
97        self.items.as_deref().unwrap_or_default()
98    }
99}
100
101/// A single business profile returned by Trustpilot Search.
102#[derive(Debug, Default, Serialize, Deserialize, Clone)]
103pub struct BusinessDataApiTrustpilotSearchItem {
104    /// Element type, e.g. `"trustpilot_search_organic"`.
105    #[serde(rename = "type")]
106    pub item_type: Option<String>,
107    /// Rank within elements of the same type.
108    pub rank_group: Option<i64>,
109    /// Rank across all elements regardless of type.
110    pub rank_absolute: Option<i64>,
111    /// Business name.
112    pub title: Option<String>,
113    /// Business website domain.
114    pub domain: Option<String>,
115    /// URL of the business's Trustpilot profile.
116    pub url: Option<String>,
117    /// Business description.
118    pub description: Option<String>,
119    /// Business category on Trustpilot.
120    pub category: Option<String>,
121    /// Total number of reviews the business has received.
122    pub reviews_count: Option<i64>,
123    /// Aggregated TrustScore rating.
124    pub rating: Option<BusinessDataApiRating>,
125    /// Trustpilot verification status of the profile (raw object).
126    pub verification: Option<Value>,
127    /// Business contact details (raw object).
128    pub contact_info: Option<Value>,
129}
130
131/// Result of a Trustpilot Reviews request: metadata plus individual reviews.
132#[derive(Debug, Default, Serialize, Deserialize, Clone)]
133pub struct BusinessDataApiTrustpilotReviewsResult {
134    /// Business domain the task was set for.
135    pub domain: Option<String>,
136    /// Result type, e.g. `"trustpilot_reviews"`.
137    #[serde(rename = "type")]
138    pub result_type: Option<String>,
139    /// Source domain the data was collected from (e.g. `"trustpilot.com"`).
140    pub se_domain: Option<String>,
141    /// URL of the Trustpilot business page the data was parsed from.
142    pub check_url: Option<String>,
143    /// UTC time the result was collected.
144    pub datetime: Option<String>,
145    /// Business name the reviews belong to.
146    pub title: Option<String>,
147    /// Business address shown on the profile.
148    pub location: Option<String>,
149    /// Total number of reviews the business has received.
150    pub reviews_count: Option<i64>,
151    /// Aggregated TrustScore rating.
152    pub rating: Option<BusinessDataApiRating>,
153    /// Number of reviews in `items`.
154    pub items_count: Option<i64>,
155    /// Parsed individual reviews.
156    pub items: Option<Vec<BusinessDataApiTrustpilotReviewItem>>,
157}
158
159impl BusinessDataApiTrustpilotReviewsResult {
160    /// Items of this result (empty slice when the API returned none).
161    pub fn items(&self) -> &[BusinessDataApiTrustpilotReviewItem] {
162        self.items.as_deref().unwrap_or_default()
163    }
164}
165
166/// A single Trustpilot review.
167#[derive(Debug, Default, Serialize, Deserialize, Clone)]
168pub struct BusinessDataApiTrustpilotReviewItem {
169    /// Element type, e.g. `"trustpilot_review_search"`.
170    #[serde(rename = "type")]
171    pub item_type: Option<String>,
172    /// Rank within elements of the same type.
173    pub rank_group: Option<i64>,
174    /// Rank across all elements regardless of type.
175    pub rank_absolute: Option<i64>,
176    /// Placement of the element on the page.
177    pub position: Option<String>,
178    /// Direct URL to the review.
179    pub url: Option<String>,
180    /// Rating given by this review.
181    pub rating: Option<BusinessDataApiRating>,
182    /// Whether the review is from a verified purchase.
183    pub verified: Option<bool>,
184    /// Language code of the review.
185    pub language: Option<String>,
186    /// UTC timestamp the review was published.
187    pub timestamp: Option<String>,
188    /// Date of the experience the review describes.
189    pub time_of_experience: Option<String>,
190    /// Review headline.
191    pub title: Option<String>,
192    /// Review body text.
193    pub review_text: Option<String>,
194    /// Images attached to the review (raw objects).
195    pub review_images: Option<Vec<Value>>,
196    /// Reviewer profile details (raw object).
197    pub user_profile: Option<Value>,
198    /// Owner replies to the review (raw objects).
199    pub responses: Option<Vec<Value>>,
200    /// Number of likes the review received.
201    pub likes_count: Option<i64>,
202}