Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
people.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Linkedin
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die();
11 
12 /**
13  * Linkedin API People class for the Joomla Platform.
14  *
15  * @package Joomla.Platform
16  * @subpackage Linkedin
17  * @since 13.1
18  */
20 {
21  /**
22  * Method to get a member's profile.
23  *
24  * @param string $id Member id of the profile you want.
25  * @param string $url The public profile URL.
26  * @param string $fields Request fields beyond the default ones.
27  * @param string $type Choosing public or standard profile.
28  * @param string $language A comma separated list of locales ordered from highest to lowest preference.
29  *
30  * @return array The decoded JSON response
31  *
32  * @since 13.1
33  */
34  public function getProfile($id = null, $url = null, $fields = null, $type = 'standard', $language = null)
35  {
36  $token = $this->oauth->getToken();
37 
38  // Set parameters.
39  $parameters = array(
40  'oauth_token' => $token['key']
41  );
42 
43  // Set the API base
44  $base = '/v1/people/';
45 
46  $data['format'] = 'json';
47 
48  // Check if a member id is specified.
49  if ($id)
50  {
51  $base .= 'id=' . $id;
52  }
53  elseif (!$url)
54  {
55  $base .= '~';
56  }
57 
58  // Check if profile url is specified.
59  if ($url)
60  {
61  $base .= 'url=' . $this->oauth->safeEncode($url);
62 
63  // Choose public profile
64  if (!strcmp($type, 'public'))
65  {
66  $base .= ':public';
67  }
68  }
69 
70  // Check if fields is specified.
71  if ($fields)
72  {
73  $base .= ':' . $fields;
74  }
75 
76  // Check if language is specified.
77  $header = array();
78  if ($language)
79  {
80  $header = array('Accept-Language' => $language);
81  }
82 
83  // Build the request path.
84  $path = $this->getOption('api.url') . $base;
85 
86  // Send the request.
87  $response = $this->oauth->oauthRequest($path, 'GET', $parameters, $data, $header);
88 
89  return json_decode($response->body);
90  }
91 
92  /**
93  * Method to get a list of connections for a user who has granted access to his/her account.
94  *
95  * @param string $fields Request fields beyond the default ones.
96  * @param integer $start Starting location within the result set for paginated returns.
97  * @param integer $count The number of results returned.
98  * @param string $modified Values are updated or new.
99  * @param string $modified_since Value as a Unix time stamp of milliseconds since epoch.
100  *
101  * @return array The decoded JSON response
102  *
103  * @since 13.1
104  */
105  public function getConnections($fields = null, $start = 0, $count = 500, $modified = null, $modified_since = null)
106  {
107  $token = $this->oauth->getToken();
108 
109  // Set parameters.
110  $parameters = array(
111  'oauth_token' => $token['key']
112  );
113 
114  // Set the API base
115  $base = '/v1/people/~/connections';
116 
117  $data['format'] = 'json';
118 
119  // Check if fields is specified.
120  if ($fields)
121  {
122  $base .= ':' . $fields;
123  }
124 
125  // Check if start is specified.
126  if ($start > 0)
127  {
128  $data['start'] = $start;
129  }
130  // Check if count is specified.
131  if ($count != 500)
132  {
133  $data['count'] = $count;
134  }
135 
136  // Check if modified is specified.
137  if ($modified)
138  {
139  $data['modified'] = $modified;
140  }
141 
142  // Check if modified_since is specified.
143  if ($modified_since)
144  {
145  $data['modified-since'] = $modified_since;
146  }
147 
148  // Build the request path.
149  $path = $this->getOption('api.url') . $base;
150 
151  // Send the request.
152  $response = $this->oauth->oauthRequest($path, 'GET', $parameters, $data);
153 
154  return json_decode($response->body);
155  }
156 
157  /**
158  * Method to get information about people.
159  *
160  * @param string $fields Request fields beyond the default ones. provide 'api-standard-profile-request'
161  * field for out of network profiles.
162  * @param string $keywords Members who have all the keywords anywhere in their profile.
163  * @param string $first_name Members with a matching first name. Matches must be exact.
164  * @param string $last_name Members with a matching last name. Matches must be exactly.
165  * @param string $company_name Members who have a matching company name on their profile.
166  * @param boolean $current_company A value of true matches members who currently work at the company specified in the company-name
167  * parameter.
168  * @param string $title Matches members with that title on their profile.
169  * @param boolean $current_title A value of true matches members whose title is currently the one specified in the title-name parameter.
170  * @param string $school_name Members who have a matching school name on their profile.
171  * @param string $current_school A value of true matches members who currently attend the school specified in the school-name parameter.
172  * @param string $country_code Matches members with a location in a specific country. Values are defined in by ISO 3166 standard.
173  * Country codes must be in all lower case.
174  * @param integer $postal_code Matches members centered around a Postal Code. Must be combined with the country-code parameter.
175  * Not supported for all countries.
176  * @param integer $distance Matches members within a distance from a central point. This is measured in miles.
177  * @param string $facets Facet buckets to return, e.g. location.
178  * @param array $facet Array of facet values to search over. Contains values for location, industry, network, language,
179  * current-company, past-company and school, in exactly this order, null must be specified for an element if no value.
180  * @param integer $start Starting location within the result set for paginated returns.
181  * @param integer $count The number of results returned.
182  * @param string $sort Controls the search result order. There are four options: connections, recommenders,
183  * distance and relevance.
184  *
185  * @return array The decoded JSON response
186  *
187  * @since 13.1
188  */
189  public function search($fields = null, $keywords = null, $first_name = null, $last_name = null, $company_name = null,
190  $current_company = null, $title = null, $current_title = null, $school_name = null, $current_school = null, $country_code = null,
191  $postal_code = null, $distance = null, $facets = null, $facet = null, $start = 0, $count = 10, $sort = null)
192  {
193  $token = $this->oauth->getToken();
194 
195  // Set parameters.
196  $parameters = array(
197  'oauth_token' => $token['key']
198  );
199 
200  // Set the API base
201  $base = '/v1/people-search';
202 
203  $data['format'] = 'json';
204 
205  // Check if fields is specified.
206  if ($fields)
207  {
208  $base .= ':' . $fields;
209  }
210 
211  // Check if keywords is specified.
212  if ($keywords)
213  {
214  $data['keywords'] = $keywords;
215  }
216 
217  // Check if first_name is specified.
218  if ($first_name)
219  {
220  $data['first-name'] = $first_name;
221  }
222 
223  // Check if last_name is specified.
224  if ($last_name)
225  {
226  $data['last-name'] = $last_name;
227  }
228 
229  // Check if company-name is specified.
230  if ($company_name)
231  {
232  $data['company-name'] = $company_name;
233  }
234 
235  // Check if current_company is specified.
236  if ($current_company)
237  {
238  $data['current-company'] = $current_company;
239  }
240 
241  // Check if title is specified.
242  if ($title)
243  {
244  $data['title'] = $title;
245  }
246 
247  // Check if current_title is specified.
248  if ($current_title)
249  {
250  $data['current-title'] = $current_title;
251  }
252 
253  // Check if school_name is specified.
254  if ($school_name)
255  {
256  $data['school-name'] = $school_name;
257  }
258 
259  // Check if current_school is specified.
260  if ($current_school)
261  {
262  $data['current-school'] = $current_school;
263  }
264 
265  // Check if country_code is specified.
266  if ($country_code)
267  {
268  $data['country-code'] = $country_code;
269  }
270 
271  // Check if postal_code is specified.
272  if ($postal_code)
273  {
274  $data['postal-code'] = $postal_code;
275  }
276 
277  // Check if distance is specified.
278  if ($distance)
279  {
280  $data['distance'] = $distance;
281  }
282 
283  // Check if facets is specified.
284  if ($facets)
285  {
286  $data['facets'] = $facets;
287  }
288 
289  // Check if facet is specified.
290  if ($facet)
291  {
292  $data['facet'] = array();
293  for ($i = 0; $i < count($facet); $i++)
294  {
295  if ($facet[$i])
296  {
297  if ($i == 0)
298  {
299  $data['facet'][] = 'location,' . $facet[$i];
300  }
301  if ($i == 1)
302  {
303  $data['facet'][] = 'industry,' . $facet[$i];
304  }
305  if ($i == 2)
306  {
307  $data['facet'][] = 'network,' . $facet[$i];
308  }
309  if ($i == 3)
310  {
311  $data['facet'][] = 'language,' . $facet[$i];
312  }
313  if ($i == 4)
314  {
315  $data['facet'][] = 'current-company,' . $facet[$i];
316  }
317  if ($i == 5)
318  {
319  $data['facet'][] = 'past-company,' . $facet[$i];
320  }
321  if ($i == 6)
322  {
323  $data['facet'][] = 'school,' . $facet[$i];
324  }
325  }
326  }
327  }
328 
329  // Check if start is specified.
330  if ($start > 0)
331  {
332  $data['start'] = $start;
333  }
334 
335  // Check if count is specified.
336  if ($count != 10)
337  {
338  $data['count'] = $count;
339  }
340 
341  // Check if sort is specified.
342  if ($sort)
343  {
344  $data['sort'] = $sort;
345  }
346 
347  // Build the request path.
348  $path = $this->getOption('api.url') . $base;
349 
350  // Send the request.
351  $response = $this->oauth->oauthRequest($path, 'GET', $parameters, $data);
352 
353  if (strpos($fields, 'api-standard-profile-request') === false)
354  {
355  return json_decode($response->body);
356  }
357 
358  // Get header name.
359  $name = explode('"name": "', $response->body);
360  $name = explode('"', $name[1]);
361  $name = $name[0];
362 
363  // Get header value.
364  $value = explode('"value": "', $response->body);
365  $value = explode('"', $value[1]);
366  $value = $value[0];
367 
368  // Get request url.
369  $url = explode('"url": "', $response->body);
370  $url = explode('"', $url[1]);
371  $url = $url[0];
372 
373  // Build header for out of network profile.
374  $header[$name] = $value;
375 
376  // Send the request.
377  $response = $this->oauth->oauthRequest($url, 'GET', $parameters, $data, $header);
378 
379  return json_decode($response->body);
380  }
381 }