├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml ├── src └── Artesaos │ └── LinkedIn │ ├── Facades │ └── LinkedIn.php │ ├── LinkedInLaravel.php │ ├── LinkedinServiceProvider.php │ └── config │ └── linkedin.php └── tests ├── AbstractTestCase.php └── LinkedinTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | vendor/ 3 | composer.lock -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.6 5 | - 7.0 6 | - hhvm 7 | 8 | before_script: 9 | - composer self-update 10 | - composer install 11 | script: vendor/bin/phpunit 12 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.3.0 (2017-04-08) 2 | 3 | Features: 4 | 5 | - Added support for Laravel 5.4 6 | - Updated happyr/linkedin-api-client to version 1.0.0 7 | 8 | ## 1.2.0 (2016-09-20) 9 | 10 | Features: 11 | 12 | - Added support for Laravel 5.3 13 | - Improved tests with orchestra/testbench 14 | 15 | ## 1.1.0 (2016-06-24) 16 | 17 | Features: 18 | 19 | - Updated to Happyr/LinkedIn-API-client 0.7 20 | 21 | ## 1.0.0 (2016-02-15) 22 | 23 | Features: 24 | 25 | - Lumen support included 26 | - Creadentials are loaded from .env for better security 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 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 13 | all 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 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Linkedin API integration for Laravel Framework 2 | [![Build Status](https://travis-ci.org/artesaos/laravel-linkedin.svg?branch=master)](https://travis-ci.org/artesaos/laravel-linkedin) [![Latest Stable Version](https://poser.pugx.org/artesaos/laravel-linkedin/v/stable)](https://packagist.org/packages/artesaos/laravel-linkedin) [![Total Downloads](https://poser.pugx.org/artesaos/laravel-linkedin/downloads)](https://packagist.org/packages/artesaos/laravel-linkedin) [![Latest Unstable Version](https://poser.pugx.org/artesaos/laravel-linkedin/v/unstable)](https://packagist.org/packages/artesaos/laravel-linkedin) [![License](https://poser.pugx.org/artesaos/laravel-linkedin/license)](https://packagist.org/packages/artesaos/laravel-linkedin) 3 | 4 | This package is a wrapper for [Happyr/LinkedIn-API-client](https://github.com/Happyr/LinkedIn-API-client). 5 | You can view the documentation for php version [here](https://github.com/Happyr/LinkedIn-API-client/blob/master/Readme.md). Don't forget to consult the oficial [LinkedIn API](https://developer.linkedin.com/) site. 6 | 7 | ###### If you need install on Lumen, go to [Lumen section](#installation-on-lumen) 8 | 9 | ### Installation on Laravel 10 | 11 | ##### Install with composer 12 | ```bash 13 | composer require artesaos/laravel-linkedin 14 | ``` 15 | 16 | ##### Add service Provider 17 | ``` 18 | Artesaos\LinkedIn\LinkedinServiceProvider::class, 19 | ``` 20 | 21 | ##### Facade 22 | ``` 23 | 'LinkedIn' => \Artesaos\LinkedIn\Facades\LinkedIn::class, 24 | ``` 25 | 26 | ##### Publish config file 27 | ``` 28 | php artisan vendor:publish --provider="Artesaos\LinkedIn\LinkedinServiceProvider" 29 | ``` 30 | 31 | ### Installation on Lumen 32 | 33 | ##### Install with composer 34 | ```bash 35 | composer require artesaos/laravel-linkedin 36 | ``` 37 | 38 | ##### Add Service Provider, facade and config parameters to the `bootstrap/app.php` file and copy the [linkedin.php](https://github.com/artesaos/laravel-linkedin/blob/master/src/Artesaos/LinkedIn/config/linkedin.php) to the config directory of your project (create then if not exists) 39 | ```php 40 | $app->register(\Artesaos\LinkedIn\LinkedinServiceProvider::class); 41 | class_alias(\Artesaos\LinkedIn\Facades\LinkedIn::class,'LinkedIn'); 42 | 43 | $app->configure('linkedin'); 44 | ``` 45 | 46 | ### Usage 47 | 48 | In order to use this API client (or any other LinkedIn clients) you have to [register your app](https://www.linkedin.com/developer/apps) 49 | with LinkedIn to receive an API key. Once you've registered your LinkedIn app, you will be provided with 50 | an *API Key* and *Secret Key*, please fill this values on `linkedin.php` config file. 51 | 52 | ####Basic Usage 53 | The unique difference in this package is the `LinkedIn` facade. Instead of this: 54 | ```php 55 | $linkedIn=new Happyr\LinkedIn\LinkedIn('app_id', 'app_secret'); 56 | $linkedin->foo(); 57 | ``` 58 | you can simple call the facade for anyone method, like this: 59 | ```php 60 | LinkedIn::foo(); 61 | ``` 62 | or use the laravel container: 63 | ```php 64 | app('linkedin')->foo(); 65 | app()['linkedin']->foo(); 66 | App::make('linkedin')->foo(); // ... 67 | ``` 68 | 69 | The service container automatically return an instance of `LinkedIn` class ready to use 70 | 71 | #### LinkedIn login 72 | 73 | This example below is showing how to login with LinkedIn using `LinkedIn` facade. 74 | 75 | ```php 76 | if (LinkedIn::isAuthenticated()) { 77 | //we know that the user is authenticated now. Start query the API 78 | $user=LinkedIn::get('v1/people/~:(firstName,lastName)'); 79 | echo "Welcome ".$user['firstName']; 80 | exit(); 81 | }elseif (LinkedIn::hasError()) { 82 | echo "User canceled the login."; 83 | exit(); 84 | } 85 | 86 | //if not authenticated 87 | $url = LinkedIn::getLoginUrl(); 88 | echo "Login with LinkedIn"; 89 | exit(); 90 | ``` 91 | 92 | 93 | #### Get basic profile info 94 | You can retrive information using the `get()` method, like this: 95 | ```php 96 | LinkedIn::get('v1/people/~:(firstName,num-connections,picture-url)'); 97 | ``` 98 | This query return an array of information. You can view all the `REST` api's methods in [REST API Console](https://apigee.com/console/linkedin) 99 | 100 | #### How to post on LinkedIn wall 101 | 102 | The example below shows how you can post on a users wall. The access token is fetched from the database. 103 | 104 | ```php 105 | LinkedIn::setAccessToken('access_token_from_db'); 106 | 107 | $options = ['json'=> 108 | [ 109 | 'comment' => 'Im testing Happyr LinkedIn client with Laravel Framework! https://github.com/artesaos/laravel-linkedin', 110 | 'visibility' => [ 111 | 'code' => 'anyone' 112 | ] 113 | ] 114 | ]; 115 | 116 | $result = LinkedIn::post('v1/people/~/shares', $options); 117 | ``` 118 | 119 | 120 | You may of course do the same in xml. Use the following options array. 121 | ```php 122 | $options = array( 123 | 'format' => 'xml', 124 | 'body' => ' 125 | Im testing Happyr LinkedIn client! https://github.com/Happyr/LinkedIn-API-client 126 | 127 | anyone 128 | 129 | '); 130 | ``` 131 | 132 | ## Configuration 133 | 134 | ### The api options 135 | 136 | The third parameter of `LinkedIn::api` is an array with options. Below is a table of array keys that you may use. 137 | 138 | | Option name | Description 139 | | ----------- | ----------- 140 | | body | The body of a HTTP request. Put your xml string here. 141 | | format | Set this to 'json', 'xml' or 'simple_xml' to override the default value. 142 | | headers | This is HTTP headers to the request 143 | | json | This is an array with json data that will be encoded to a json string. Using this option you do need to specify a format. 144 | | response_data_type | To override the response format for one request 145 | | query | This is an array with query parameters 146 | 147 | 148 | 149 | ### Changing request format 150 | 151 | The default format when communicating with LinkedIn API is json. You can let the API do `json_encode` for you. 152 | The following code shows you how. 153 | 154 | ```php 155 | $body = array( 156 | 'comment' => 'Testing the linkedin API!', 157 | 'visibility' => array('code' => 'anyone') 158 | ); 159 | 160 | LinkedIn::post('v1/people/~/shares', array('json'=>$body)); 161 | LinkedIn::post('v1/people/~/shares', array('body'=>json_encode($body))); 162 | ``` 163 | 164 | When using `array('json'=>$body)` as option the format will always be `json`. You can change the request format in three ways. 165 | 166 | ```php 167 | // By setter 168 | LinkedIn::setFormat('xml'); 169 | 170 | // Set format for just one request 171 | LinkedIn::post('v1/people/~/shares', array('format'=>'xml', 'body'=>$body)); 172 | ``` 173 | 174 | 175 | ### Understanding response data type 176 | 177 | The data type returned from `LinkedIn::api` can be configured. You may use the 178 | `LinkedIn::setResponseDataType` or as an option for `LinkedIn::api` 179 | 180 | ```php 181 | // By setter 182 | LinkedIn::setResponseDataType('simple_xml'); 183 | 184 | // Set format for just one request 185 | LinkedIn::get('v1/people/~:(firstName,lastName)', array('response_data_type'=>'psr7')); 186 | 187 | ``` 188 | 189 | Below is a table that specifies what the possible return data types are when you call `LinkedIn::api`. 190 | 191 | | Type | Description 192 | | ------ | ------------ 193 | | array | An assosiative array. This can only be used with the `json` format. 194 | | simple_xml | A SimpleXMLElement. See [PHP manual](http://php.net/manual/en/class.simplexmlelement.php). This can only be used with the `xml` format. 195 | | psr7 | A PSR7 response. 196 | | stream | A file stream. 197 | | string | A plain old string. 198 | 199 | ### Using different scopes 200 | 201 | If you want to define special scopes when you authenticate the user you should specify them when you are generating the 202 | login url. If you don't specify scopes LinkedIn will use the default scopes that you have configured for the app. 203 | 204 | ```php 205 | $scope = 'r_fullprofile,r_emailaddress,w_share'; 206 | //or 207 | $scope = array('rw_groups', 'r_contactinfo', 'r_fullprofile', 'w_messages'); 208 | 209 | $url = LinkedIn::getLoginUrl(array('scope'=>$scope)); 210 | return "Login with LinkedIn"; 211 | ``` 212 | 213 | #### Changelog 214 | 215 | You can view the latest changes [here](https://github.com/artesaos/laravel-linkedin/blob/master/CHANGELOG.md) 216 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "artesaos/laravel-linkedin", 3 | "type": "library", 4 | "description": "Linkedin API integration for Laravel and Lumen 5", 5 | "keywords": ["LinkedIn","Laravel Framework","Lumen","API","Client","SDK","Integration","REST"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Mauri de Souza Nunes", 10 | "email": "mauri870@gmail.com" 11 | } 12 | ], 13 | "require": { 14 | "php": ">=5.5.9", 15 | "illuminate/contracts": "~5.0", 16 | "illuminate/http": "~5.0", 17 | "illuminate/support": "~5.0", 18 | "happyr/linkedin-api-client": "~1.0", 19 | "php-http/guzzle6-adapter": "^1.1", 20 | "php-http/curl-client": "^1.7", 21 | "guzzlehttp/psr7": "^1.4", 22 | "php-http/message": "^1.5" 23 | }, 24 | "require-dev": { 25 | "phpunit/phpunit": "~5.0", 26 | "orchestra/testbench": "~3.4@dev" 27 | }, 28 | "autoload": { 29 | "psr-4": { 30 | "Artesaos\\LinkedIn\\": "src/Artesaos/LinkedIn/" 31 | } 32 | }, 33 | "autoload-dev": { 34 | "psr-4": { 35 | "Artesaos\\LinkedIn\\Tests\\": "tests" 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | tests 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/Artesaos/LinkedIn/Facades/LinkedIn.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) 2015, Mauri de Souza Nunes 7 | * @license https://opensource.org/licenses/MIT MIT License 8 | */ 9 | 10 | namespace Artesaos\LinkedIn\Facades; 11 | 12 | use Illuminate\Support\Facades\Facade; 13 | 14 | class LinkedIn extends Facade { 15 | 16 | protected static function getFacadeAccessor() { 17 | return 'linkedin'; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Artesaos/LinkedIn/LinkedInLaravel.php: -------------------------------------------------------------------------------- 1 | 6 | * @license https://opensource.org/licenses/MIT MIT License 7 | */ 8 | 9 | namespace Artesaos\LinkedIn; 10 | 11 | use Happyr\LinkedIn\LinkedIn; 12 | 13 | class LinkedInLaravel extends LinkedIn 14 | { 15 | 16 | /** 17 | * LinkedInLaravel constructor. 18 | * 19 | * @param string $app_id 20 | * @param string $app_secret 21 | */ 22 | public function __construct($app_id, $app_secret) 23 | { 24 | parent::__construct($app_id, $app_secret); 25 | } 26 | } -------------------------------------------------------------------------------- /src/Artesaos/LinkedIn/LinkedinServiceProvider.php: -------------------------------------------------------------------------------- 1 | 6 | * @license https://opensource.org/licenses/MIT MIT License 7 | */ 8 | 9 | namespace Artesaos\LinkedIn; 10 | 11 | use Http\Adapter\Guzzle6\Client; 12 | use Illuminate\Support\ServiceProvider; 13 | use Http\Adapter\Guzzle6\Client as HttpClient; 14 | use Http\Message\MessageFactory\GuzzleMessageFactory as HttpGuzzleMessageFactory; 15 | 16 | class LinkedinServiceProvider extends ServiceProvider 17 | { 18 | /** 19 | * Perform post-registration booting of services. 20 | * 21 | * @return void 22 | */ 23 | public function boot() 24 | { 25 | //Publish config file 26 | if(function_exists('config_path')){ 27 | //If is not a Lumen App... 28 | $this->publishes([ 29 | __DIR__ . '/config/linkedin.php' => config_path('linkedin.php'), 30 | ]); 31 | 32 | $this->mergeConfigFrom( 33 | __DIR__ . '/config/linkedin.php', 'linkedin' 34 | ); 35 | } 36 | } 37 | 38 | /** 39 | * Register bindings in the container. 40 | * 41 | * @return void 42 | */ 43 | public function register() 44 | { 45 | $this->app->singleton('LinkedIn', function(){ 46 | $linkedIn = new LinkedInLaravel(config('linkedin.api_key'), config('linkedin.api_secret')); 47 | $linkedIn->setHttpClient(new Client()); 48 | $linkedIn->setHttpMessageFactory(new HttpGuzzleMessageFactory()); 49 | 50 | return $linkedIn; 51 | }); 52 | 53 | $this->app->alias('LinkedIn', 'linkedin'); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Artesaos/LinkedIn/config/linkedin.php: -------------------------------------------------------------------------------- 1 | 7 | * @license https://opensource.org/licenses/MIT MIT License 8 | */ 9 | 10 | return [ 11 | 'api_key' => env('LINKEDIN_KEY','yourapikey'), 12 | 'api_secret' => env('LINKEDIN_SECRET','yourapisecret'), 13 | ]; 14 | -------------------------------------------------------------------------------- /tests/AbstractTestCase.php: -------------------------------------------------------------------------------- 1 | LinkedIn::class 20 | ]; 21 | } 22 | 23 | protected function getEnvironmentSetUp($app) 24 | { 25 | $app['config']->set('linkedin.api_key', 'yourapikey'); 26 | $app['config']->set('linkedin.api_secret', 'yourapisecret'); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/LinkedinTest.php: -------------------------------------------------------------------------------- 1 | 7 | * @license https://opensource.org/licenses/MIT MIT License 8 | */ 9 | 10 | namespace Artesaos\LinkedIn\Tests; 11 | use Artesaos\LinkedIn\Facades\LinkedIn; 12 | 13 | class LinkedinTest extends AbstractTestCase 14 | { 15 | /** 16 | * @test 17 | */ 18 | public function test_bindings() 19 | { 20 | $bindings = [$this->app['linkedin'], $this->app['LinkedIn']]; 21 | 22 | foreach($bindings as $binding) { 23 | $this->assertInstanceOf( 24 | \Happyr\LinkedIn\LinkedIn::class, 25 | $binding 26 | ); 27 | } 28 | } 29 | 30 | /** 31 | * @test 32 | */ 33 | public function test_facade() 34 | { 35 | $this->assertEquals( 36 | LinkedIn::isAuthenticated(), 37 | false 38 | ); 39 | } 40 | } 41 | --------------------------------------------------------------------------------