/libraries/joomla/linkedin/jobs.php

https://github.com/Paladin/joomla-platform · PHP · 372 lines · 178 code · 62 blank · 132 comment · 31 complexity · 6aa8c390347f832bf2cdf2a29217e709 MD5 · raw file

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