Skip to content

Commit 4d7ccf4

Browse files
committed
Token updates, added license, doc update
1 parent 2e8eeea commit 4d7ccf4

File tree

4 files changed

+114
-31
lines changed

4 files changed

+114
-31
lines changed

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2017 Philipp Tkachev
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.

README.md

+54-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
LinkedIn API Client with OAuth 2 authorization witten on PHP
1+
LinkedIn API Client with OAuth 2 authorization written on PHP
22
============================================================
3-
[![Build Status](https://travis-ci.org/zoonman/linkedin-client.svg)](https://travis-ci.org/zoonman/linkedin-client) [![Code Climate](https://codeclimate.com/github/zoonman/linkedin-client/badges/gpa.svg)](https://codeclimate.com/github/zoonman/linkedin-client) [![Packagist](https://img.shields.io/packagist/dt/zoonman/linkedin-client.svg)](https://packagist.org/packages/zoonman/linkedin-client) [![GitHub license](https://img.shields.io/github/license/zoonman/linkedin-client.svg)](https://github.com/zoonman/linkedin-client/LICENSE.md)
3+
[![Build Status](https://travis-ci.org/zoonman/linkedin-client.svg)](https://travis-ci.org/zoonman/linkedin-api-php-client) [![Code Climate](https://codeclimate.com/github/zoonman/linkedin-api-php-client/badges/gpa.svg)](https://codeclimate.com/github/zoonman/linkedin-api-php-client) [![Packagist](https://img.shields.io/packagist/dt/zoonman/linkedin-api-php-client.svg)](https://packagist.org/packages/zoonman/linkedin-api-php-client) [![GitHub license](https://img.shields.io/github/license/zoonman/linkedin-api-php-client.svg)](https://github.com/zoonman/linkedin-api-php-client/LICENSE.md)
44

55

66

@@ -49,23 +49,30 @@ $client = new Client(
4949

5050
#### Getting local redirect URL
5151

52-
Get current redirect url use
52+
To start linking process you have to setup redirect url.
53+
You can set your own or use current one.
54+
SDK provides you a `getRedirectUrl()` helper for your convenience:
5355

5456
```php
55-
$client->getRedirectUrl();
57+
$redirectUrl = $client->getRedirectUrl();
5658
```
5759

60+
We recommend you to have it stored during the linking session
61+
because you will need to use it when you will be getting access token.
5862

5963
#### Setting local redirect URL
6064

61-
To set redirect url use
65+
Set a custom redirect url use:
6266

6367
```php
6468
$client->setRedirectUrl('http://your.domain.tld/path/to/script/');
6569
```
6670

6771
#### Getting LinkedIn redirect URL
6872

73+
In order of performing OAUTH 2.0 flow, you should get LinkedIn login URL.
74+
During this procedure you have to define scope of requested permissions.
75+
Use `Scope` enum class to get scope names.
6976
To get redirect url to LinkedIn, use the following approach:
7077

7178
```php
@@ -76,9 +83,11 @@ $scopes = [
7683
'rw_company_admin',
7784
'w_share',
7885
];
79-
$loginUrl = $client->getLoginUrl(); // get url on LinkedIn to start linking
86+
$loginUrl = $client->getLoginUrl($scopes); // get url on LinkedIn to start linking
8087
```
8188

89+
Now you can take user to LinkedIn. You can use link or rely on Location HTTP header.
90+
8291
#### Getting Access Token
8392

8493
To get access token use (don't forget to set redirect url)
@@ -99,6 +108,17 @@ $profile = $client->api(
99108
);
100109
```
101110

111+
There are two helper methods:
112+
113+
```php
114+
// get method
115+
$client->get('ENDPOINT', ['param' => 'value']);
116+
117+
//post
118+
$client->post('ENDPOINT', ['param' => 'value']);
119+
```
120+
121+
102122
To perform api call to get profile information
103123

104124
```php
@@ -108,31 +128,42 @@ $profile = $client->get(
108128
print_r($profile);
109129
```
110130

111-
To list companies where you an admin
131+
To list companies where you are an admin
112132

113133
```php
114134
$profile = $client->get(
115-
'people/~:(id,email-address,first-name,last-name)'
135+
'companies',
136+
['is-company-admin' => true]
116137
);
117138
print_r($profile);
118139
```
119140

120-
To share content
141+
To share content on a personal profile
121142

122143
```php
123144
$share = $client->post(
124-
'people/~/shares',
125-
[
126-
'comment' => 'Checkout this amazing PHP SDK for LinkedIn!',
127-
'content' => [
128-
'title' => 'PHP Client for LinkedIn API',
129-
'description' => 'OAuth 2 flow, composer Package',
130-
'submitted-url' => 'https://github.com/zoonman/linkedin-api-php-client',
131-
'submitted-image-url' => 'https://github.com/fluidicon.png',
132-
],
133-
'visibility' => [
134-
'code' => 'anyone'
135-
]
136-
]
137-
);
145+
'people/~/shares',
146+
[
147+
'comment' => 'Checkout this amazing PHP SDK for LinkedIn!',
148+
'content' => [
149+
'title' => 'PHP Client for LinkedIn API',
150+
'description' => 'OAuth 2 flow, composer Package',
151+
'submitted-url' => 'https://github.com/zoonman/linkedin-api-php-client',
152+
'submitted-image-url' => 'https://github.com/fluidicon.png',
153+
],
154+
'visibility' => [
155+
'code' => 'anyone'
156+
]
157+
]
158+
);
138159
```
160+
161+
162+
## Contributing
163+
164+
Please, open PR with your changes linked to an GitHub issue.
165+
You code must follow [PSR](http://www.php-fig.org/psr/) standards and have PHPUnit tests.
166+
167+
## License
168+
169+
[MIT](LICENSE.md)

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "zoonman/linkedin-client",
2+
"name": "zoonman/linkedin-api-php-client",
33
"description": "Client for LinkedIn API v2",
44
"type": "library",
55
"require": {

src/AccessToken.php

+38-7
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,30 @@ class AccessToken
3030
protected $token;
3131

3232
/**
33+
* When token will expire.
34+
*
35+
* Please, pay attention that LinkedIn API always returns "expires in" time,
36+
* which is amount of seconds before token will expire since now.
37+
* If you are going to store token somewhere, you have to keep "expires at"
38+
* or two values - "expires in" and "token created".
39+
* Using "expires at" approach lets you have efficient queries to find
40+
* tokens will soon expire and be proactive with regards to your
41+
* B2C communication.
42+
*
3343
* @var int
3444
*/
35-
protected $expiresIn;
45+
protected $expiresAt;
3646

3747
/**
3848
* AccessToken constructor.
3949
*
4050
* @param string $token
41-
* @param int $expiresIn
51+
* @param int $expiresAt
4252
*/
43-
public function __construct($token = '', $expiresIn = 0)
53+
public function __construct($token = '', $expiresAt = 0)
4454
{
4555
$this->setToken($token);
46-
$this->setExpiresIn($expiresIn);
56+
$this->setExpiresAt($expiresAt);
4757
}
4858

4959
/**
@@ -76,7 +86,7 @@ public function setToken($token)
7686
*/
7787
public function getExpiresIn()
7888
{
79-
return $this->expiresIn;
89+
return $this->expiresAt - time();
8090
}
8191

8292
/**
@@ -88,7 +98,7 @@ public function getExpiresIn()
8898
*/
8999
public function setExpiresIn($expiresIn)
90100
{
91-
$this->expiresIn = $expiresIn;
101+
$this->expiresAt = $expiresIn + time();
92102
return $this;
93103
}
94104

@@ -103,6 +113,27 @@ public function __toString()
103113
}
104114

105115
/**
116+
* @return int
117+
*/
118+
public function getExpiresAt()
119+
{
120+
return $this->expiresAt;
121+
}
122+
123+
/**
124+
* @param int $expiresAt
125+
*
126+
* @return AccessToken
127+
*/
128+
public function setExpiresAt($expiresAt)
129+
{
130+
$this->expiresAt = $expiresAt;
131+
return $this;
132+
}
133+
134+
/**
135+
* Instantiate token object
136+
*
106137
* @param $responseArray
107138
*
108139
* @return \LinkedIn\AccessToken
@@ -126,7 +157,7 @@ public static function fromResponseArray($responseArray)
126157
}
127158
return new static(
128159
$responseArray['access_token'],
129-
$responseArray['expires_in']
160+
$responseArray['expires_in'] + time()
130161
);
131162
}
132163
}

0 commit comments

Comments
 (0)