Source for file communications.php

Documentation is available at communications.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 Social Communications class for the Joomla Platform.
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Linkedin
  17.  * @since       13.1
  18.  */
  19. {
  20.     /**
  21.      * Method used to invite people.
  22.      *
  23.      * @param   string  $email       A string containing email of the recipient.
  24.      * @param   string  $first_name  A string containing frist name of the recipient.
  25.      * @param   string  $last_name   A string containing last name of the recipient.
  26.      * @param   string  $subject     The subject of the message that will be sent to the recipient
  27.      * @param   string  $body        A text of the message.
  28.      * @param   string  $connection  Only connecting as a 'friend' is supported presently.
  29.      *
  30.      * @return  array  The decoded JSON response
  31.      *
  32.      * @since   13.1
  33.      */
  34.     public function inviteByEmail($email$first_name$last_name$subject$body$connection 'friend')
  35.     {
  36.         $token $this->oauth->getToken();
  37.  
  38.         // Set parameters.
  39.         $parameters array(
  40.             'oauth_token' => $token['key']
  41.         );
  42.  
  43.         // Set the success response code.
  44.         $this->oauth->setOption('success_code'201);
  45.  
  46.         // Set the API base.
  47.         $base '/v1/people/~/mailbox';
  48.  
  49.         // Build the xml.
  50.         $xml '<mailbox-item>
  51.                   <recipients>
  52.                       <recipient>
  53.                         <person path="/people/email=' $email '">
  54.                             <first-name>' $first_name '</first-name>
  55.                             <last-name>' $last_name '</last-name>
  56.                         </person>
  57.                     </recipient>
  58.                 </recipients>
  59.                 <subject>' $subject '</subject>
  60.                 <body>' $body '</body>
  61.                 <item-content>
  62.                     <invitation-request>
  63.                       <connect-type>' $connection '</connect-type>
  64.                     </invitation-request>
  65.                 </item-content>
  66.              </mailbox-item>';
  67.  
  68.         $header['Content-Type''text/xml';
  69.  
  70.         // Build the request path.
  71.         $path $this->getOption('api.url'$base;
  72.  
  73.         // Send the request.
  74.         $response $this->oauth->oauthRequest($path'POST'$parameters$xml$header);
  75.  
  76.         return $response;
  77.     }
  78.  
  79.     /**
  80.      * Method used to invite people.
  81.      *
  82.      * @param   string  $id          Member id.
  83.      * @param   string  $first_name  A string containing frist name of the recipient.
  84.      * @param   string  $last_name   A string containing last name of the recipient.
  85.      * @param   string  $subject     The subject of the message that will be sent to the recipient
  86.      * @param   string  $body        A text of the message.
  87.      * @param   string  $connection  Only connecting as a 'friend' is supported presently.
  88.      *
  89.      * @return  array  The decoded JSON response
  90.      *
  91.      * @since   13.1
  92.      */
  93.     public function inviteById($id$first_name$last_name$subject$body$connection 'friend')
  94.     {
  95.         $token $this->oauth->getToken();
  96.  
  97.         // Set parameters.
  98.         $parameters array(
  99.             'oauth_token' => $token['key']
  100.         );
  101.  
  102.         // Set the API base for people search.
  103.         $base '/v1/people-search:(people:(api-standard-profile-request))';
  104.  
  105.         $data['format''json';
  106.         $data['first-name'$first_name;
  107.         $data['last-name'$last_name;
  108.  
  109.         // Build the request path.
  110.         $path $this->getOption('api.url'$base;
  111.  
  112.         // Send the request.
  113.         $response $this->oauth->oauthRequest($path'GET'$parameters$data);
  114.  
  115.         if (strpos($response->body'apiStandardProfileRequest'=== false)
  116.         {
  117.             throw new RuntimeException($response->body);
  118.         }
  119.  
  120.         // Get header value.
  121.         $value explode('"value": "'$response->body);
  122.         $value explode('"'$value[1]);
  123.         $value $value[0];
  124.  
  125.         // Split on the colon character.
  126.         $value explode(':'$value);
  127.         $name $value[0];
  128.         $value $value[1];
  129.  
  130.         // Set the success response code.
  131.         $this->oauth->setOption('success_code'201);
  132.  
  133.         // Set the API base.
  134.         $base '/v1/people/~/mailbox';
  135.  
  136.         // Build the xml.
  137.         $xml '<mailbox-item>
  138.                   <recipients>
  139.                       <recipient>
  140.                         <person path="/people/id=' $id '">
  141.                         </person>
  142.                     </recipient>
  143.                 </recipients>
  144.                 <subject>' $subject '</subject>
  145.                 <body>' $body '</body>
  146.                 <item-content>
  147.                     <invitation-request>
  148.                       <connect-type>' $connection '</connect-type>
  149.                       <authorization>
  150.                           <name>' $name '</name>
  151.                         <value>' $value '</value>
  152.                       </authorization>
  153.                     </invitation-request>
  154.                 </item-content>
  155.              </mailbox-item>';
  156.  
  157.         $header['Content-Type''text/xml';
  158.  
  159.         // Build the request path.
  160.         $path $this->getOption('api.url'$base;
  161.  
  162.         // Send the request.
  163.         $response $this->oauth->oauthRequest($path'POST'$parameters$xml$header);
  164.  
  165.         return $response;
  166.     }
  167.  
  168.     /**
  169.      * Method used to send messages via LinkedIn between two or more individuals connected to the member sending the message..
  170.      *
  171.      * @param   mixed   $recipient  A string containing the member id or an array of ids.
  172.      * @param   string  $subject    The subject of the message that will be sent to the recipient
  173.      * @param   string  $body       A text of the message.
  174.      *
  175.      * @return  array  The decoded JSON response
  176.      *
  177.      * @since   13.1
  178.      */
  179.     public function sendMessage($recipient$subject$body)
  180.     {
  181.         $token $this->oauth->getToken();
  182.  
  183.         // Set parameters.
  184.         $parameters array(
  185.             'oauth_token' => $token['key']
  186.         );
  187.  
  188.         // Set the success response code.
  189.         $this->oauth->setOption('success_code'201);
  190.  
  191.         // Set the API base.
  192.         $base '/v1/people/~/mailbox';
  193.  
  194.         // Build the xml.
  195.         $xml '<mailbox-item>
  196.                   <recipients>';
  197.  
  198.         if (is_array($recipient))
  199.         {
  200.             foreach ($recipient as $r)
  201.             {
  202.                 $xml .= '<recipient>
  203.                             <person path="/people/' $r '"/>
  204.                         </recipient>';
  205.             }
  206.         }
  207.  
  208.         $xml .= '</recipients>
  209.                  <subject>' $subject '</subject>
  210.                  <body>' $body '</body>
  211.                 </mailbox-item>';
  212.  
  213.         $header['Content-Type''text/xml';
  214.  
  215.         // Build the request path.
  216.         $path $this->getOption('api.url'$base;
  217.  
  218.         // Send the request.
  219.         $response $this->oauth->oauthRequest($path'POST'$parameters$xml$header);
  220.  
  221.         return $response;
  222.     }
  223. }

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