Source for file stream.php

Documentation is available at stream.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 Stream class for the Joomla Platform.
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Linkedin
  17.  * @since       13.1
  18.  */
  19. {
  20.     /**
  21.      * Method to add a new share. Note: post must contain comment and/or (title and url).
  22.      *
  23.      * @param   string   $visibility   One of anyone: all members or connections-only: connections only.
  24.      * @param   string   $comment      Text of member's comment.
  25.      * @param   string   $title        Title of shared document.
  26.      * @param   string   $url          URL for shared content.
  27.      * @param   string   $image        URL for image of shared content.
  28.      * @param   string   $description  Description of shared content.
  29.      * @param   boolean  $twitter      True to have LinkedIn pass the status message along to a member's tethered Twitter account.
  30.      *
  31.      * @return  array  The decoded JSON response
  32.      *
  33.      * @since   13.1
  34.      * @throws  RuntimeException
  35.      */
  36.     public function share($visibility$comment null$title null$url null$image null$description null$twitter false)
  37.     {
  38.         $token $this->oauth->getToken();
  39.  
  40.         // Set parameters.
  41.         $parameters array(
  42.             'oauth_token' => $token['key']
  43.         );
  44.  
  45.         // Set the success response code.
  46.         $this->oauth->setOption('success_code'201);
  47.  
  48.         // Set the API base
  49.         $base '/v1/people/~/shares';
  50.  
  51.         // Check if twitter is true.
  52.         if ($twitter)
  53.         {
  54.             $base .= '?twitter-post=true';
  55.         }
  56.  
  57.         // Build xml.
  58.         $xml '<share>
  59.                   <visibility>
  60.                      <code>' $visibility '</code>
  61.                   </visibility>';
  62.  
  63.         // Check if comment specified.
  64.         if ($comment)
  65.         {
  66.             $xml .= '<comment>' $comment '</comment>';
  67.         }
  68.  
  69.         // Check if title and url are specified.
  70.         if ($title && $url)
  71.         {
  72.             $xml .= '<content>
  73.                        <title>' $title '</title>
  74.                        <submitted-url>' $url '</submitted-url>';
  75.  
  76.             // Check if image is specified.
  77.             if ($image)
  78.             {
  79.                 $xml .= '<submitted-image-url>' $image '</submitted-image-url>';
  80.             }
  81.  
  82.             // Check if descrption id specified.
  83.             if ($description)
  84.             {
  85.                 $xml .= '<description>' $description '</description>';
  86.             }
  87.  
  88.             $xml .= '</content>';
  89.         }
  90.         elseif (!$comment)
  91.         {
  92.             throw new RuntimeException('Post must contain comment and/or (title and url).');
  93.         }
  94.  
  95.         $xml .= '</share>';
  96.  
  97.         // Build the request path.
  98.         $path $this->getOption('api.url'$base;
  99.  
  100.         $header['Content-Type''text/xml';
  101.  
  102.         // Send the request.
  103.         $response $this->oauth->oauthRequest($path'POST'$parameters$xml$header);
  104.  
  105.         return $response;
  106.     }
  107.  
  108.     /**
  109.      * Method to reshare an existing share.
  110.      *
  111.      * @param   string   $visibility  One of anyone: all members or connections-only: connections only.
  112.      * @param   string   $id          The unique identifier for a share.
  113.      * @param   string   $comment     Text of member's comment.
  114.      * @param   boolean  $twitter     True to have LinkedIn pass the status message along to a member's tethered Twitter account.
  115.      *
  116.      * @return  array  The decoded JSON response
  117.      *
  118.      * @since   13.1
  119.      * @throws  RuntimeException
  120.      */
  121.     public function reshare($visibility$id$comment null$twitter false)
  122.     {
  123.         $token $this->oauth->getToken();
  124.  
  125.         // Set parameters.
  126.         $parameters array(
  127.             'oauth_token' => $token['key']
  128.         );
  129.  
  130.         // Set the success response code.
  131.         $this->oauth->setOption('success_code'201);
  132.  
  133.         // Set the API base
  134.         $base '/v1/people/~/shares';
  135.  
  136.         // Check if twitter is true.
  137.         if ($twitter)
  138.         {
  139.             $base .= '?twitter-post=true';
  140.         }
  141.  
  142.         // Build xml.
  143.         $xml '<share>
  144.                   <visibility>
  145.                      <code>' $visibility '</code>
  146.                   </visibility>';
  147.  
  148.         // Check if comment specified.
  149.         if ($comment)
  150.         {
  151.             $xml .= '<comment>' $comment '</comment>';
  152.         }
  153.  
  154.         $xml .= '   <attribution>
  155.                        <share>
  156.                              <id>' $id '</id>
  157.                        </share>
  158.                     </attribution>
  159.                  </share>';
  160.  
  161.         // Build the request path.
  162.         $path $this->getOption('api.url'$base;
  163.  
  164.         $header['Content-Type''text/xml';
  165.  
  166.         // Send the request.
  167.         $response $this->oauth->oauthRequest($path'POST'$parameters$xml$header);
  168.  
  169.         return $response;
  170.     }
  171.  
  172.     /**
  173.      * Method to get a particular member's current share.
  174.      *
  175.      * @param   string  $id   Member id of the profile you want.
  176.      * @param   string  $url  The public profile URL.
  177.      *
  178.      * @return  array  The decoded JSON response
  179.      *
  180.      * @since   13.1
  181.      */
  182.     public function getCurrentShare($id null$url null)
  183.     {
  184.         $token $this->oauth->getToken();
  185.  
  186.         // Set parameters.
  187.         $parameters array(
  188.             'oauth_token' => $token['key']
  189.         );
  190.  
  191.         // Set the API base
  192.         $base '/v1/people/';
  193.  
  194.         // Check if a member id is specified.
  195.         if ($id)
  196.         {
  197.             $base .= 'id=' $id;
  198.         }
  199.         elseif (!$url)
  200.         {
  201.             $base .= '~';
  202.         }
  203.  
  204.         // Check if profile url is specified.
  205.         if ($url)
  206.         {
  207.             $base .= 'url=' $this->oauth->safeEncode($url);
  208.         }
  209.  
  210.         $base .= ':(current-share)';
  211.  
  212.         // Set request parameters.
  213.         $data['format''json';
  214.  
  215.         // Build the request path.
  216.         $path $this->getOption('api.url'$base;
  217.  
  218.         // Send the request.
  219.         $response $this->oauth->oauthRequest($path'GET'$parameters$data);
  220.  
  221.         return json_decode($response->body);
  222.     }
  223.  
  224.     /**
  225.      * Method to get a particular member's current share.
  226.      *
  227.      * @param   string   $id    Member id of the profile you want.
  228.      * @param   string   $url   The public profile URL.
  229.      * @param   boolean  $self  Used to return member's feed. Omitted to return aggregated network feed.
  230.      *
  231.      * @return  array  The decoded JSON response
  232.      *
  233.      * @since   13.1
  234.      */
  235.     public function getShareStream($id null$url null$self true)
  236.     {
  237.         $token $this->oauth->getToken();
  238.  
  239.         // Set parameters.
  240.         $parameters array(
  241.             'oauth_token' => $token['key']
  242.         );
  243.  
  244.         // Set the API base
  245.         $base '/v1/people/';
  246.  
  247.         // Check if a member id is specified.
  248.         if ($id)
  249.         {
  250.             $base .= $id;
  251.         }
  252.         elseif (!$url)
  253.         {
  254.             $base .= '~';
  255.         }
  256.  
  257.         // Check if profile url is specified.
  258.         if ($url)
  259.         {
  260.             $base .= 'url=' $this->oauth->safeEncode($url);
  261.         }
  262.  
  263.         $base .= '/network';
  264.  
  265.         // Set request parameters.
  266.         $data['format''json';
  267.         $data['type''SHAR';
  268.  
  269.         // Check if self is true
  270.         if ($self)
  271.         {
  272.             $data['scope''self';
  273.         }
  274.  
  275.         // Build the request path.
  276.         $path $this->getOption('api.url'$base;
  277.  
  278.         // Send the request.
  279.         $response $this->oauth->oauthRequest($path'GET'$parameters$data);
  280.  
  281.         return json_decode($response->body);
  282.     }
  283.  
  284.     /**
  285.      * Method to get the users network updates.
  286.      *
  287.      * @param   string   $id      Member id.
  288.      * @param   boolean  $self    Used to return member's feed. Omitted to return aggregated network feed.
  289.      * @param   mixed    $type    String containing any valid Network Update Type from the table or an array of strings
  290.      *                                to specify more than one Network Update type.
  291.      * @param   integer  $count   Number of updates to return, with a maximum of 250.
  292.      * @param   integer  $start   The offset by which to start Network Update pagination.
  293.      * @param   string   $after   Timestamp after which to retrieve updates.
  294.      * @param   string   $before  Timestamp before which to retrieve updates.
  295.      * @param   boolean  $hidden  Whether to display updates from people the member has chosen to "hide" from their update stream.
  296.      *
  297.      * @return  array  The decoded JSON response
  298.      *
  299.      * @since   13.1
  300.      */
  301.     public function getNetworkUpdates($id null$self true$type null$count 0$start 0$after null$before null,
  302.         $hidden false)
  303.     {
  304.         $token $this->oauth->getToken();
  305.  
  306.         // Set parameters.
  307.         $parameters array(
  308.             'oauth_token' => $token['key']
  309.         );
  310.  
  311.         // Set the API base
  312.         $base '/v1/people/';
  313.  
  314.         // Check if a member id is specified.
  315.         if ($id)
  316.         {
  317.             $base .= $id;
  318.         }
  319.         else
  320.         {
  321.             $base .= '~';
  322.         }
  323.  
  324.         $base .= '/network/updates';
  325.  
  326.         // Set request parameters.
  327.         $data['format''json';
  328.  
  329.         // Check if self is true.
  330.         if ($self)
  331.         {
  332.             $data['scope''self';
  333.         }
  334.  
  335.         // Check if type is specified.
  336.         if ($type)
  337.         {
  338.             $data['type'$type;
  339.         }
  340.  
  341.         // Check if count is specified.
  342.         if ($count 0)
  343.         {
  344.             $data['count'$count;
  345.         }
  346.  
  347.         // Check if start is specified.
  348.         if ($start 0)
  349.         {
  350.             $data['start'$start;
  351.         }
  352.  
  353.         // Check if after is specified.
  354.         if ($after)
  355.         {
  356.             $data['after'$after;
  357.         }
  358.  
  359.         // Check if before is specified.
  360.         if ($before 0)
  361.         {
  362.             $data['before'$before;
  363.         }
  364.  
  365.         // Check if hidden is true.
  366.         if ($hidden)
  367.         {
  368.             $data['hidden'$hidden;
  369.         }
  370.  
  371.         // Build the request path.
  372.         $path $this->getOption('api.url'$base;
  373.  
  374.         // Send the request.
  375.         $response $this->oauth->oauthRequest($path'GET'$parameters$data);
  376.  
  377.         return json_decode($response->body);
  378.     }
  379.  
  380.     /**
  381.      * Method to get information about the current member's network.
  382.      *
  383.      * @return  array  The decoded JSON response
  384.      *
  385.      * @since   13.1
  386.      */
  387.     public function getNetworkStats()
  388.     {
  389.         $token $this->oauth->getToken();
  390.  
  391.         // Set parameters.
  392.         $parameters array(
  393.             'oauth_token' => $token['key']
  394.         );
  395.  
  396.         // Set the API base
  397.         $base '/v1/people/~/network/network-stats';
  398.  
  399.         // Set request parameters.
  400.         $data['format''json';
  401.  
  402.         // Build the request path.
  403.         $path $this->getOption('api.url'$base;
  404.  
  405.         // Send the request.
  406.         $response $this->oauth->oauthRequest($path'GET'$parameters$data);
  407.  
  408.         return json_decode($response->body);
  409.     }
  410.  
  411.     /**
  412.      * Method to get the users network updates.
  413.      *
  414.      * @param   string  $body  The actual content of the update. You can use HTML to include links to the user name and the content the user
  415.      *                          created. Other HTML tags are not supported. All body text should be HTML entity escaped and UTF-8 compliant.
  416.      *
  417.      * @return  array  The decoded JSON response
  418.      *
  419.      * @since   13.1
  420.      */
  421.     public function postNetworkUpdate($body)
  422.     {
  423.         $token $this->oauth->getToken();
  424.  
  425.         // Set parameters.
  426.         $parameters array(
  427.             'oauth_token' => $token['key']
  428.         );
  429.  
  430.         // Set the success response code.
  431.         $this->oauth->setOption('success_code'201);
  432.  
  433.         // Set the API base
  434.         $base '/v1/people/~/person-activities';
  435.  
  436.         // Build the xml.
  437.         $xml '<activity locale="en_US">
  438.                     <content-type>linkedin-html</content-type>
  439.                     <body>' $body '</body>
  440.                 </activity>';
  441.  
  442.         $header['Content-Type''text/xml';
  443.  
  444.         // Build the request path.
  445.         $path $this->getOption('api.url'$base;
  446.  
  447.         // Send the request.
  448.         $response $this->oauth->oauthRequest($path'POST'$parameters$xml$header);
  449.  
  450.         return $response;
  451.     }
  452.  
  453.     /**
  454.      * Method to retrieve all comments for a given network update.
  455.      *
  456.      * @param   string  $key  update/update-key representing an update.
  457.      *
  458.      * @return  array  The decoded JSON response
  459.      *
  460.      * @since   13.1
  461.      */
  462.     public function getComments($key)
  463.     {
  464.         $token $this->oauth->getToken();
  465.  
  466.         // Set parameters.
  467.         $parameters array(
  468.             'oauth_token' => $token['key']
  469.         );
  470.  
  471.         // Set the API base
  472.         $base '/v1/people/~/network/updates/key=' $key '/update-comments';
  473.  
  474.         // Set request parameters.
  475.         $data['format''json';
  476.  
  477.         // Build the request path.
  478.         $path $this->getOption('api.url'$base;
  479.  
  480.         // Send the request.
  481.         $response $this->oauth->oauthRequest($path'GET'$parameters$data);
  482.  
  483.         return json_decode($response->body);
  484.     }
  485.  
  486.     /**
  487.      * Method to post a new comment to an existing update.
  488.      *
  489.      * @param   string  $key      update/update-key representing an update.
  490.      * @param   string  $comment  Maximum length of 700 characters
  491.      *
  492.      * @return  array  The decoded JSON response
  493.      *
  494.      * @since   13.1
  495.      */
  496.     public function postComment($key$comment)
  497.     {
  498.         $token $this->oauth->getToken();
  499.  
  500.         // Set parameters.
  501.         $parameters array(
  502.             'oauth_token' => $token['key']
  503.         );
  504.  
  505.         // Set the success response code.
  506.         $this->oauth->setOption('success_code'201);
  507.  
  508.         // Set the API base
  509.         $base '/v1/people/~/network/updates/key=' $key '/update-comments';
  510.  
  511.         // Build the xml.
  512.         $xml '<update-comment>
  513.                   <comment>' $comment '</comment>
  514.                 </update-comment>';
  515.  
  516.         $header['Content-Type''text/xml';
  517.  
  518.         // Build the request path.
  519.         $path $this->getOption('api.url'$base;
  520.  
  521.         // Send the request.
  522.         $response $this->oauth->oauthRequest($path'POST'$parameters$xml$header);
  523.  
  524.         return $response;
  525.     }
  526.  
  527.     /**
  528.      * Method to retrieve the complete list of people who liked an update.
  529.      *
  530.      * @param   string  $key  update/update-key representing an update.
  531.      *
  532.      * @return  array  The decoded JSON response
  533.      *
  534.      * @since   13.1
  535.      */
  536.     public function getLikes($key)
  537.     {
  538.         $token $this->oauth->getToken();
  539.  
  540.         // Set parameters.
  541.         $parameters array(
  542.             'oauth_token' => $token['key']
  543.         );
  544.  
  545.         // Set the API base
  546.         $base '/v1/people/~/network/updates/key=' $key '/likes';
  547.  
  548.         // Set request parameters.
  549.         $data['format''json';
  550.  
  551.         // Build the request path.
  552.         $path $this->getOption('api.url'$base;
  553.  
  554.         // Send the request.
  555.         $response $this->oauth->oauthRequest($path'GET'$parameters$data);
  556.  
  557.         return json_decode($response->body);
  558.     }
  559.  
  560.     /**
  561.      * Method to like or unlike an update.
  562.      *
  563.      * @param   string   $key   Update/update-key representing an update.
  564.      * @param   boolean  $like  True to like update, false otherwise.
  565.      *
  566.      * @return  array  The decoded JSON response
  567.      *
  568.      * @since   13.1
  569.      */
  570.     private function _likeUnlike($key$like)
  571.     {
  572.         $token $this->oauth->getToken();
  573.  
  574.         // Set parameters.
  575.         $parameters array(
  576.             'oauth_token' => $token['key']
  577.         );
  578.  
  579.         // Set the success response code.
  580.         $this->oauth->setOption('success_code'204);
  581.  
  582.         // Set the API base
  583.         $base '/v1/people/~/network/updates/key=' $key '/is-liked';
  584.  
  585.         // Build xml.
  586.         $xml '<is-liked>' $this->booleanToString($like'</is-liked>';
  587.  
  588.         // Build the request path.
  589.         $path $this->getOption('api.url'$base;
  590.  
  591.         $header['Content-Type''text/xml';
  592.  
  593.         // Send the request.
  594.         $response $this->oauth->oauthRequest($path'PUT'$parameters$xml$header);
  595.  
  596.         return $response;
  597.     }
  598.  
  599.     /**
  600.      * Method used to like an update.
  601.      *
  602.      * @param   string  $key  Update/update-key representing an update.
  603.      *
  604.      * @return  array  The decoded JSON response
  605.      *
  606.      * @since   13.1
  607.      */
  608.     public function like($key)
  609.     {
  610.         return $this->_likeUnlike($keytrue);
  611.     }
  612.  
  613.     /**
  614.      * Method used to unlike an update.
  615.      *
  616.      * @param   string  $key  Update/update-key representing an update.
  617.      *
  618.      * @return  array  The decoded JSON response
  619.      *
  620.      * @since   13.1
  621.      */
  622.     public function unlike($key)
  623.     {
  624.         return $this->_likeUnlike($keyfalse);
  625.     }
  626. }

Documentation generated on Tue, 19 Nov 2013 15:14:30 +0100 by phpDocumentor 1.4.3