1 | <?php |
||
32 | class LinkedIn |
||
33 | { |
||
34 | /** |
||
35 | * The OAuth access token received in exchange for a valid authorization |
||
36 | * code. null means the access token has yet to be determined. |
||
37 | * |
||
38 | * @var AccessToken |
||
39 | */ |
||
40 | protected $accessToken = null; |
||
41 | |||
42 | /** |
||
43 | * @var string format |
||
44 | */ |
||
45 | private $format; |
||
46 | |||
47 | /** |
||
48 | * @var string responseFormat |
||
49 | */ |
||
50 | private $responseDataType; |
||
51 | |||
52 | /** |
||
53 | * @var ResponseInterface |
||
54 | */ |
||
55 | private $lastResponse; |
||
56 | |||
57 | /** |
||
58 | * @var RequestManager |
||
59 | */ |
||
60 | private $requestManager; |
||
61 | |||
62 | /** |
||
63 | * @var Authenticator |
||
64 | */ |
||
65 | private $authenticator; |
||
66 | |||
67 | /** |
||
68 | * @var UrlGeneratorInterface |
||
69 | */ |
||
70 | private $urlGenerator; |
||
71 | |||
72 | /** |
||
73 | * Constructor. |
||
74 | * |
||
75 | * @param string $appId |
||
76 | * @param string $appSecret |
||
77 | * @param string $format 'json', 'xml' |
||
78 | * @param string $responseDataType 'array', 'string', 'simple_xml' 'psr7', 'stream' |
||
79 | */ |
||
80 | public function __construct($appId, $appSecret, $format = 'json', $responseDataType = 'array') |
||
88 | |||
89 | /** |
||
90 | * Is the current user authenticated? |
||
91 | * |
||
92 | * @return bool |
||
93 | */ |
||
94 | public function isAuthenticated() |
||
105 | |||
106 | /** |
||
107 | * Make an API call. Read about what calls that are possible here: https://developer.linkedin.com/docs/rest-api. |
||
108 | * |
||
109 | * Example: |
||
110 | * $linkedIn->api('GET', '/v1/people/~:(id,firstName,lastName,headline)'); |
||
111 | * |
||
112 | * The options: |
||
113 | * - body: the body of the request |
||
114 | * - format: the format you are using to send the request |
||
115 | * - headers: array with headers to use |
||
116 | * - response_data_type: the data type to get back |
||
117 | * - query: query parameters to the request |
||
118 | * |
||
119 | * @param string $method This is the HTTP verb |
||
120 | * @param string $resource everything after the domain in the URL. |
||
121 | * @param array $options See the readme for option description. |
||
122 | * |
||
123 | * @return mixed this depends on the response_data_type parameter. |
||
124 | */ |
||
125 | public function api($method, $resource, array $options = array()) |
||
152 | |||
153 | /** |
||
154 | * Modify and filter the request options. Make sure we use the correct query parameters and headers. |
||
155 | * |
||
156 | * @param array &$options |
||
157 | * |
||
158 | * @return string the request format to use |
||
159 | */ |
||
160 | protected function filterRequestOption(array &$options) |
||
186 | |||
187 | /** |
||
188 | * Get a login URL where the user can put his/hers LinkedIn credentials and authorize the application. |
||
189 | * |
||
190 | * The options: |
||
191 | * - redirect_uri: the url to go to after a successful login |
||
192 | * - scope: comma (or space) separated list of requested extended permissions |
||
193 | * |
||
194 | * @param array $options Provide custom parameters |
||
195 | * |
||
196 | * @return string The URL for the login flow |
||
197 | */ |
||
198 | public function getLoginUrl($options = array()) |
||
202 | |||
203 | /** |
||
204 | * See docs for LinkedIn::api(). |
||
205 | * |
||
206 | * @param string $resource |
||
207 | * @param array $options |
||
208 | * |
||
209 | * @return mixed |
||
210 | */ |
||
211 | public function get($resource, array $options = array()) |
||
215 | |||
216 | /** |
||
217 | * See docs for LinkedIn::api(). |
||
218 | * |
||
219 | * @param string $resource |
||
220 | * @param array $options |
||
221 | * |
||
222 | * @return mixed |
||
223 | */ |
||
224 | public function post($resource, array $options = array()) |
||
228 | |||
229 | /** |
||
230 | * Clear the data storage. This will forget everything about the user and authentication process. |
||
231 | * |
||
232 | * @return $this |
||
233 | */ |
||
234 | public function clearStorage() |
||
240 | |||
241 | /** |
||
242 | * If the user has canceled the login we will return with an error. |
||
243 | * |
||
244 | * @return bool |
||
245 | */ |
||
246 | public function hasError() |
||
250 | |||
251 | /** |
||
252 | * Returns a LoginError or null. |
||
253 | * |
||
254 | * @return LoginError|null |
||
255 | */ |
||
256 | public function getError() |
||
262 | |||
263 | /** |
||
264 | * Get the default format to use when sending requests. |
||
265 | * |
||
266 | * @return string |
||
267 | */ |
||
268 | public function getFormat() |
||
272 | |||
273 | /** |
||
274 | * Set the default format to use when sending requests. |
||
275 | * |
||
276 | * @param string $format |
||
277 | * |
||
278 | * @return $this |
||
279 | */ |
||
280 | public function setFormat($format) |
||
286 | |||
287 | /** |
||
288 | * Get the default data type to be returned as a response. |
||
289 | * |
||
290 | * @return string |
||
291 | */ |
||
292 | public function getResponseDataType() |
||
296 | |||
297 | /** |
||
298 | * Set the default data type to be returned as a response. |
||
299 | * |
||
300 | * @param string $responseDataType |
||
301 | * |
||
302 | * @return $this |
||
303 | */ |
||
304 | public function setResponseDataType($responseDataType) |
||
310 | |||
311 | /** |
||
312 | * Get the last response. This will always return a PSR-7 response no matter of the data type used. |
||
313 | * |
||
314 | * @return ResponseInterface|null |
||
315 | */ |
||
316 | public function getLastResponse() |
||
320 | |||
321 | /** |
||
322 | * Returns an access token. If we do not have one in memory, try to fetch one from a *code* in the $_REQUEST. |
||
323 | * |
||
324 | * @return AccessToken|null The access token of null if the access token is not found |
||
325 | */ |
||
326 | public function getAccessToken() |
||
337 | |||
338 | /** |
||
339 | * If you have stored a previous access token in a storage (database) you could set it here. After setting an |
||
340 | * access token you have to make sure to verify it is still valid by running LinkedIn::isAuthenticated. |
||
341 | * |
||
342 | * @param string|AccessToken $accessToken |
||
343 | * |
||
344 | * @return $this |
||
345 | */ |
||
346 | public function setAccessToken($accessToken) |
||
356 | |||
357 | /** |
||
358 | * Set a URL generator. |
||
359 | * |
||
360 | * @param UrlGeneratorInterface $urlGenerator |
||
361 | * |
||
362 | * @return $this |
||
363 | */ |
||
364 | public function setUrlGenerator(UrlGeneratorInterface $urlGenerator) |
||
370 | |||
371 | /** |
||
372 | * @return UrlGeneratorInterface |
||
373 | */ |
||
374 | protected function getUrlGenerator() |
||
382 | |||
383 | /** |
||
384 | * Set a data storage. |
||
385 | * |
||
386 | * @param DataStorageInterface $storage |
||
387 | * |
||
388 | * @return $this |
||
389 | */ |
||
390 | public function setStorage(DataStorageInterface $storage) |
||
396 | |||
397 | /** |
||
398 | * Set a http client. |
||
399 | * |
||
400 | * @param HttpClient $client |
||
401 | * |
||
402 | * @return $this |
||
403 | */ |
||
404 | public function setHttpClient(HttpClient $client) |
||
410 | |||
411 | /** |
||
412 | * @return RequestManager |
||
413 | */ |
||
414 | protected function getRequestManager() |
||
418 | |||
419 | /** |
||
420 | * @return Authenticator |
||
421 | */ |
||
422 | protected function getAuthenticator() |
||
426 | } |
||
427 |