data_for_seo/entity/business_data/common.rs
1//! Shared entity types used across the Business Data API domain.
2//!
3//! See <https://docs.dataforseo.com/v3/business_data/overview/>.
4
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
7
8/// Rating object returned by most Business Data results and items.
9#[derive(Debug, Default, Serialize, Deserialize, Clone)]
10pub struct BusinessDataApiRating {
11 /// Rating scale, e.g. `"Max5"` for a 1-5 star scale.
12 pub rating_type: Option<String>,
13 /// Rating value on the scale given by `rating_type`.
14 pub value: Option<f64>,
15 /// Number of votes that contributed to the rating.
16 pub votes_count: Option<i64>,
17 /// Maximum value the rating can reach (e.g. `5`).
18 pub rating_max: Option<i64>,
19}
20
21/// Structured breakdown of an address into its components.
22#[derive(Debug, Default, Serialize, Deserialize, Clone)]
23pub struct BusinessDataApiAddressInfo {
24 /// Borough or neighborhood the business is located in.
25 pub borough: Option<String>,
26 /// Street address (house number and street name).
27 pub address: Option<String>,
28 /// City the business is located in.
29 pub city: Option<String>,
30 /// Postal or ZIP code.
31 pub zip: Option<String>,
32 /// Region, state, or province.
33 pub region: Option<String>,
34 /// Two-letter ISO country code (e.g. `"US"`).
35 pub country_code: Option<String>,
36}
37
38/// A single row returned by a `tasks_ready` endpoint.
39/// See <https://docs.dataforseo.com/v3/business_data/google/my_business_info/tasks_ready/>.
40#[derive(Debug, Default, Serialize, Deserialize, Clone)]
41pub struct BusinessDataApiTaskReady {
42 /// Identifier of the completed task, used to retrieve results.
43 pub id: Option<String>,
44 /// Search engine the task was set for (e.g. `"google"`).
45 pub se: Option<String>,
46 /// Type of the completed task (e.g. `"reviews"`).
47 pub se_type: Option<String>,
48 /// UTC time the task was posted.
49 pub date_posted: Option<String>,
50 /// User-defined task identifier supplied on `task_post`.
51 pub tag: Option<String>,
52 /// Endpoint to call to collect the task's results.
53 pub endpoint: Option<String>,
54}
55
56/// Request body for the `id_list` and `errors` endpoints.
57/// See <https://docs.dataforseo.com/v3/business_data/id_list/>.
58#[derive(Debug, Default, Serialize, Deserialize, Clone)]
59pub struct BusinessDataApiIdListRequest {
60 /// Start of the time range, in `yyyy-mm-dd hh-mm-ss +00:00` format.
61 pub datetime_from: String,
62 /// End of the time range, in `yyyy-mm-dd hh-mm-ss +00:00` format.
63 pub datetime_to: String,
64 /// Maximum number of rows to return (default `1000`, max `1000`).
65 #[serde(skip_serializing_if = "Option::is_none")]
66 pub limit: Option<i32>,
67 /// Number of rows to skip before returning results.
68 #[serde(skip_serializing_if = "Option::is_none")]
69 pub offset: Option<i32>,
70 /// Sorting rule applied to the returned rows (e.g. `"datetime,asc"`).
71 #[serde(skip_serializing_if = "Option::is_none")]
72 pub sort: Option<String>,
73 /// When `true`, includes per-task metadata in each row.
74 #[serde(skip_serializing_if = "Option::is_none")]
75 pub include_metadata: Option<bool>,
76}
77
78impl BusinessDataApiIdListRequest {
79 /// Builds a request bounded by the `[datetime_from, datetime_to]` window.
80 pub fn new<T: Into<String>>(datetime_from: T, datetime_to: T) -> Self {
81 BusinessDataApiIdListRequest {
82 datetime_from: datetime_from.into(),
83 datetime_to: datetime_to.into(),
84 ..BusinessDataApiIdListRequest::default()
85 }
86 }
87}
88
89/// A single row returned by the `id_list` endpoint.
90/// See <https://docs.dataforseo.com/v3/business_data/id_list/>.
91#[derive(Debug, Default, Serialize, Deserialize, Clone)]
92pub struct BusinessDataApiIdList {
93 /// Identifier of the task.
94 pub id: Option<String>,
95 /// Endpoint the task was set on.
96 pub url: Option<String>,
97 /// UTC time the task was posted.
98 pub datetime_posted: Option<String>,
99 /// UTC time the task finished processing.
100 pub datetime_done: Option<String>,
101 /// Current processing status of the task.
102 pub status: Option<String>,
103 /// Money charged for the task, in USD.
104 pub cost: Option<f64>,
105 /// Per-task metadata, present when `include_metadata` was requested.
106 pub metadata: Option<Value>,
107}
108
109/// A single row returned by the `errors` endpoint.
110/// See <https://docs.dataforseo.com/v3/business_data/errors/>.
111#[derive(Debug, Default, Serialize, Deserialize, Clone)]
112pub struct BusinessDataApiErrorItem {
113 /// Identifier of the task that produced the error.
114 pub id: Option<String>,
115 /// UTC time the error occurred.
116 pub datetime: Option<String>,
117 /// Internal function that raised the error.
118 pub function: Option<String>,
119 /// DataForSEO error code.
120 pub error_code: Option<i32>,
121 /// Human-readable error message.
122 pub error_message: Option<String>,
123 /// URL involved in the failed request, when applicable.
124 pub http_url: Option<String>,
125 /// HTTP method of the failed request.
126 pub http_method: Option<String>,
127 /// HTTP status code returned by the failed request.
128 pub http_code: Option<i32>,
129 /// Time the failed request took, in seconds.
130 pub http_time: Option<f64>,
131 /// Raw HTTP response body of the failed request.
132 pub http_response: Option<String>,
133}