Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
jobs.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 Jobs class for the Joomla Platform.
14  *
15  * @package Joomla.Platform
16  * @subpackage Linkedin
17  * @since 13.1
18  */
20 {
21  /**
22  * Method to retrieve detailed information about a job.
23  *
24  * @param integer $id The unique identifier for a job.
25  * @param string $fields Request fields beyond the default ones.
26  *
27  * @return array The decoded JSON response
28  *
29  * @since 13.1
30  */
31  public function getJob($id, $fields = null)
32  {
33  $token = $this->oauth->getToken();
34 
35  // Set parameters.
36  $parameters = array(
37  'oauth_token' => $token['key']
38  );
39 
40  // Set the API base
41  $base = '/v1/jobs/' . $id;
42 
43  // Set request parameters.
44  $data['format'] = 'json';
45 
46  // Check if fields is specified.
47  if ($fields)
48  {
49  $base .= ':' . $fields;
50  }
51 
52  // Build the request path.
53  $path = $this->getOption('api.url') . $base;
54 
55  // Send the request.
56  $response = $this->oauth->oauthRequest($path, 'GET', $parameters, $data);
57 
58  return json_decode($response->body);
59  }
60 
61  /**
62  * Method to get a list of bookmarked jobs for the current member.
63  *
64  * @param string $fields Request fields beyond the default ones.
65  *
66  * @return array The decoded JSON response
67  *
68  * @since 13.1
69  */
70  public function getBookmarked($fields = null)
71  {
72  $token = $this->oauth->getToken();
73 
74  // Set parameters.
75  $parameters = array(
76  'oauth_token' => $token['key']
77  );
78 
79  // Set the API base
80  $base = '/v1/people/~/job-bookmarks';
81 
82  // Set request parameters.
83  $data['format'] = 'json';
84 
85  // Check if fields is specified.
86  if ($fields)
87  {
88  $base .= ':' . $fields;
89  }
90 
91  // Build the request path.
92  $path = $this->getOption('api.url') . $base;
93 
94  // Send the request.
95  $response = $this->oauth->oauthRequest($path, 'GET', $parameters, $data);
96 
97  return json_decode($response->body);
98  }
99 
100  /**
101  * Method to bookmark a job to the current user's account.
102  *
103  * @param integer $id The unique identifier for a job.
104  *
105  * @return array The decoded JSON response
106  *
107  * @since 13.1
108  */
109  public function bookmark($id)
110  {
111  $token = $this->oauth->getToken();
112 
113  // Set parameters.
114  $parameters = array(
115  'oauth_token' => $token['key']
116  );
117 
118  // Set the success response code.
119  $this->oauth->setOption('success_code', 201);
120 
121  // Set the API base
122  $base = '/v1/people/~/job-bookmarks';
123 
124  // Build xml.
125  $xml = '<job-bookmark><job><id>' . $id . '</id></job></job-bookmark>';
126 
127  // Build the request path.
128  $path = $this->getOption('api.url') . $base;
129 
130  $header['Content-Type'] = 'text/xml';
131 
132  // Send the request.
133  $response = $this->oauth->oauthRequest($path, 'POST', $parameters, $xml, $header);
134 
135  return $response;
136  }
137 
138  /**
139  * Method to delete a bookmark.
140  *
141  * @param integer $id The unique identifier for a job.
142  *
143  * @return array The decoded JSON response
144  *
145  * @since 13.1
146  */
147  public function deleteBookmark($id)
148  {
149  $token = $this->oauth->getToken();
150 
151  // Set parameters.
152  $parameters = array(
153  'oauth_token' => $token['key']
154  );
155 
156  // Set the success response code.
157  $this->oauth->setOption('success_code', 204);
158 
159  // Set the API base
160  $base = '/v1/people/~/job-bookmarks/' . $id;
161 
162  // Build the request path.
163  $path = $this->getOption('api.url') . $base;
164 
165  // Send the request.
166  $response = $this->oauth->oauthRequest($path, 'DELETE', $parameters);
167 
168  return $response;
169  }
170 
171  /**
172  * Method to retrieve job suggestions for the current user.
173  *
174  * @param string $fields Request fields beyond the default ones.
175  * @param integer $start Starting location within the result set for paginated returns.
176  * @param integer $count The number of results returned.
177  *
178  * @return array The decoded JSON response
179  *
180  * @since 13.1
181  */
182  public function getSuggested($fields = null, $start = 0, $count = 0)
183  {
184  $token = $this->oauth->getToken();
185 
186  // Set parameters.
187  $parameters = array(
188  'oauth_token' => $token['key']
189  );
190 
191  // Set the API base
192  $base = '/v1/people/~/suggestions/job-suggestions';
193 
194  $data['format'] = 'json';
195 
196  // Check if fields is specified.
197  if ($fields)
198  {
199  $base .= ':' . $fields;
200  }
201 
202  // Check if start is specified.
203  if ($start > 0)
204  {
205  $data['start'] = $start;
206  }
207 
208  // Check if count is specified.
209  if ($count > 0)
210  {
211  $data['count'] = $count;
212  }
213 
214  // Build the request path.
215  $path = $this->getOption('api.url') . $base;
216 
217  // Send the request.
218  $response = $this->oauth->oauthRequest($path, 'GET', $parameters, $data);
219 
220  return json_decode($response->body);
221  }
222 
223  /**
224  * Method to search across LinkedIn's job postings.
225  *
226  * @param string $fields Request fields beyond the default ones.
227  * @param string $keywords Members who have all the keywords anywhere in their profile.
228  * @param string $company_name Jobs with a matching company name.
229  * @param string $job_title Matches jobs with the same job title.
230  * @param string $country_code Matches members with a location in a specific country. Values are defined in by ISO 3166 standard.
231  * Country codes must be in all lower case.
232  * @param integer $postal_code Matches members centered around a Postal Code. Must be combined with the country-code parameter.
233  * Not supported for all countries.
234  * @param integer $distance Matches members within a distance from a central point. This is measured in miles.
235  * @param string $facets Facet buckets to return, e.g. location.
236  * @param array $facet Array of facet values to search over. Contains values for company, date-posted, location, job-function,
237  * industry, and salary, in exactly this order, null must be specified for an element if no value.
238  * @param integer $start Starting location within the result set for paginated returns.
239  * @param integer $count The number of results returned.
240  * @param string $sort Controls the search result order. There are four options: R (relationship), DA (date-posted-asc),
241  * DD (date-posted-desc).
242  *
243  * @return array The decoded JSON response
244  *
245  * @since 13.1
246  */
247  public function search($fields = null, $keywords = null, $company_name = null, $job_title = null, $country_code = null, $postal_code = null,
248  $distance = null, $facets = null, $facet = null, $start = 0, $count = 0, $sort = null)
249  {
250  $token = $this->oauth->getToken();
251 
252  // Set parameters.
253  $parameters = array(
254  'oauth_token' => $token['key']
255  );
256 
257  // Set the API base
258  $base = '/v1/job-search';
259 
260  $data['format'] = 'json';
261 
262  // Check if fields is specified.
263  if ($fields)
264  {
265  $base .= ':' . $fields;
266  }
267 
268  // Check if keywords is specified.
269  if ($keywords)
270  {
271  $data['keywords'] = $keywords;
272  }
273 
274  // Check if company-name is specified.
275  if ($company_name)
276  {
277  $data['company-name'] = $company_name;
278  }
279 
280  // Check if job-title is specified.
281  if ($job_title)
282  {
283  $data['job-title'] = $job_title;
284  }
285 
286  // Check if country_code is specified.
287  if ($country_code)
288  {
289  $data['country-code'] = $country_code;
290  }
291 
292  // Check if postal_code is specified.
293  if ($postal_code)
294  {
295  $data['postal-code'] = $postal_code;
296  }
297 
298  // Check if distance is specified.
299  if ($distance)
300  {
301  $data['distance'] = $distance;
302  }
303 
304  // Check if facets is specified.
305  if ($facets)
306  {
307  $data['facets'] = $facets;
308  }
309 
310  // Check if facet is specified.
311  if ($facet)
312  {
313  $data['facet'] = array();
314  for ($i = 0; $i < count($facet); $i++)
315  {
316  if ($facet[$i])
317  {
318  if ($i == 0)
319  {
320  $data['facet'][] = 'company,' . $this->oauth->safeEncode($facet[$i]);
321  }
322  if ($i == 1)
323  {
324  $data['facet'][] = 'date-posted,' . $facet[$i];
325  }
326  if ($i == 2)
327  {
328  $data['facet'][] = 'location,' . $facet[$i];
329  }
330  if ($i == 3)
331  {
332  $data['facet'][] = 'job-function,' . $this->oauth->safeEncode($facet[$i]);
333  }
334  if ($i == 4)
335  {
336  $data['facet'][] = 'industry,' . $facet[$i];
337  }
338  if ($i == 5)
339  {
340  $data['facet'][] = 'salary,' . $facet[$i];
341  }
342  }
343  }
344  }
345 
346  // Check if start is specified.
347  if ($start > 0)
348  {
349  $data['start'] = $start;
350  }
351 
352  // Check if count is specified.
353  if ($count > 0)
354  {
355  $data['count'] = $count;
356  }
357 
358  // Check if sort is specified.
359  if ($sort)
360  {
361  $data['sort'] = $sort;
362  }
363 
364  // Build the request path.
365  $path = $this->getOption('api.url') . $base;
366 
367  // Send the request.
368  $response = $this->oauth->oauthRequest($path, 'GET', $parameters, $data);
369 
370  return json_decode($response->body);
371  }
372 }