Skip to content

Commit 381c8cb

Browse files
committed
Add support of JsonSerializable interface
1 parent a6cd3f0 commit 381c8cb

File tree

5 files changed

+68
-7
lines changed

5 files changed

+68
-7
lines changed

src/AccessToken.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @package LinkedIn
2323
*/
24-
class AccessToken
24+
class AccessToken implements \JsonSerializable
2525
{
2626

2727
/**
@@ -80,7 +80,7 @@ public function setToken($token)
8080
}
8181

8282
/**
83-
* Get token expiration
83+
* The number of seconds remaining, from the time it was requested, before the token will expire.
8484
*
8585
* @return int seconds
8686
*/
@@ -92,7 +92,7 @@ public function getExpiresIn()
9292
/**
9393
* Set token expiration time
9494
*
95-
* @param int $expiresIn seconds
95+
* @param int $expiresIn amount of seconds before expiration
9696
*
9797
* @return AccessToken
9898
*/
@@ -113,6 +113,8 @@ public function __toString()
113113
}
114114

115115
/**
116+
* Get Unix epoch time when token will expire
117+
*
116118
* @return int
117119
*/
118120
public function getExpiresAt()
@@ -121,7 +123,9 @@ public function getExpiresAt()
121123
}
122124

123125
/**
124-
* @param int $expiresAt
126+
* Set Unix epoch time when token will expire
127+
*
128+
* @param int $expiresAt seconds, unix time
125129
*
126130
* @return AccessToken
127131
*/
@@ -132,7 +136,7 @@ public function setExpiresAt($expiresAt)
132136
}
133137

134138
/**
135-
* Instantiate token object
139+
* Instantiate access token object
136140
*
137141
* @param $responseArray
138142
*
@@ -160,4 +164,14 @@ public static function fromResponseArray($responseArray)
160164
$responseArray['expires_in'] + time()
161165
);
162166
}
167+
168+
public function jsonSerialize()
169+
{
170+
return [
171+
'token' => $this->getToken(),
172+
'expiresAt' => $this->getExpiresAt(),
173+
];
174+
}
175+
176+
163177
}

src/Client.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ protected static function responseToArray($response)
183183
}
184184

185185
/**
186-
* @param string $accessToken
186+
* Set AccessToken object
187+
*
188+
* @param AccessToken $accessToken
187189
*
188190
* @return Client
189191
*/

src/Exception.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,26 @@
1616

1717
namespace LinkedIn;
1818

19+
/**
20+
* Class Exception
21+
* @package LinkedIn
22+
*/
1923
class Exception extends \Exception
2024
{
25+
/**
26+
* Error's description
27+
*
28+
* @var string
29+
*/
2130
protected $description;
31+
32+
/**
33+
* Exception constructor.
34+
* @param string $message
35+
* @param int $code
36+
* @param null $previousException
37+
* @param $description
38+
*/
2239
public function __construct(
2340
$message = "",
2441
$code = 0,
@@ -30,7 +47,9 @@ public function __construct(
3047
}
3148

3249
/**
33-
* @return mixed
50+
* Get textual description that summarizes error.
51+
*
52+
* @return string
3453
*/
3554
public function getDescription()
3655
{

src/Scope.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,30 @@
1616

1717
namespace LinkedIn;
1818

19+
/**
20+
* Class Scope defines list of available permissions
21+
*
22+
* @package LinkedIn
23+
*/
1924
class Scope extends AbstractEnum
2025
{
26+
/**
27+
* Allows to read basic information about profile, such as name
28+
*/
2129
const READ_BASIC_PROFILE = 'r_basicprofile';
30+
31+
/**
32+
* Enables access to email address field
33+
*/
2234
const READ_EMAIL_ADDRESS = 'r_emailaddress';
35+
36+
/**
37+
* Enables to manage business company, retrieve analytics
38+
*/
2339
const MANAGE_COMPANY = 'rw_company_admin';
40+
41+
/**
42+
* Enables ability to share content on LinkedIn
43+
*/
2444
const SHARING = 'w_share';
2545
}

tests/AccessTokenTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,10 @@ public function testToString()
112112
$token = new AccessToken('hello', 1);
113113
$this->assertEquals('hello', (string) $token);
114114
}
115+
116+
public function testJsonSerialize()
117+
{
118+
$token = new AccessToken('hello', 1);
119+
$this->assertEquals('{"token":"hello","expiresAt":1}', json_encode($token));
120+
}
115121
}

0 commit comments

Comments
 (0)