linkedin_api/
types.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3use url::Url;
4
5pub struct Identity {
6    pub authentication_token: String,
7    pub session_cookie: String,
8}
9
10/// Parameters for people search.
11#[derive(Debug, Clone, Default)]
12pub struct SearchPeopleParams {
13    pub keywords: Option<String>,
14    pub connection_of: Option<String>,
15    pub network_depth: Option<String>,
16    pub current_company: Option<Vec<String>>,
17    pub past_companies: Option<Vec<String>>,
18    pub nonprofit_interests: Option<Vec<String>>,
19    pub profile_languages: Option<Vec<String>>,
20    pub regions: Option<Vec<String>>,
21    pub industries: Option<Vec<String>>,
22    pub schools: Option<Vec<String>>,
23    pub include_private_profiles: bool,
24    pub limit: Option<usize>,
25}
26
27/// Strongly-typed struct for profiles.
28#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
29#[serde(rename_all = "camelCase")]
30pub struct Profile {
31    #[serde(rename = "entityUrn")]
32    pub entity_urn: Option<String>,
33
34    pub first_name: Option<String>,
35    pub last_name: Option<String>,
36    pub headline: Option<String>,
37    pub summary: Option<String>,
38    pub industry_name: Option<String>,
39    #[serde(rename = "industryUrn")]
40    pub industry_urn: Option<String>,
41
42    pub geo_country_name: Option<String>,
43    #[serde(rename = "geoCountryUrn")]
44    pub geo_country_urn: Option<String>,
45    #[serde(rename = "geoLocationName")]
46    pub geo_location_name: Option<String>,
47    #[serde(rename = "geoLocationBackfilled")]
48    pub geo_location_backfilled: Option<bool>,
49
50    pub address: Option<String>,
51    pub birth_date: Option<BirthDate>,
52
53    pub default_locale: Option<Locale>,
54    pub supported_locales: Option<Vec<Locale>>,
55
56    pub location: Option<Location>,
57    #[serde(rename = "locationName")]
58    pub location_name: Option<String>,
59
60    #[serde(rename = "miniProfile")]
61    pub mini_profile: Option<MiniProfile>,
62
63    pub profile_picture: Option<ProfilePicture>,
64    #[serde(rename = "profilePictureOriginalImage")]
65    pub profile_picture_original_image: Option<VectorImageContainer>,
66
67    #[serde(rename = "showEducationOnProfileTopCard")]
68    pub show_education_on_profile_top_card: Option<bool>,
69    pub student: Option<bool>,
70
71    #[serde(rename = "versionTag")]
72    pub version_tag: Option<String>,
73
74    #[serde(skip)]
75    pub profile_id: String, // extracted from entityUrn with get_id_from_urn
76
77    #[serde(skip)]
78    pub experience: Vec<Experience>,
79
80    #[serde(skip)]
81    pub education: Vec<Education>,
82
83    #[serde(skip)]
84    pub skills: Vec<Skill>,
85}
86
87#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
88#[serde(rename_all = "camelCase")]
89pub struct BirthDate {
90    pub day: Option<u32>,
91    pub month: Option<u32>,
92    pub year: Option<u32>,
93}
94
95#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
96#[serde(rename_all = "camelCase")]
97pub struct Locale {
98    pub country: Option<String>,
99    pub language: Option<String>,
100}
101
102#[derive(Debug, PartialEq, Clone, Default, Serialize, Deserialize)]
103#[serde(rename_all = "camelCase")]
104pub struct Location {
105    pub basic_location: Option<BasicLocation>,
106}
107
108#[derive(Debug, PartialEq, Clone, Default, Serialize, Deserialize)]
109#[serde(rename_all = "camelCase")]
110pub struct BasicLocation {
111    pub country_code: Option<String>,
112    pub postal_code: Option<String>,
113}
114
115#[derive(Debug, PartialEq, Clone, Default, Serialize, Deserialize)]
116#[serde(rename_all = "camelCase")]
117pub struct MiniProfile {
118    #[serde(rename = "dashEntityUrn")]
119    pub dash_entity_urn: Option<String>,
120    #[serde(rename = "entityUrn")]
121    pub entity_urn: Option<String>,
122    #[serde(rename = "objectUrn")]
123    pub object_urn: Option<String>,
124    pub public_identifier: Option<String>,
125    pub first_name: Option<String>,
126    pub last_name: Option<String>,
127    pub occupation: Option<String>,
128    pub tracking_id: Option<String>,
129    pub picture: Option<VectorImageContainer>,
130}
131
132#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
133#[serde(rename_all = "camelCase")]
134pub struct ProfilePicture {
135    pub display_image: Option<String>,
136    pub original_image: Option<String>,
137    pub photo_filter_edit_info: Option<PhotoFilterEditInfo>,
138}
139
140#[derive(Debug, PartialEq, Clone, Default, Serialize, Deserialize)]
141#[serde(rename_all = "camelCase")]
142pub struct PhotoFilterEditInfo {
143    pub top_left: Option<Point>,
144    pub top_right: Option<Point>,
145    pub bottom_left: Option<Point>,
146    pub bottom_right: Option<Point>,
147    pub brightness: Option<f32>,
148    pub contrast: Option<f32>,
149    pub saturation: Option<f32>,
150    pub vignette: Option<f32>,
151    pub photo_filter_type: Option<String>,
152}
153
154#[derive(Debug, PartialEq, Clone, Default, Serialize, Deserialize)]
155#[serde(rename_all = "camelCase")]
156pub struct Point {
157    pub x: f32,
158    pub y: f32,
159}
160
161#[derive(Debug, PartialEq, Clone, Default, Serialize, Deserialize)]
162#[serde(rename_all = "camelCase")]
163pub struct VectorImageContainer {
164    #[serde(rename = "com.linkedin.common.VectorImage")]
165    pub vector_image: Option<VectorImage>,
166}
167
168#[derive(Debug, PartialEq, Clone, Default, Serialize, Deserialize)]
169#[serde(rename_all = "camelCase")]
170pub struct VectorImage {
171    pub root_url: Option<String>,
172    pub artifacts: Vec<ImageArtifact>,
173}
174
175#[derive(Debug, PartialEq, Clone, Default, Serialize, Deserialize)]
176#[serde(rename_all = "camelCase")]
177pub struct ImageArtifact {
178    pub height: u32,
179    pub width: u32,
180    pub expires_at: Option<u64>,
181    pub file_identifying_url_path_segment: Option<String>,
182}
183
184/// An experience entry
185#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
186#[serde(rename_all = "camelCase")]
187pub struct Experience {
188    pub title: Option<String>,
189    #[serde(rename = "companyName")]
190    pub company_name: Option<String>,
191    #[serde(rename = "companyLogoUrl")]
192    pub company_logo_url: Option<String>,
193    pub description: Option<String>,
194}
195
196/// An education entry
197#[derive(Debug, PartialEq, Clone, Default, Serialize, Deserialize)]
198#[serde(rename_all = "camelCase")]
199pub struct Education {
200    pub school_name: Option<String>,
201    pub degree: Option<String>,
202    pub field_of_study: Option<String>,
203}
204
205/// A skill entry
206#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
207#[serde(rename_all = "camelCase")]
208pub struct Skill {
209    pub name: String,
210}
211
212#[derive(Debug, Clone, Serialize, Deserialize)]
213pub struct ContactInfo {
214    #[serde(rename = "emailAddress")]
215    pub email_address: Option<String>,
216    pub websites: Vec<Website>,
217    pub twitter: Vec<String>,
218    #[serde(rename = "phoneNumbers")]
219    pub phone_numbers: Vec<String>,
220    pub birthdate: Option<String>,
221    pub ims: Option<Vec<Value>>,
222}
223
224#[derive(Debug, Clone, Serialize, Deserialize)]
225pub struct Website {
226    pub url: String,
227    pub label: Option<String>,
228}
229
230#[derive(Debug, Clone, Serialize, Deserialize)]
231pub struct Connection {
232    pub urn_id: String,
233    pub public_id: String,
234    pub distance: String,
235}
236
237#[derive(Debug, Clone, Serialize, Deserialize)]
238pub struct Conversation {
239    pub id: String,
240}
241
242#[derive(Debug, Clone, Serialize, Deserialize)]
243pub struct ConversationDetails {
244    pub id: String,
245}
246
247#[derive(Debug, Clone, Serialize, Deserialize)]
248pub struct MemberBadges {
249    pub premium: bool,
250    pub open_link: bool,
251    pub influencer: bool,
252    pub job_seeker: bool,
253}
254
255#[derive(Debug, Clone, Serialize, Deserialize)]
256pub struct NetworkInfo {
257    pub followers_count: u64,
258}
259
260#[derive(Debug, Clone, Serialize, Deserialize)]
261pub struct School {
262    pub name: String,
263}
264
265#[derive(Debug, Clone, Serialize, Deserialize)]
266pub struct Company {
267    pub name: String,
268}
269
270#[derive(Debug, Clone, Serialize, Deserialize)]
271pub struct PersonSearchResult {
272    pub urn_id: String,
273    pub public_id: String,
274    pub distance: String,
275}
276
277#[derive(Debug, Clone, Serialize, Deserialize)]
278pub struct Invitation {
279    #[serde(rename = "entityUrn")]
280    pub entity_urn: String,
281    #[serde(rename = "sharedSecret")]
282    pub shared_secret: String,
283}
284
285pub(crate) struct UniformResourceName {
286    pub(crate) namespace: String, // the context of the id
287    pub(crate) id: String,
288}
289impl Profile {
290    /// Helper method to get full name
291    fn get_full_name(&self) -> Option<String> {
292        match (&self.first_name, &self.last_name) {
293            (Some(first), Some(last)) => Some(format!("{} {}", first, last)),
294            (Some(first), None) => Some(first.clone()),
295            (None, Some(last)) => Some(last.clone()),
296            (None, None) => None,
297        }
298    }
299
300    /// Helper method to get profile image URL
301    fn get_profile_image(&self) -> Option<Url> {
302        self.profile_picture_original_image
303            .as_ref()
304            .and_then(|container| container.vector_image.as_ref())
305            .and_then(|vector_image| {
306                if let (Some(root_url), Some(artifact)) =
307                    (&vector_image.root_url, vector_image.artifacts.first())
308                {
309                    let full_url = format!(
310                        "{}{}",
311                        root_url,
312                        artifact
313                            .file_identifying_url_path_segment
314                            .as_deref()
315                            .unwrap_or("")
316                    );
317                    Url::parse(&full_url).ok()
318                } else {
319                    None
320                }
321            })
322    }
323}