Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
companies.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 Companies class for the Joomla Platform.
14  *
15  * @package Joomla.Platform
16  * @subpackage Linkedin
17  * @since 13.1
18  */
20 {
21  /**
22  * Method to retrieve companies using a company ID, a universal name, or an email domain.
23  *
24  * @param integer $id The unique internal numeric company identifier.
25  * @param string $name The unique string identifier for a company.
26  * @param string $domain Company email domains.
27  * @param string $fields Request fields beyond the default ones.
28  *
29  * @return array The decoded JSON response
30  *
31  * @since 13.1
32  * @throws RuntimeException
33  */
34  public function getCompanies($id = null, $name = null, $domain = null, $fields = null)
35  {
36  // At least one value is needed to retrieve data.
37  if ($id == null && $name == null && $domain == null)
38  {
39  // We don't have a valid entry
40  throw new RuntimeException('You must specify a company ID, a universal name, or an email domain.');
41  }
42 
43  $token = $this->oauth->getToken();
44 
45  // Set parameters.
46  $parameters = array(
47  'oauth_token' => $token['key']
48  );
49 
50  // Set the API base
51  $base = '/v1/companies';
52 
53  if ($id && $name)
54  {
55  $base .= '::(' . $id . ',universal-name=' . $name . ')';
56  }
57  elseif ($id)
58  {
59  $base .= '/' . $id;
60  }
61  elseif ($name)
62  {
63  $base .= '/universal-name=' . $name;
64  }
65 
66  // Set request parameters.
67  $data['format'] = 'json';
68 
69  if ($domain)
70  {
71  $data['email-domain'] = $domain;
72  }
73 
74  // Check if fields is specified.
75  if ($fields)
76  {
77  $base .= ':' . $fields;
78  }
79 
80  // Build the request path.
81  $path = $this->getOption('api.url') . $base;
82 
83  // Send the request.
84  $response = $this->oauth->oauthRequest($path, 'GET', $parameters, $data);
85 
86  return json_decode($response->body);
87  }
88 
89  /**
90  * Method to read shares for a particular company .
91  *
92  * @param string $id The unique company identifier.
93  * @param string $type Any valid Company Update Type from the table: https://developer.linkedin.com/reading-company-updates.
94  * @param integer $count Maximum number of updates to return.
95  * @param integer $start The offset by which to start Network Update pagination.
96  *
97  * @return array The decoded JSON response
98  *
99  * @since 13.1
100  */
101  public function getUpdates($id, $type = null, $count = 0, $start = 0)
102  {
103  $token = $this->oauth->getToken();
104 
105  // Set parameters.
106  $parameters = array(
107  'oauth_token' => $token['key']
108  );
109 
110  // Set the API base
111  $base = '/v1/companies/' . $id . '/updates';
112 
113  // Set request parameters.
114  $data['format'] = 'json';
115 
116  // Check if type is specified.
117  if ($type)
118  {
119  $data['event-type'] = $type;
120  }
121 
122  // Check if count is specified.
123  if ($count > 0)
124  {
125  $data['count'] = $count;
126  }
127 
128  // Check if start is specified.
129  if ($start > 0)
130  {
131  $data['start'] = $start;
132  }
133 
134  // Build the request path.
135  $path = $this->getOption('api.url') . $base;
136 
137  // Send the request.
138  $response = $this->oauth->oauthRequest($path, 'GET', $parameters, $data);
139 
140  return json_decode($response->body);
141  }
142 
143  /**
144  * Method to search across company pages.
145  *
146  * @param string $fields Request fields beyond the default ones.
147  * @param string $keywords Members who have all the keywords anywhere in their profile.
148  * @param boolean $hq Matching companies by the headquarters location. When this is set to "true" and a location facet is used,
149  * this restricts returned companies to only those whose headquarters resides in the specified location.
150  * @param string $facets Facet buckets to return, e.g. location.
151  * @param array $facet Array of facet values to search over. Contains values for location, industry, network, company-size,
152  * num-followers-range and fortune, in exactly this order, null must be specified for an element if no value.
153  * @param integer $start Starting location within the result set for paginated returns.
154  * @param integer $count The number of results returned.
155  * @param string $sort Controls the search result order. There are four options: relevance, relationship,
156  * followers and company-size.
157  *
158  * @return array The decoded JSON response
159  *
160  * @since 13.1
161  */
162  public function search($fields = null, $keywords = null, $hq = false, $facets = null, $facet = null, $start = 0, $count = 0, $sort = null)
163  {
164  $token = $this->oauth->getToken();
165 
166  // Set parameters.
167  $parameters = array(
168  'oauth_token' => $token['key']
169  );
170 
171  // Set the API base
172  $base = '/v1/company-search';
173 
174  $data['format'] = 'json';
175 
176  // Check if fields is specified.
177  if ($fields)
178  {
179  $base .= ':' . $fields;
180  }
181 
182  // Check if keywords is specified.
183  if ($keywords)
184  {
185  $data['keywords'] = $keywords;
186  }
187 
188  // Check if hq is true.
189  if ($hq)
190  {
191  $data['hq-only'] = $hq;
192  }
193 
194  // Check if facets is specified.
195  if ($facets)
196  {
197  $data['facets'] = $facets;
198  }
199 
200  // Check if facet is specified.
201  if ($facet)
202  {
203  $data['facet'] = array();
204  for ($i = 0; $i < count($facet); $i++)
205  {
206  if ($facet[$i])
207  {
208  if ($i == 0)
209  {
210  $data['facet'][] = 'location,' . $facet[$i];
211  }
212  if ($i == 1)
213  {
214  $data['facet'][] = 'industry,' . $facet[$i];
215  }
216  if ($i == 2)
217  {
218  $data['facet'][] = 'network,' . $facet[$i];
219  }
220  if ($i == 3)
221  {
222  $data['facet'][] = 'company-size,' . $facet[$i];
223  }
224  if ($i == 4)
225  {
226  $data['facet'][] = 'num-followers-range,' . $facet[$i];
227  }
228  if ($i == 5)
229  {
230  $data['facet'][] = 'fortune,' . $facet[$i];
231  }
232  }
233  }
234  }
235 
236  // Check if start is specified.
237  if ($start > 0)
238  {
239  $data['start'] = $start;
240  }
241 
242  // Check if count is specified.
243  if ($count > 0)
244  {
245  $data['count'] = $count;
246  }
247 
248  // Check if sort is specified.
249  if ($sort)
250  {
251  $data['sort'] = $sort;
252  }
253 
254  // Build the request path.
255  $path = $this->getOption('api.url') . $base;
256 
257  // Send the request.
258  $response = $this->oauth->oauthRequest($path, 'GET', $parameters, $data);
259 
260  return json_decode($response->body);
261  }
262 
263  /**
264  * Method to get a list of companies the current member is following.
265  *
266  * @param string $fields Request fields beyond the default ones.
267  *
268  * @return array The decoded JSON response
269  *
270  * @since 13.1
271  */
272  public function getFollowed($fields = null)
273  {
274  $token = $this->oauth->getToken();
275 
276  // Set parameters.
277  $parameters = array(
278  'oauth_token' => $token['key']
279  );
280 
281  // Set the API base
282  $base = '/v1/people/~/following/companies';
283 
284  $data['format'] = 'json';
285 
286  // Check if fields is specified.
287  if ($fields)
288  {
289  $base .= ':' . $fields;
290  }
291 
292  // Build the request path.
293  $path = $this->getOption('api.url') . $base;
294 
295  // Send the request.
296  $response = $this->oauth->oauthRequest($path, 'GET', $parameters, $data);
297 
298  return json_decode($response->body);
299  }
300 
301  /**
302  * Method to follow a company.
303  *
304  * @param string $id The unique identifier for a company.
305  *
306  * @return array The decoded JSON response
307  *
308  * @since 13.1
309  */
310  public function follow($id)
311  {
312  $token = $this->oauth->getToken();
313 
314  // Set parameters.
315  $parameters = array(
316  'oauth_token' => $token['key']
317  );
318 
319  // Set the success response code.
320  $this->oauth->setOption('success_code', 201);
321 
322  // Set the API base
323  $base = '/v1/people/~/following/companies';
324 
325  // Build xml.
326  $xml = '<company><id>' . $id . '</id></company>';
327 
328  // Build the request path.
329  $path = $this->getOption('api.url') . $base;
330 
331  $header['Content-Type'] = 'text/xml';
332 
333  // Send the request.
334  $response = $this->oauth->oauthRequest($path, 'POST', $parameters, $xml, $header);
335 
336  return $response;
337  }
338 
339  /**
340  * Method to unfollow a company.
341  *
342  * @param string $id The unique identifier for a company.
343  *
344  * @return array The decoded JSON response
345  *
346  * @since 13.1
347  */
348  public function unfollow($id)
349  {
350  $token = $this->oauth->getToken();
351 
352  // Set parameters.
353  $parameters = array(
354  'oauth_token' => $token['key']
355  );
356 
357  // Set the success response code.
358  $this->oauth->setOption('success_code', 204);
359 
360  // Set the API base
361  $base = '/v1/people/~/following/companies/id=' . $id;
362 
363  // Build the request path.
364  $path = $this->getOption('api.url') . $base;
365 
366  // Send the request.
367  $response = $this->oauth->oauthRequest($path, 'DELETE', $parameters);
368 
369  return $response;
370  }
371 
372  /**
373  * Method to get a collection of suggested companies for the current user.
374  *
375  * @param string $fields Request fields beyond the default ones.
376  * @param integer $start Starting location within the result set for paginated returns.
377  * @param integer $count The number of results returned.
378  *
379  * @return array The decoded JSON response
380  *
381  * @since 13.1
382  */
383  public function getSuggested($fields = null, $start = 0, $count = 0)
384  {
385  $token = $this->oauth->getToken();
386 
387  // Set parameters.
388  $parameters = array(
389  'oauth_token' => $token['key']
390  );
391 
392  // Set the API base
393  $base = '/v1/people/~/suggestions/to-follow/companies';
394 
395  $data['format'] = 'json';
396 
397  // Check if fields is specified.
398  if ($fields)
399  {
400  $base .= ':' . $fields;
401  }
402 
403  // Check if start is specified.
404  if ($start > 0)
405  {
406  $data['start'] = $start;
407  }
408 
409  // Check if count is specified.
410  if ($count > 0)
411  {
412  $data['count'] = $count;
413  }
414 
415  // Build the request path.
416  $path = $this->getOption('api.url') . $base;
417 
418  // Send the request.
419  $response = $this->oauth->oauthRequest($path, 'GET', $parameters, $data);
420 
421  return json_decode($response->body);
422  }
423 
424  /**
425  * Method to get a collection of suggested companies for the current user.
426  *
427  * @param string $id The unique identifier for a company.
428  * @param string $fields Request fields beyond the default ones.
429  * @param integer $start Starting location within the result set for paginated returns.
430  * @param integer $count The number of results returned.
431  *
432  * @return array The decoded JSON response
433  *
434  * @since 13.1
435  */
436  public function getProducts($id, $fields = null, $start = 0, $count = 0)
437  {
438  $token = $this->oauth->getToken();
439 
440  // Set parameters.
441  $parameters = array(
442  'oauth_token' => $token['key']
443  );
444 
445  // Set the API base
446  $base = '/v1/companies/' . $id . '/products';
447 
448  $data['format'] = 'json';
449 
450  // Check if fields is specified.
451  if ($fields)
452  {
453  $base .= ':' . $fields;
454  }
455 
456  // Check if start is specified.
457  if ($start > 0)
458  {
459  $data['start'] = $start;
460  }
461 
462  // Check if count is specified.
463  if ($count > 0)
464  {
465  $data['count'] = $count;
466  }
467 
468  // Build the request path.
469  $path = $this->getOption('api.url') . $base;
470 
471  // Send the request.
472  $response = $this->oauth->oauthRequest($path, 'GET', $parameters, $data);
473 
474  return json_decode($response->body);
475  }
476 }