├── .gitignore ├── .php_cs ├── .scrutinizer.yml ├── .travis.yml ├── LICENSE ├── README.md ├── composer.json ├── lib └── LinkedIn │ ├── Client.php │ ├── DataModel │ ├── BasicProfile.php │ ├── ContentEntity.php │ ├── Model.php │ ├── ShareContent.php │ ├── ShareDistributionTarget.php │ ├── ShareResponse.php │ ├── ShareText.php │ ├── Shares.php │ └── Thumbnail.php │ ├── Endpoint │ ├── BaseUri.php │ ├── EndpointBase.php │ ├── Me.php │ └── Share.php │ ├── Exception │ ├── RuntimeException.php │ └── TokenNotInitializedException.php │ ├── Serializer │ └── Normalizer │ │ └── LinkedInObjectNormalizer.php │ └── Transport │ ├── CurlExtensionTransport.php │ ├── Factory.php │ └── TransportInterface.php ├── phpunit.xml.dist └── test └── LinkedIn ├── ClientTest.php ├── DataModel └── SharesTest.php └── Endpoint ├── EndpointBaseTest.php ├── MeTest.php └── ShareTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | composer.lock 3 | .php_cs.cache -------------------------------------------------------------------------------- /.php_cs: -------------------------------------------------------------------------------- 1 | in(__DIR__) 4 | ->exclude(['vendor', 'test']) 5 | ; 6 | return PhpCsFixer\Config::create() 7 | ->setFinder($finder) 8 | ->setRules([ 9 | '@PSR2' => true, 10 | 'psr0' => false, 11 | 'array_syntax' => ['syntax' => 'short'], 12 | 'concat_space' => ['spacing' => 'none'], 13 | 'lowercase_cast' => true, 14 | 'lowercase_constants' => true, 15 | 'lowercase_keywords' => true, 16 | 'no_trailing_comma_in_singleline_array' => true, 17 | 'no_unused_imports' => true, 18 | 'not_operator_with_successor_space' => true, 19 | 'ordered_imports' => true, 20 | ]) 21 | ; -------------------------------------------------------------------------------- /.scrutinizer.yml: -------------------------------------------------------------------------------- 1 | build: 2 | nodes: 3 | analysis: 4 | project_setup: 5 | override: 6 | - 'true' 7 | tests: 8 | override: 9 | - php-scrutinizer-run 10 | - 11 | command: phpcs-run 12 | use_website_config: true 13 | 14 | tools: 15 | external_code_coverage: true 16 | 17 | checks: 18 | php: true 19 | 20 | coding_style: 21 | php: 22 | indentation: 23 | general: 24 | size: 1 25 | 26 | filter: 27 | excluded_paths: 28 | - test/* -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | cache: 4 | directories: 5 | - $HOME/.composer/cache 6 | 7 | php: 8 | - 7.0 9 | - 7.1 10 | - 7.2 11 | - 7.3 12 | 13 | matrix: 14 | fast_finish: true 15 | 16 | before_install: composer self-update 17 | 18 | install: composer update --prefer-dist --no-progress 19 | 20 | script: if [ "$TRAVIS_PHP_VERSION" == "7.1" ]; then vendor/bin/phpunit --coverage-clover=coverage.clover; else vendor/bin/phpunit; fi 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 R-Everse SpA 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deprecation notice 2 | 3 | This package is deprecated and will soon be removed. 4 | 5 | ## reverse/linkedin-php 6 | 7 | PHP client for LinkedIn API V2. 8 | 9 | ### Requirements 10 | 11 | - php >= 7.0 12 | 13 | ### Installation 14 | 15 | ```bash 16 | composer require reverse/linkedin-php:"dev-master" 17 | ``` 18 | 19 | ### Using LinkedIn API 20 | 21 | To work with LinkedIn API have to init `Client` classes. 22 | 23 | ```php 24 | $client = new Client('appId', 'appSecret', 'returnUrl'); 25 | ``` 26 | 27 | 28 | ### Authentication 29 | 30 | ```php 31 | $client = new Client('appId', 'appSecret', 'returnUrl'); 32 | if (array_key_exists('code', $_GET)) { 33 | $client->initToken($_GET['code']); 34 | 35 | $me = new Me($client); 36 | } else { 37 | $authUrl = $client->getAuthenticationUrl([ 38 | 'scope' => [Client::PERMISSION_LITE_PROFILE] 39 | ]); 40 | header('Location: '.$authUrl); 41 | exit; 42 | } 43 | ``` 44 | 45 | ### Share 46 | 47 | There is possibility to publish a new post or share a post on LinkedIn activities 48 | 49 | To share a post: 50 | ```php 51 | $client = new Client('appId', 'appSecret', 'returnUrl'); 52 | if (array_key_exists('code', $_GET)) { 53 | $client->initToken($_GET['code']); 54 | 55 | $shares = new Shares(); 56 | $shares->setResharedShare('urn:li:share:1232132') // Post's urn:id 57 | 58 | $shares->setOwner('urn:li:person:c7RFYxyz78') 59 | 60 | $shareText = new ShareText(); 61 | $shareText->setTitle('my title'); 62 | 63 | $shares->setText($shareText); 64 | 65 | $shareEndpoint = new REverse\LinkedIn\Endpoint\Share($client); 66 | $shareEndpoint->postShares($shares); 67 | } else { 68 | $authUrl = $client->getAuthenticationUrl([ 69 | 'scope' => [Client::PERMISSION_LITE_PROFILE, Client::PERMISSION_W_MEMBER_SOCIAL] 70 | ]); 71 | header('Location: '.$authUrl); 72 | exit; 73 | } 74 | ``` 75 | 76 | Before to perform this operation, the user declared in `setOwner` must be authenticated in LinkedIn's application. 77 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "reverse/linkedin-php", 3 | "description": "PHP library for LinkedIn", 4 | "type": "library", 5 | "require": { 6 | "php": ">=7.0", 7 | "league/oauth2-linkedin": "^4.1", 8 | "ext-curl": "*", 9 | "ext-json": "*", 10 | "symfony/serializer": "^3.4", 11 | "symfony/property-access": "^3.4", 12 | "symfony/property-info": "^3.4" 13 | }, 14 | "require-dev": { 15 | "phpunit/phpunit": "^6.5" 16 | }, 17 | "autoload": { 18 | "psr-4": { 19 | "REverse\\LinkedIn\\": "lib/LinkedIn/" 20 | } 21 | }, 22 | "autoload-dev": { 23 | "psr-4": { 24 | "REverse\\LinkedIn\\Test\\": "test/LinkedIn/" 25 | } 26 | }, 27 | "license": "MIT", 28 | "authors": [ 29 | { 30 | "name": "Giovanni Albero", 31 | "email": "giovannialbero.solinf@gmail.com" 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /lib/LinkedIn/Client.php: -------------------------------------------------------------------------------- 1 | linkedInProvider = new LinkedInProvider([ 52 | 'clientId' => $clientId, 53 | 'clientSecret' => $clientSecret, 54 | 'redirectUri' => $redirectUri, 55 | ]); 56 | 57 | $this->linkedInProvider->withResourceOwnerVersion(2); 58 | 59 | $this->transport = Factory::createTransport(); 60 | } 61 | 62 | /** 63 | * @param array $options 64 | * 65 | * @return string 66 | */ 67 | public function getAuthenticationUrl(array $options = []): string 68 | { 69 | return $this->linkedInProvider->getAuthorizationUrl($options); 70 | } 71 | 72 | public function isAuthenticated() 73 | { 74 | return $this->token !== null && ! $this->token->hasExpired(); 75 | } 76 | 77 | /** 78 | * @param string $code 79 | * 80 | * @return string 81 | * 82 | * @throws IdentityProviderException 83 | */ 84 | public function initToken(string $code): AccessTokenInterface 85 | { 86 | $this->token = $this->linkedInProvider->getAccessToken('authorization_code', [ 87 | 'code' => $code, 88 | ]); 89 | 90 | $this->initHeader(); 91 | 92 | return $this->token; 93 | } 94 | 95 | /** 96 | * @return string 97 | * @throws TokenNotInitializedException 98 | */ 99 | public function getToken(): AccessTokenInterface 100 | { 101 | if (null === $this->token) { 102 | throw new TokenNotInitializedException(); 103 | } 104 | return $this->token; 105 | } 106 | 107 | public function setToken(AccessTokenInterface $token) 108 | { 109 | $this->token = $token; 110 | 111 | $this->initHeader(); 112 | 113 | return $this; 114 | } 115 | 116 | public function getHeader() 117 | { 118 | return $this->header; 119 | } 120 | 121 | public function doRequest($path, $body, $method): string 122 | { 123 | return $this->transport->executeRequest(self::BASE_URI.$path, $body, $method, $this->header); 124 | } 125 | 126 | private function initHeader() 127 | { 128 | $this->header = [ 129 | 'Authorization: Bearer '.$this->token->getToken(), 130 | 'Content-Type: application/json', 131 | 'cache-control: no-cache', 132 | 'X-Restli-Protocol-Version: 2.0.0', 133 | ]; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /lib/LinkedIn/DataModel/BasicProfile.php: -------------------------------------------------------------------------------- 1 | id; 28 | } 29 | 30 | /** 31 | * @param string $id 32 | * @return BasicProfile 33 | */ 34 | public function setId($id) 35 | { 36 | $this->id = $id; 37 | 38 | return $this; 39 | } 40 | 41 | /** 42 | * @return string 43 | */ 44 | public function getLocalizedLastName() 45 | { 46 | return $this->localizedLastName; 47 | } 48 | 49 | /** 50 | * @param string $localizedLastName 51 | * @return BasicProfile 52 | */ 53 | public function setLocalizedLastName($localizedLastName) 54 | { 55 | $this->localizedLastName = $localizedLastName; 56 | 57 | return $this; 58 | } 59 | 60 | /** 61 | * @return string 62 | */ 63 | public function getLocalizedFirstName() 64 | { 65 | return $this->localizedFirstName; 66 | } 67 | 68 | /** 69 | * @param string $localizedFirstName 70 | * @return BasicProfile 71 | */ 72 | public function setLocalizedFirstName($localizedFirstName) 73 | { 74 | $this->localizedFirstName = $localizedFirstName; 75 | 76 | return $this; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /lib/LinkedIn/DataModel/ContentEntity.php: -------------------------------------------------------------------------------- 1 | entity; 33 | } 34 | 35 | /** 36 | * @param string $entity 37 | * @return ContentEntity 38 | */ 39 | public function setEntity(string $entity): ContentEntity 40 | { 41 | $this->entity = $entity; 42 | 43 | return $this; 44 | } 45 | 46 | /** 47 | * @return string 48 | */ 49 | public function getEntityLocation() 50 | { 51 | return $this->entityLocation; 52 | } 53 | 54 | /** 55 | * @param string $entityLocation 56 | * @return ContentEntity 57 | */ 58 | public function setEntityLocation(string $entityLocation): ContentEntity 59 | { 60 | $this->entityLocation = $entityLocation; 61 | 62 | return $this; 63 | } 64 | 65 | /** 66 | * @return string 67 | */ 68 | public function getResolvedUrl() 69 | { 70 | return $this->resolvedUrl; 71 | } 72 | 73 | /** 74 | * @param string $resolvedUrl 75 | * @return ContentEntity 76 | */ 77 | public function setResolvedUrl(string $resolvedUrl): ContentEntity 78 | { 79 | $this->resolvedUrl = $resolvedUrl; 80 | 81 | return $this; 82 | } 83 | 84 | /** 85 | * @return array|Thumbnail[] 86 | */ 87 | public function getThumbnails(): array 88 | { 89 | return $this->thumbnails; 90 | } 91 | 92 | /** 93 | * @param array|Thumbnail[] $thumbnails 94 | * @return ContentEntity 95 | */ 96 | public function setThumbnails(array $thumbnails): ContentEntity 97 | { 98 | $this->thumbnails = $thumbnails; 99 | 100 | return $this; 101 | } 102 | 103 | public function addThumbnail(Thumbnail $thumbnail): ContentEntity 104 | { 105 | $this->thumbnails[] = $thumbnail; 106 | 107 | return $this; 108 | } 109 | 110 | public function removeThumbnail(Thumbnail $thumbnail): ContentEntity 111 | { 112 | $key = array_search($thumbnail, $this->thumbnails); 113 | 114 | if ($key !== false) { 115 | unset($this->thumbnails[$key]); 116 | } 117 | 118 | return $this; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /lib/LinkedIn/DataModel/Model.php: -------------------------------------------------------------------------------- 1 | serializer = new Serializer($normalizers, $encoders); 30 | } 31 | 32 | public function jsonSerialize() 33 | { 34 | return $this->serializer->serialize($this, 'json'); 35 | } 36 | 37 | public function initObjectByJson(string $json) 38 | { 39 | $this->serializer->deserialize($json, get_class($this), 'json', ['object_to_populate' => $this]); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /lib/LinkedIn/DataModel/ShareContent.php: -------------------------------------------------------------------------------- 1 | description; 40 | } 41 | 42 | /** 43 | * @param string $description 44 | * @return ShareContent 45 | */ 46 | public function setDescription(string $description): ShareContent 47 | { 48 | $this->description = $description; 49 | 50 | return $this; 51 | } 52 | 53 | /** 54 | * @return string 55 | */ 56 | public function getTitle() 57 | { 58 | return $this->title; 59 | } 60 | 61 | /** 62 | * @param string $title 63 | * @return ShareContent 64 | */ 65 | public function setTitle(string $title): ShareContent 66 | { 67 | $this->title = $title; 68 | 69 | return $this; 70 | } 71 | 72 | /** 73 | * @return array|ContentEntity[] 74 | */ 75 | public function getContentEntities(): array 76 | { 77 | return $this->contentEntities; 78 | } 79 | 80 | /** 81 | * @param array|ContentEntity[] $contentEntities 82 | * @return ShareContent 83 | */ 84 | public function setContentEntities(array $contentEntities): ShareContent 85 | { 86 | $this->contentEntities = $contentEntities; 87 | 88 | return $this; 89 | } 90 | 91 | /** 92 | * @param ContentEntity $contentEntity 93 | * 94 | * @return ShareContent 95 | */ 96 | public function addContentEntity(ContentEntity $contentEntity): ShareContent 97 | { 98 | $this->contentEntities[] = $contentEntity; 99 | 100 | return $this; 101 | } 102 | 103 | /** 104 | * @param ContentEntity $contentEntity 105 | * 106 | * @return ShareContent 107 | */ 108 | public function removeContentEntity(ContentEntity $contentEntity): ShareContent 109 | { 110 | $key = array_search($contentEntity, $this->contentEntities); 111 | 112 | if ($key !== false) { 113 | unset($contentEntity[$key]); 114 | } 115 | 116 | return $this; 117 | } 118 | 119 | /** 120 | * @return string 121 | */ 122 | public function getShareMediaCategory() 123 | { 124 | return $this->shareMediaCategory; 125 | } 126 | 127 | /** 128 | * @param string $shareMediaCategory 129 | * @return ShareContent 130 | */ 131 | public function setShareMediaCategory(string $shareMediaCategory): ShareContent 132 | { 133 | $this->shareMediaCategory = $shareMediaCategory; 134 | 135 | return $this; 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /lib/LinkedIn/DataModel/ShareDistributionTarget.php: -------------------------------------------------------------------------------- 1 | id; 48 | } 49 | 50 | /** 51 | * @param string $id 52 | * @return ShareResponse 53 | */ 54 | public function setId(string $id): ShareResponse 55 | { 56 | $this->id = $id; 57 | 58 | return $this; 59 | } 60 | 61 | /** 62 | * @return string 63 | */ 64 | public function getActivity() 65 | { 66 | return $this->activity; 67 | } 68 | 69 | /** 70 | * @param string $activity 71 | * @return ShareResponse 72 | */ 73 | public function setActivity(string $activity): ShareResponse 74 | { 75 | $this->activity = $activity; 76 | 77 | return $this; 78 | } 79 | 80 | /** 81 | * @return ShareContent 82 | */ 83 | public function getContent() 84 | { 85 | return $this->content; 86 | } 87 | 88 | /** 89 | * @param ShareContent $content 90 | * @return ShareResponse 91 | */ 92 | public function setContent(ShareContent $content): ShareResponse 93 | { 94 | $this->content = $content; 95 | 96 | return $this; 97 | } 98 | 99 | /** 100 | * @return bool 101 | */ 102 | public function isEdited() 103 | { 104 | return $this->edited; 105 | } 106 | 107 | /** 108 | * @param bool $edited 109 | * @return ShareResponse 110 | */ 111 | public function setEdited(bool $edited): ShareResponse 112 | { 113 | $this->edited = $edited; 114 | 115 | return $this; 116 | } 117 | 118 | /** 119 | * @return string 120 | */ 121 | public function getOwner() 122 | { 123 | return $this->owner; 124 | } 125 | 126 | /** 127 | * @param string $owner 128 | * @return ShareResponse 129 | */ 130 | public function setOwner(string $owner): ShareResponse 131 | { 132 | $this->owner = $owner; 133 | 134 | return $this; 135 | } 136 | 137 | /** 138 | * @return string 139 | */ 140 | public function getSubject() 141 | { 142 | return $this->subject; 143 | } 144 | 145 | /** 146 | * @param string $subject 147 | * @return ShareResponse 148 | */ 149 | public function setSubject(string $subject): ShareResponse 150 | { 151 | $this->subject = $subject; 152 | 153 | return $this; 154 | } 155 | 156 | /** 157 | * @return ShareText 158 | */ 159 | public function getText() 160 | { 161 | return $this->text; 162 | } 163 | 164 | /** 165 | * @param ShareText $text 166 | * @return ShareResponse 167 | */ 168 | public function setText(ShareText $text): ShareResponse 169 | { 170 | $this->text = $text; 171 | 172 | return $this; 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /lib/LinkedIn/DataModel/ShareText.php: -------------------------------------------------------------------------------- 1 | text; 18 | } 19 | 20 | /** 21 | * @param string $text 22 | * 23 | * @return ShareText 24 | */ 25 | public function setText(string $text): ShareText 26 | { 27 | $this->text = $text; 28 | 29 | return $this; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/LinkedIn/DataModel/Shares.php: -------------------------------------------------------------------------------- 1 | owner; 53 | } 54 | 55 | /** 56 | * @param string $owner 57 | * @return Shares 58 | */ 59 | public function setOwner(string $owner): Shares 60 | { 61 | $this->owner = $owner; 62 | 63 | return $this; 64 | } 65 | 66 | /** 67 | * @return string 68 | */ 69 | public function getAgent() 70 | { 71 | return $this->agent; 72 | } 73 | 74 | /** 75 | * @param string $agent 76 | * @return Shares 77 | */ 78 | public function setAgent(string $agent): Shares 79 | { 80 | $this->agent = $agent; 81 | 82 | return $this; 83 | } 84 | 85 | /** 86 | * @return string 87 | */ 88 | public function getSubject() 89 | { 90 | return $this->subject; 91 | } 92 | 93 | /** 94 | * @param string $subject 95 | * @return Shares 96 | */ 97 | public function setSubject(string $subject): Shares 98 | { 99 | $this->subject = $subject; 100 | 101 | return $this; 102 | } 103 | 104 | /** 105 | * @return ShareText 106 | */ 107 | public function getText() 108 | { 109 | return $this->text; 110 | } 111 | 112 | /** 113 | * @param ShareText $text 114 | * @return Shares 115 | */ 116 | public function setText(ShareText $text): Shares 117 | { 118 | $this->text = $text; 119 | 120 | return $this; 121 | } 122 | 123 | /** 124 | * @return ShareContent 125 | */ 126 | public function getContent() 127 | { 128 | return $this->content; 129 | } 130 | 131 | /** 132 | * @param ShareContent $content 133 | * @return Shares 134 | */ 135 | public function setContent(ShareContent $content): Shares 136 | { 137 | $this->content = $content; 138 | 139 | return $this; 140 | } 141 | 142 | /** 143 | * @return ShareDistributionTarget 144 | */ 145 | public function getDistribution() 146 | { 147 | return $this->distribution; 148 | } 149 | 150 | /** 151 | * @param ShareDistributionTarget $distribution 152 | * @return Shares 153 | */ 154 | public function setDistribution(ShareDistributionTarget $distribution): Shares 155 | { 156 | $this->distribution = $distribution; 157 | 158 | return $this; 159 | } 160 | 161 | /** 162 | * @return string 163 | */ 164 | public function getResharedShare() 165 | { 166 | return $this->resharedShare; 167 | } 168 | 169 | /** 170 | * @param string $resharedShare 171 | * @return Shares 172 | */ 173 | public function setResharedShare(string $resharedShare): Shares 174 | { 175 | $this->resharedShare = $resharedShare; 176 | 177 | return $this; 178 | } 179 | 180 | /** 181 | * @return string 182 | */ 183 | public function getOriginalShare() 184 | { 185 | return $this->originalShare; 186 | } 187 | 188 | /** 189 | * @param string $originalShare 190 | * @return Shares 191 | */ 192 | public function setOriginalShare(string $originalShare): Shares 193 | { 194 | $this->originalShare = $originalShare; 195 | 196 | return $this; 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /lib/LinkedIn/DataModel/Thumbnail.php: -------------------------------------------------------------------------------- 1 | authors; 33 | } 34 | 35 | /** 36 | * @param array $authors 37 | * @return Thumbnail 38 | */ 39 | public function setAuthors(array $authors): Thumbnail 40 | { 41 | $this->authors = $authors; 42 | 43 | return $this; 44 | } 45 | 46 | /** 47 | * @return object 48 | */ 49 | public function getImageSpecificContent() 50 | { 51 | return $this->imageSpecificContent; 52 | } 53 | 54 | /** 55 | * @param object|array $imageSpecificContent 56 | * @return Thumbnail 57 | */ 58 | public function setImageSpecificContent($imageSpecificContent): Thumbnail 59 | { 60 | $this->imageSpecificContent = $imageSpecificContent; 61 | 62 | return $this; 63 | } 64 | 65 | /** 66 | * @return array 67 | */ 68 | public function getPublishers(): array 69 | { 70 | return $this->publishers; 71 | } 72 | 73 | /** 74 | * @param array $publishers 75 | * @return Thumbnail 76 | */ 77 | public function setPublishers(array $publishers): Thumbnail 78 | { 79 | $this->publishers = $publishers; 80 | 81 | return $this; 82 | } 83 | 84 | /** 85 | * @return string 86 | */ 87 | public function getResolvedUrl() 88 | { 89 | return $this->resolvedUrl; 90 | } 91 | 92 | /** 93 | * @param string $resolvedUrl 94 | * @return Thumbnail 95 | */ 96 | public function setResolvedUrl(string $resolvedUrl): Thumbnail 97 | { 98 | $this->resolvedUrl = $resolvedUrl; 99 | 100 | return $this; 101 | } 102 | } -------------------------------------------------------------------------------- /lib/LinkedIn/Endpoint/BaseUri.php: -------------------------------------------------------------------------------- 1 | client = $client; 21 | } 22 | 23 | /** 24 | * @return Client 25 | */ 26 | public function getClient(): Client 27 | { 28 | return $this->client; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/LinkedIn/Endpoint/Me.php: -------------------------------------------------------------------------------- 1 | getClient()->doRequest(self::ENDPOINT_PATH, '', TransportInterface::METHOD_GET); 15 | 16 | $basicProfile = new BasicProfile(); 17 | $basicProfile->initObjectByJson($result); 18 | 19 | return $basicProfile; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /lib/LinkedIn/Endpoint/Share.php: -------------------------------------------------------------------------------- 1 | getClient()->doRequest(self::ENDPOINT_PATH, $shares->jsonSerialize(), TransportInterface::METHOD_POST); 16 | 17 | $shareResponse = new ShareResponse(); 18 | $shareResponse->initObjectByJson($result); 19 | 20 | return $shareResponse; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lib/LinkedIn/Exception/RuntimeException.php: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | test/ 10 | 11 | 12 | 13 | 14 | 15 | lib 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /test/LinkedIn/ClientTest.php: -------------------------------------------------------------------------------- 1 | getAuthenticationUrl(); 18 | 19 | $this->assertTrue(true); 20 | } 21 | 22 | public function testIfCallGetTokenBeforeInitTokenThisMethodThrowException() 23 | { 24 | $this->expectException(TokenNotInitializedException::class); 25 | 26 | $client = new Client('test', 'test', 'test.test'); 27 | $client->getToken(); 28 | } 29 | 30 | public function testIfCallGetTokenAfterInitTokenIsCalledMethodDoesntThrowException() 31 | { 32 | $linkedInProvider = $this->prophesize(LinkedIn::class); 33 | $token = $this->prophesize(AccessTokenInterface::class); 34 | $token->getToken()->willReturn('tokenString'); 35 | $linkedInProvider 36 | ->getAccessToken(Argument::exact('authorization_code'), Argument::exact(['code' => 'test'])) 37 | ->willReturn($token->reveal()); 38 | ; 39 | $reflection = new \ReflectionClass(Client::class); 40 | $reflectionProperty = $reflection->getProperty('linkedInProvider'); 41 | $reflectionProperty->setAccessible(true); 42 | $client = $reflection->newInstanceWithoutConstructor(); 43 | /** @var \ReflectionProperty $reflectionProperty */ 44 | 45 | $reflectionProperty->setValue($client, $linkedInProvider->reveal()); 46 | $client->initToken('test'); 47 | $client->getToken(); 48 | $this->assertTrue(true); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /test/LinkedIn/DataModel/SharesTest.php: -------------------------------------------------------------------------------- 1 | setAgent('agent') 17 | ->setOwner('owner') 18 | ; 19 | 20 | $shareContent = new ShareContent(); 21 | $shareContent 22 | ->setTitle('title content') 23 | ->setDescription('description content') 24 | ; 25 | $shares->setContent($shareContent); 26 | 27 | $expected = '{"owner":"owner","agent":"agent","content":{"description":"description content","title":"title content","contentEntities":[]}}'; 28 | 29 | $this->assertEquals($expected, $shares->jsonSerialize()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/LinkedIn/Endpoint/EndpointBaseTest.php: -------------------------------------------------------------------------------- 1 | prophesize(Client::class); 14 | $endpointBase = new EndpointBase($client->reveal()); 15 | 16 | $this->assertInstanceOf(Client::class, $endpointBase->getClient()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /test/LinkedIn/Endpoint/MeTest.php: -------------------------------------------------------------------------------- 1 | prophesize(Client::class); 18 | $client 19 | ->doRequest(Argument::exact(Me::ENDPOINT_PATH), Argument::exact(''), 'GET') 20 | ->willReturn('{ 21 | "firstName":{ 22 | "localized":{ 23 | "en_US":"Bob" 24 | }, 25 | "preferredLocale":{ 26 | "country":"US", 27 | "language":"en" 28 | } 29 | }, 30 | "localizedFirstName": "Bob", 31 | "headline":{ 32 | "localized":{ 33 | "en_US":"API Enthusiast at LinkedIn" 34 | }, 35 | "preferredLocale":{ 36 | "country":"US", 37 | "language":"en" 38 | } 39 | }, 40 | "localizedHeadline": "API Enthusiast at LinkedIn", 41 | "vanityName": "bsmith", 42 | "id":"yrZCpj2Z12", 43 | "lastName":{ 44 | "localized":{ 45 | "en_US":"Smith" 46 | }, 47 | "preferredLocale":{ 48 | "country":"US", 49 | "language":"en" 50 | } 51 | }, 52 | "localizedLastName": "Smith", 53 | "profilePicture": { 54 | "displayImage": "urn:li:digitalmediaAsset:C4D00AAAAbBCDEFGhiJ" 55 | } 56 | }') 57 | ; 58 | $me = new Me($client->reveal()); 59 | 60 | $basicProfile = $me->get(); 61 | 62 | $this->assertEquals("yrZCpj2Z12", $basicProfile->getId()); 63 | $this->assertEquals("Bob", $basicProfile->getLocalizedFirstName()); 64 | $this->assertEquals("Smith", $basicProfile->getLocalizedLastName()); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /test/LinkedIn/Endpoint/ShareTest.php: -------------------------------------------------------------------------------- 1 | prophesize(Client::class); 18 | $shares = $this->prophesize(Shares::class); 19 | $shares->jsonSerialize()->shouldBeCalled(); 20 | $client 21 | ->doRequest(Argument::exact(Share::ENDPOINT_PATH), Argument::cetera(), 'POST') 22 | ->willReturn(' 23 | { 24 | "activity": "urn:li:activity:6275832358151294976", 25 | "content": { 26 | "contentEntities": [ 27 | { 28 | "entityLocation": "https://www.example.com/content.html", 29 | "thumbnails": [ 30 | { 31 | "authors": [], 32 | "imageSpecificContent": {}, 33 | "publishers": [], 34 | "resolvedUrl": "https://www.example.com/image.jpg" 35 | } 36 | ] 37 | } 38 | ], 39 | "title": "Test Share with Content" 40 | }, 41 | "created": { 42 | "actor": "urn:li:person:324_kGGaLE", 43 | "time": 1496275033520 44 | }, 45 | "distribution": { 46 | "linkedInDistributionTarget": { 47 | "visibleToGuest": false 48 | } 49 | }, 50 | "edited": false, 51 | "id": "6275832358189047808", 52 | "lastModified": { 53 | "actor": "urn:li:person:324_kGGaLE", 54 | "time": 1496275033520 55 | }, 56 | "owner": "urn:li:organization:2414183", 57 | "subject": "Test Share Subject", 58 | "text": { 59 | "text": "Test Share!" 60 | } 61 | } 62 | ') 63 | ; 64 | 65 | $share = new Share($client->reveal()); 66 | 67 | /** @var ShareResponse $result */ 68 | $result = $share->postShares($shares->reveal()); 69 | 70 | $this->assertEquals("Test Share Subject", $result->getSubject()); 71 | $this->assertInstanceOf(ShareContent::class, $result->getContent()); 72 | $this->assertEquals('Test Share with Content', $result->getContent()->getTitle()); 73 | $this->assertCount(1, $result->getContent()->getContentEntities()); 74 | $this->assertEquals('https://www.example.com/content.html', $result->getContent()->getContentEntities()[0]->getEntityLocation()); 75 | $this->assertCount(1, $result->getContent()->getContentEntities()[0]->getThumbnails()); 76 | $this->assertEquals('https://www.example.com/image.jpg', $result->getContent()->getContentEntities()[0]->getThumbnails()[0]->getResolvedUrl()); 77 | } 78 | } 79 | --------------------------------------------------------------------------------