PageRenderTime 28ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/joomla/linkedin/companies.php

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