Skip to content

Commit

Permalink
Update Linkedin.php (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
khrigo authored Jul 17, 2023
1 parent 51dd197 commit 470b781
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/Providers/Linkedin.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function getBasicProfile(string $token): array

$response = $this->getHttpClient()->get($url, [
'headers' => [
'Authorization' => 'Bearer '.$token,
'Authorization' => 'Bearer ' . $token,
'X-RestLi-Protocol-Version' => '2.0.0',
],
]);
Expand All @@ -65,7 +65,7 @@ protected function getEmailAddress(string $token): array

$response = $this->getHttpClient()->get($url, [
'headers' => [
'Authorization' => 'Bearer '.$token,
'Authorization' => 'Bearer ' . $token,
'X-RestLi-Protocol-Version' => '2.0.0',
],
]);
Expand All @@ -75,12 +75,13 @@ protected function getEmailAddress(string $token): array

protected function mapUserToObject(array $user): Contracts\UserInterface
{
$preferredLocale = ($user['firstName.preferredLocale.language'] ?? null).'_'.($user['firstName.preferredLocale.country'] ?? null);
$firstName = $user['firstName.localized.'.$preferredLocale] ?? null;
$lastName = $user['lastName.localized.'.$preferredLocale] ?? null;
$name = $firstName.' '.$lastName;
$preferredLocale = ($user['firstName']['preferredLocale']['language'] ?? null) . '_' .
($user['firstName']['preferredLocale']['country'] ?? null);
$firstName = $user['firstName']['localized'][$preferredLocale] ?? null;
$lastName = $user['lastName']['localized'][$preferredLocale] ?? null;
$name = $firstName . ' ' . $lastName;

$images = $user['profilePicture.displayImage~.elements'] ?? [];
$images = $user['profilePicture']['displayImage~']['elements'] ?? [];
$avatars = \array_filter($images, static fn ($image) => ($image['data']['com.linkedin.digitalmedia.mediaartifact.StillImage']['storageSize']['width'] ?? 0) === 100);
$avatar = \array_shift($avatars);
$originalAvatars = \array_filter($images, static fn ($image) => ($image['data']['com.linkedin.digitalmedia.mediaartifact.StillImage']['storageSize']['width'] ?? 0) === 800);
Expand All @@ -91,8 +92,8 @@ protected function mapUserToObject(array $user): Contracts\UserInterface
Contracts\ABNF_NICKNAME => $name,
Contracts\ABNF_NAME => $name,
Contracts\ABNF_EMAIL => $user['emailAddress'] ?? null,
Contracts\ABNF_AVATAR => $avatar['identifiers.0.identifier'] ?? null,
'avatar_original' => $originalAvatar['identifiers.0.identifier'] ?? null,
Contracts\ABNF_AVATAR => $avatar['identifiers']['0']['identifier'] ?? null,
'avatar_original' => $originalAvatar['identifiers']['0']['identifier'] ?? null,
]);
}
}

0 comments on commit 470b781

Please sign in to comment.