peopledatalabs/models/
autocomplete.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{models::common::BaseParams, PDLError};
4
5#[derive(Debug, Serialize, Deserialize)]
6pub struct AutocompleteBaseParams {
7    /// Field that autocomplete will be calculated for
8    #[serde(rename = "field", default)]
9    pub field: String,
10    /// Text that is used as the seed for autocompletion
11    #[serde(rename = "text", default)]
12    pub text: Option<String>,
13    /// Setting titlecase to true will titlecase the data in 200 responses
14    #[serde(rename = "titlecase", skip_serializing_if = "Option::is_none")]
15    pub titlecase: Option<bool>,
16}
17
18#[derive(Debug, Serialize, Deserialize)]
19pub struct AutocompleteParams {
20    #[serde(flatten)]
21    pub base_params: Option<BaseParams>,
22    #[serde(flatten)]
23    pub autocomplete_base_params: AutocompleteBaseParams,
24}
25
26impl AutocompleteParams {
27    pub fn validate(&self) -> Result<(), PDLError> {
28        if self.autocomplete_base_params.field.is_empty() {
29            return Err(PDLError::ValidationError);
30        }
31        Ok(())
32    }
33}
34
35#[derive(Debug, Serialize, Deserialize)]
36pub struct AutocompleteResponse {
37    /// See https://docs.peopledatalabs.com/docs/output-response-autocomplete-api for more information
38    pub status: i32,
39    pub data: Option<Vec<AutocompleteResult>>,
40    pub fields: Option<Vec<String>>,
41}
42
43#[derive(Debug, Serialize, Deserialize)]
44pub struct Meta {
45    pub website: Option<String>,
46    pub location_name: Option<String>,
47    pub id: Option<String>,
48    pub industry: Option<String>,
49    pub linkedin_slug: Option<String>,
50    pub display_name: Option<String>,
51    pub display_name_history: Option<Vec<String>>,
52    pub alternative_names: Option<Vec<String>>,
53    pub country: Option<String>,
54    pub locality: Option<String>,
55    pub region: Option<String>,
56    pub role: Option<String>,
57    pub fields: Option<Vec<String>>,
58}
59
60#[derive(Debug, Serialize, Deserialize)]
61pub struct AutocompleteResult {
62    /// The plain text name of this Autocomplete API suggestion.
63    /// The prefix of this field will match the value of the text input parameter.
64    pub name: Option<String>,
65    /// The number of records in our Person Dataset for this Autocomplete API suggestion.
66    /// This field is used for sorting elements in the data array.
67    pub count: Option<i32>,
68    /// A set of additional fields returned for each result in the data array.
69    /// The metadata fields depend on the field input parameter
70    pub meta: Option<Meta>,
71}