Source for file people.php

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

Documentation generated on Tue, 19 Nov 2013 15:10:29 +0100 by phpDocumentor 1.4.3