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