Source for file companies.php

Documentation is available at companies.php

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

Documentation generated on Tue, 19 Nov 2013 14:56:09 +0100 by phpDocumentor 1.4.3