Source for file groups.php

Documentation is available at groups.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 Groups 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 group.
  22.      *
  23.      * @param   string   $id      The unique identifier for a group.
  24.      * @param   string   $fields  Request fields beyond the default ones.
  25.      * @param   integer  $start   Starting location within the result set for paginated returns.
  26.      * @param   integer  $count   The number of results returned.
  27.      *
  28.      * @return  array  The decoded JSON response
  29.      *
  30.      * @since   13.1
  31.      */
  32.     public function getGroup($id$fields null$start 0$count 5)
  33.     {
  34.         $token $this->oauth->getToken();
  35.  
  36.         // Set parameters.
  37.         $parameters array(
  38.             'oauth_token' => $token['key']
  39.         );
  40.  
  41.         // Set the API base
  42.         $base '/v1/groups/' $id;
  43.  
  44.         $data['format''json';
  45.  
  46.         // Check if fields is specified.
  47.         if ($fields)
  48.         {
  49.             $base .= ':' $fields;
  50.         }
  51.  
  52.         // Check if start is specified.
  53.         if ($start 0)
  54.         {
  55.             $data['start'$start;
  56.         }
  57.  
  58.         // Check if count is specified.
  59.         if ($count != 5)
  60.         {
  61.             $data['count'$count;
  62.         }
  63.  
  64.         // Build the request path.
  65.         $path $this->getOption('api.url'$base;
  66.  
  67.         // Send the request.
  68.         $response $this->oauth->oauthRequest($path'GET'$parameters$data);
  69.  
  70.         return json_decode($response->body);
  71.     }
  72.  
  73.     /**
  74.      * Method to find the groups a member belongs to.
  75.      *
  76.      * @param   string   $id                The unique identifier for a user.
  77.      * @param   string   $fields            Request fields beyond the default ones.
  78.      * @param   integer  $start             Starting location within the result set for paginated returns.
  79.      * @param   integer  $count             The number of results returned.
  80.      * @param   string   $membership_state  The state of the caller’s membership to the specified group.
  81.      *                                          Values are: non-member, awaiting-confirmation, awaiting-parent-group-confirmation, member, moderator, manager, owner.
  82.      *
  83.      * @return  array  The decoded JSON response
  84.      *
  85.      * @since   13.1
  86.      */
  87.     public function getMemberships($id null$fields null$start 0$count 5$membership_state null)
  88.     {
  89.         $token $this->oauth->getToken();
  90.  
  91.         // Set parameters.
  92.         $parameters array(
  93.             'oauth_token' => $token['key']
  94.         );
  95.  
  96.         // Set the API base
  97.         $base '/v1/people/';
  98.  
  99.         // Check if id is specified.
  100.         if ($id)
  101.         {
  102.             $base .= $id '/group-memberships';
  103.         }
  104.         else
  105.         {
  106.             $base .= '~/group-memberships';
  107.         }
  108.  
  109.         $data['format''json';
  110.  
  111.         // Check if fields is specified.
  112.         if ($fields)
  113.         {
  114.             $base .= ':' $fields;
  115.         }
  116.  
  117.         // Check if start is specified.
  118.         if ($start 0)
  119.         {
  120.             $data['start'$start;
  121.         }
  122.  
  123.         // Check if count is specified.
  124.         if ($count != 5)
  125.         {
  126.             $data['count'$count;
  127.         }
  128.  
  129.         // Check if membership_state is specified.
  130.         if ($membership_state)
  131.         {
  132.             $data['membership-state'$membership_state;
  133.         }
  134.  
  135.         // Build the request path.
  136.         $path $this->getOption('api.url'$base;
  137.  
  138.         // Send the request.
  139.         $response $this->oauth->oauthRequest($path'GET'$parameters$data);
  140.  
  141.         return json_decode($response->body);
  142.     }
  143.  
  144.     /**
  145.      * Method to find the groups a member belongs to.
  146.      *
  147.      * @param   string   $person_id  The unique identifier for a user.
  148.      * @param   string   $group_id   The unique identifier for a group.
  149.      * @param   string   $fields     Request fields beyond the default ones.
  150.      * @param   integer  $start      Starting location within the result set for paginated returns.
  151.      * @param   integer  $count      The number of results returned.
  152.      *
  153.      * @return  array  The decoded JSON response
  154.      *
  155.      * @since   13.1
  156.      */
  157.     public function getSettings($person_id null$group_id null$fields null$start 0$count 5)
  158.     {
  159.         $token $this->oauth->getToken();
  160.  
  161.         // Set parameters.
  162.         $parameters array(
  163.             'oauth_token' => $token['key']
  164.         );
  165.  
  166.         // Set the API base
  167.         $base '/v1/people/';
  168.  
  169.         // Check if person_id is specified.
  170.         if ($person_id)
  171.         {
  172.             $base .= $person_id '/group-memberships';
  173.         }
  174.         else
  175.         {
  176.             $base .= '~/group-memberships';
  177.         }
  178.  
  179.         // Check if group_id is specified.
  180.         if ($group_id)
  181.         {
  182.             $base .= '/' $group_id;
  183.         }
  184.  
  185.         $data['format''json';
  186.  
  187.         // Check if fields is specified.
  188.         if ($fields)
  189.         {
  190.             $base .= ':' $fields;
  191.         }
  192.  
  193.         // Check if start is specified.
  194.         if ($start 0)
  195.         {
  196.             $data['start'$start;
  197.         }
  198.  
  199.         // Check if count is specified.
  200.         if ($count != 5)
  201.         {
  202.             $data['count'$count;
  203.         }
  204.  
  205.         // Build the request path.
  206.         $path $this->getOption('api.url'$base;
  207.  
  208.         // Send the request.
  209.         $response $this->oauth->oauthRequest($path'GET'$parameters$data);
  210.  
  211.         return json_decode($response->body);
  212.     }
  213.  
  214.     /**
  215.      * Method to change a groups settings.
  216.      *
  217.      * @param   string   $group_id          The unique identifier for a group.
  218.      * @param   boolean  $show_logo         Show group logo in profile.
  219.      * @param   string   $digest_frequency  E-mail digest frequency.
  220.      * @param   boolean  $announcements     E-mail announcements from managers.
  221.      * @param   boolean  $allow_messages    Allow messages from members.
  222.      * @param   boolean  $new_post          E-mail for every new post.
  223.      *
  224.      * @return  array  The decoded JSON response
  225.      *
  226.      * @since   13.1
  227.      */
  228.     public function changeSettings($group_id$show_logo null$digest_frequency null$announcements null,
  229.         $allow_messages null$new_post null)
  230.     {
  231.         $token $this->oauth->getToken();
  232.  
  233.         // Set parameters.
  234.         $parameters array(
  235.             'oauth_token' => $token['key']
  236.         );
  237.  
  238.         // Set the API base
  239.         $base '/v1/people/~/group-memberships/' $group_id;
  240.  
  241.         // Build xml.
  242.         $xml '<group-membership>';
  243.  
  244.         if (!is_null($show_logo))
  245.         {
  246.             $xml .= '<show-group-logo-in-profile>' $this->booleanToString($show_logo'</show-group-logo-in-profile>';
  247.         }
  248.  
  249.         if ($digest_frequency)
  250.         {
  251.             $xml .= '<email-digest-frequency><code>' $digest_frequency '</code></email-digest-frequency>';
  252.         }
  253.  
  254.         if (!is_null($announcements))
  255.         {
  256.             $xml .= '<email-announcements-from-managers>' $this->booleanToString($announcements'</email-announcements-from-managers>';
  257.         }
  258.  
  259.         if (!is_null($allow_messages))
  260.         {
  261.             $xml .= '<allow-messages-from-members>' $this->booleanToString($allow_messages'</allow-messages-from-members>';
  262.         }
  263.  
  264.         if (!is_null($new_post))
  265.         {
  266.             $xml .= '<email-for-every-new-post>' $this->booleanToString($new_post'</email-for-every-new-post>';
  267.         }
  268.  
  269.         $xml .= '</group-membership>';
  270.  
  271.         // Build the request path.
  272.         $path $this->getOption('api.url'$base;
  273.  
  274.         $header['Content-Type''text/xml';
  275.  
  276.         // Send the request.
  277.         $response $this->oauth->oauthRequest($path'PUT'$parameters$xml$header);
  278.  
  279.         return $response;
  280.     }
  281.  
  282.     /**
  283.      * Method to join a group.
  284.      *
  285.      * @param   string   $group_id          The unique identifier for a group.
  286.      * @param   boolean  $show_logo         Show group logo in profile.
  287.      * @param   string   $digest_frequency  E-mail digest frequency.
  288.      * @param   boolean  $announcements     E-mail announcements from managers.
  289.      * @param   boolean  $allow_messages    Allow messages from members.
  290.      * @param   boolean  $new_post          E-mail for every new post.
  291.      *
  292.      * @return  array  The decoded JSON response
  293.      *
  294.      * @since   13.1
  295.      */
  296.     public function joinGroup($group_id$show_logo null$digest_frequency null$announcements null,
  297.         $allow_messages null$new_post null)
  298.     {
  299.         $token $this->oauth->getToken();
  300.  
  301.         // Set parameters.
  302.         $parameters array(
  303.             'oauth_token' => $token['key']
  304.         );
  305.  
  306.         // Set the success response code.
  307.         $this->oauth->setOption('success_code'201);
  308.  
  309.         // Set the API base
  310.         $base '/v1/people/~/group-memberships';
  311.  
  312.         // Build xml.
  313.         $xml '<group-membership><group><id>' $group_id '</id></group>';
  314.  
  315.         if (!is_null($show_logo))
  316.         {
  317.             $xml .= '<show-group-logo-in-profile>' $this->booleanToString($show_logo'</show-group-logo-in-profile>';
  318.         }
  319.  
  320.         if ($digest_frequency)
  321.         {
  322.             $xml .= '<email-digest-frequency><code>' $digest_frequency '</code></email-digest-frequency>';
  323.         }
  324.  
  325.         if (!is_null($announcements))
  326.         {
  327.             $xml .= '<email-announcements-from-managers>' $this->booleanToString($announcements'</email-announcements-from-managers>';
  328.         }
  329.  
  330.         if (!is_null($allow_messages))
  331.         {
  332.             $xml .= '<allow-messages-from-members>' $this->booleanToString($allow_messages'</allow-messages-from-members>';
  333.         }
  334.  
  335.         if (!is_null($new_post))
  336.         {
  337.             $xml .= '<email-for-every-new-post>' $this->booleanToString($new_post'</email-for-every-new-post>';
  338.         }
  339.  
  340.         $xml .= '<membership-state><code>member</code></membership-state></group-membership>';
  341.  
  342.         // Build the request path.
  343.         $path $this->getOption('api.url'$base;
  344.  
  345.         $header['Content-Type''text/xml';
  346.  
  347.         // Send the request.
  348.         $response $this->oauth->oauthRequest($path'POST'$parameters$xml$header);
  349.  
  350.         return $response;
  351.     }
  352.  
  353.     /**
  354.      * Method to leave a group.
  355.      *
  356.      * @param   string  $group_id  The unique identifier for a group.
  357.      *
  358.      * @return  array  The decoded JSON response
  359.      *
  360.      * @since   13.1
  361.      */
  362.     public function leaveGroup($group_id)
  363.     {
  364.         $token $this->oauth->getToken();
  365.  
  366.         // Set parameters.
  367.         $parameters array(
  368.             'oauth_token' => $token['key']
  369.         );
  370.  
  371.         // Set the success response code.
  372.         $this->oauth->setOption('success_code'204);
  373.  
  374.         // Set the API base
  375.         $base '/v1/people/~/group-memberships/' $group_id;
  376.  
  377.         // Build the request path.
  378.         $path $this->getOption('api.url'$base;
  379.  
  380.         // Send the request.
  381.         $response $this->oauth->oauthRequest($path'DELETE'$parameters);
  382.  
  383.         return $response;
  384.     }
  385.  
  386.     /**
  387.      * Method to get dicussions for a group.
  388.      *
  389.      * @param   string   $id              The unique identifier for a group.
  390.      * @param   string   $fields          Request fields beyond the default ones.
  391.      * @param   integer  $start           Starting location within the result set for paginated returns.
  392.      * @param   integer  $count           The number of results returned.
  393.      * @param   string   $order           Sort order for posts. Valid for: recency, popularity.
  394.      * @param   string   $category        Category of posts. Valid for: discussion
  395.      * @param   string   $modified_since  Timestamp filter for posts created after the specified value.
  396.      *
  397.      * @return  array  The decoded JSON response
  398.      *
  399.      * @since   13.1
  400.      */
  401.     public function getDiscussions($id$fields null$start 0$count 0$order null$category 'discussion'$modified_since null)
  402.     {
  403.         $token $this->oauth->getToken();
  404.  
  405.         // Set parameters.
  406.         $parameters array(
  407.             'oauth_token' => $token['key']
  408.         );
  409.  
  410.         // Set the API base
  411.         $base '/v1/groups/' $id '/posts';
  412.  
  413.         $data['format''json';
  414.  
  415.         // Check if fields is specified.
  416.         if ($fields)
  417.         {
  418.             $base .= ':' $fields;
  419.         }
  420.  
  421.         // Check if start is specified.
  422.         if ($start 0)
  423.         {
  424.             $data['start'$start;
  425.         }
  426.  
  427.         // Check if count is specified.
  428.         if ($count 0)
  429.         {
  430.             $data['count'$count;
  431.         }
  432.  
  433.         // Check if order is specified.
  434.         if ($order)
  435.         {
  436.             $data['order'$order;
  437.         }
  438.  
  439.         // Check if category is specified.
  440.         if ($category)
  441.         {
  442.             $data['category'$category;
  443.         }
  444.  
  445.         // Check if modified_since is specified.
  446.         if ($modified_since)
  447.         {
  448.             $data['modified-since'$modified_since;
  449.         }
  450.  
  451.         // Build the request path.
  452.         $path $this->getOption('api.url'$base;
  453.  
  454.         // Send the request.
  455.         $response $this->oauth->oauthRequest($path'GET'$parameters$data);
  456.  
  457.         return json_decode($response->body);
  458.     }
  459.  
  460.     /**
  461.      * Method to get posts a user started / participated in / follows for a group.
  462.      *
  463.      * @param   string   $group_id        The unique identifier for a group.
  464.      * @param   string   $role            Filter for posts related to the caller. Valid for: creator, commenter, follower.
  465.      * @param   string   $person_id       The unique identifier for a user.
  466.      * @param   string   $fields          Request fields beyond the default ones.
  467.      * @param   integer  $start           Starting location within the result set for paginated returns.
  468.      * @param   integer  $count           The number of results returned.
  469.      * @param   string   $order           Sort order for posts. Valid for: recency, popularity.
  470.      * @param   string   $category        Category of posts. Valid for: discussion
  471.      * @param   string   $modified_since  Timestamp filter for posts created after the specified value.
  472.      *
  473.      * @return  array  The decoded JSON response
  474.      *
  475.      * @since   13.1
  476.      */
  477.     public function getUserPosts($group_id$role$person_id null$fields null$start 0$count 0,
  478.         $order null$category 'discussion'$modified_since null)
  479.     {
  480.         $token $this->oauth->getToken();
  481.  
  482.         // Set parameters.
  483.         $parameters array(
  484.             'oauth_token' => $token['key']
  485.         );
  486.  
  487.         // Set the API base
  488.         $base '/v1/people/';
  489.  
  490.         // Check if person_id is specified.
  491.         if ($person_id)
  492.         {
  493.             $base .= $person_id;
  494.         }
  495.         else
  496.         {
  497.             $base .= '~';
  498.         }
  499.  
  500.         $base .= '/group-memberships/' $group_id '/posts';
  501.  
  502.         $data['format''json';
  503.         $data['role'$role;
  504.  
  505.         // Check if fields is specified.
  506.         if ($fields)
  507.         {
  508.             $base .= ':' $fields;
  509.         }
  510.  
  511.         // Check if start is specified.
  512.         if ($start 0)
  513.         {
  514.             $data['start'$start;
  515.         }
  516.  
  517.         // Check if count is specified.
  518.         if ($count 0)
  519.         {
  520.             $data['count'$count;
  521.         }
  522.  
  523.         // Check if order is specified.
  524.         if ($order)
  525.         {
  526.             $data['order'$order;
  527.         }
  528.  
  529.         // Check if category is specified.
  530.         if ($category)
  531.         {
  532.             $data['category'$category;
  533.         }
  534.  
  535.         // Check if modified_since is specified.
  536.         if ($modified_since)
  537.         {
  538.             $data['modified-since'$modified_since;
  539.         }
  540.  
  541.         // Build the request path.
  542.         $path $this->getOption('api.url'$base;
  543.  
  544.         // Send the request.
  545.         $response $this->oauth->oauthRequest($path'GET'$parameters$data);
  546.  
  547.         return json_decode($response->body);
  548.     }
  549.  
  550.     /**
  551.      * Method to retrieve details about a post.
  552.      *
  553.      * @param   string  $post_id  The unique identifier for a post.
  554.      * @param   string  $fields   Request fields beyond the default ones.
  555.      *
  556.      * @return  array  The decoded JSON response
  557.      *
  558.      * @since   13.1
  559.      */
  560.     public function getPost($post_id$fields null)
  561.     {
  562.         $token $this->oauth->getToken();
  563.  
  564.         // Set parameters.
  565.         $parameters array(
  566.             'oauth_token' => $token['key']
  567.         );
  568.  
  569.         // Set the API base
  570.         $base '/v1/posts/' $post_id;
  571.  
  572.         $data['format''json';
  573.  
  574.         // Check if fields is specified.
  575.         if ($fields)
  576.         {
  577.             $base .= ':' $fields;
  578.         }
  579.  
  580.         // Build the request path.
  581.         $path $this->getOption('api.url'$base;
  582.  
  583.         // Send the request.
  584.         $response $this->oauth->oauthRequest($path'GET'$parameters$data);
  585.  
  586.         return json_decode($response->body);
  587.     }
  588.  
  589.     /**
  590.      * Method to retrieve all comments of a post.
  591.      *
  592.      * @param   string   $post_id  The unique identifier for a post.
  593.      * @param   string   $fields   Request fields beyond the default ones.
  594.      * @param   integer  $start    Starting location within the result set for paginated returns.
  595.      * @param   integer  $count    The number of results returned.
  596.      *
  597.      * @return  array  The decoded JSON response
  598.      *
  599.      * @since   13.1
  600.      */
  601.     public function getPostComments($post_id$fields null$start 0$count 0)
  602.     {
  603.         $token $this->oauth->getToken();
  604.  
  605.         // Set parameters.
  606.         $parameters array(
  607.             'oauth_token' => $token['key']
  608.         );
  609.  
  610.         // Set the API base
  611.         $base '/v1/posts/' $post_id '/comments';
  612.  
  613.         $data['format''json';
  614.  
  615.         // Check if fields is specified.
  616.         if ($fields)
  617.         {
  618.             $base .= ':' $fields;
  619.         }
  620.  
  621.         // Check if start is specified.
  622.         if ($start 0)
  623.         {
  624.             $data['start'$start;
  625.         }
  626.  
  627.         // Check if count is specified.
  628.         if ($count 0)
  629.         {
  630.             $data['count'$count;
  631.         }
  632.  
  633.         // Build the request path.
  634.         $path $this->getOption('api.url'$base;
  635.  
  636.         // Send the request.
  637.         $response $this->oauth->oauthRequest($path'GET'$parameters$data);
  638.  
  639.         return json_decode($response->body);
  640.     }
  641.  
  642.     /**
  643.      * Method to retrieve all comments of a post.
  644.      *
  645.      * @param   string  $group_id  The unique identifier for a group.
  646.      * @param   string  $title     Post title.
  647.      * @param   string  $summary   Post summary.
  648.      *
  649.      * @return  string  The created post's id.
  650.      *
  651.      * @since   13.1
  652.      */
  653.     public function createPost($group_id$title$summary)
  654.     {
  655.         $token $this->oauth->getToken();
  656.  
  657.         // Set parameters.
  658.         $parameters array(
  659.             'oauth_token' => $token['key']
  660.         );
  661.  
  662.         // Set the success response code.
  663.         $this->oauth->setOption('success_code'201);
  664.  
  665.         // Set the API base
  666.         $base '/v1/groups/' $group_id '/posts';
  667.  
  668.         // Build xml.
  669.         $xml '<post><title>' $title '</title><summary>' $summary '</summary></post>';
  670.  
  671.         // Build the request path.
  672.         $path $this->getOption('api.url'$base;
  673.  
  674.         $header['Content-Type''text/xml';
  675.  
  676.         // Send the request.
  677.         $response $this->oauth->oauthRequest($path'POST'$parameters$xml$header);
  678.  
  679.         // Return the post id.
  680.         $response explode('posts/'$response->headers['Location']);
  681.  
  682.         return $response[1];
  683.     }
  684.  
  685.     /**
  686.      * Method to like or unlike a post.
  687.      *
  688.      * @param   string   $post_id  The unique identifier for a group.
  689.      * @param   boolean  $like     True to like post, false otherwise.
  690.      *
  691.      * @return  array  The decoded JSON response
  692.      *
  693.      * @since   13.1
  694.      */
  695.     private function _likeUnlike($post_id$like)
  696.     {
  697.         $token $this->oauth->getToken();
  698.  
  699.         // Set parameters.
  700.         $parameters array(
  701.             'oauth_token' => $token['key']
  702.         );
  703.  
  704.         // Set the success response code.
  705.         $this->oauth->setOption('success_code'204);
  706.  
  707.         // Set the API base
  708.         $base '/v1/posts/' $post_id '/relation-to-viewer/is-liked';
  709.  
  710.         // Build xml.
  711.         $xml '<is-liked>' $this->booleanToString($like'</is-liked>';
  712.  
  713.         // Build the request path.
  714.         $path $this->getOption('api.url'$base;
  715.  
  716.         $header['Content-Type''text/xml';
  717.  
  718.         // Send the request.
  719.         $response $this->oauth->oauthRequest($path'PUT'$parameters$xml$header);
  720.  
  721.         return $response;
  722.     }
  723.  
  724.     /**
  725.      * Method used to like a post.
  726.      *
  727.      * @param   string  $post_id  The unique identifier for a group.
  728.      *
  729.      * @return  array  The decoded JSON response
  730.      *
  731.      * @since   13.1
  732.      */
  733.     public function likePost($post_id)
  734.     {
  735.         return $this->_likeUnlike($post_idtrue);
  736.     }
  737.  
  738.     /**
  739.      * Method used to unlike a post.
  740.      *
  741.      * @param   string  $post_id  The unique identifier for a group.
  742.      *
  743.      * @return  array  The decoded JSON response
  744.      *
  745.      * @since   13.1
  746.      */
  747.     public function unlikePost($post_id)
  748.     {
  749.         return $this->_likeUnlike($post_idfalse);
  750.     }
  751.  
  752.     /**
  753.      * Method to follow or unfollow a post.
  754.      *
  755.      * @param   string   $post_id  The unique identifier for a group.
  756.      * @param   boolean  $follow   True to like post, false otherwise.
  757.      *
  758.      * @return  array  The decoded JSON response
  759.      *
  760.      * @since   13.1
  761.      */
  762.     private function _followUnfollow($post_id$follow)
  763.     {
  764.         $token $this->oauth->getToken();
  765.  
  766.         // Set parameters.
  767.         $parameters array(
  768.             'oauth_token' => $token['key']
  769.         );
  770.  
  771.         // Set the success response code.
  772.         $this->oauth->setOption('success_code'204);
  773.  
  774.         // Set the API base
  775.         $base '/v1/posts/' $post_id '/relation-to-viewer/is-following';
  776.  
  777.         // Build xml.
  778.         $xml '<is-following>' $this->booleanToString($follow'</is-following>';
  779.  
  780.         // Build the request path.
  781.         $path $this->getOption('api.url'$base;
  782.  
  783.         $header['Content-Type''text/xml';
  784.  
  785.         // Send the request.
  786.         $response $this->oauth->oauthRequest($path'PUT'$parameters$xml$header);
  787.  
  788.         return $response;
  789.     }
  790.  
  791.     /**
  792.      * Method used to follow a post.
  793.      *
  794.      * @param   string  $post_id  The unique identifier for a group.
  795.      *
  796.      * @return  array  The decoded JSON response
  797.      *
  798.      * @since   13.1
  799.      */
  800.     public function followPost($post_id)
  801.     {
  802.         return $this->_followUnfollow($post_idtrue);
  803.     }
  804.  
  805.     /**
  806.      * Method used to unfollow a post.
  807.      *
  808.      * @param   string  $post_id  The unique identifier for a group.
  809.      *
  810.      * @return  array  The decoded JSON response
  811.      *
  812.      * @since   13.1
  813.      */
  814.     public function unfollowPost($post_id)
  815.     {
  816.         return $this->_followUnfollow($post_idfalse);
  817.     }
  818.  
  819.     /**
  820.      * Method to flag a post as a Promotion or Job.
  821.      *
  822.      * @param   string  $post_id  The unique identifier for a group.
  823.      * @param   string  $flag     Flag as a 'promotion' or 'job'.
  824.      *
  825.      * @return  array  The decoded JSON response
  826.      *
  827.      * @since   13.1
  828.      */
  829.     public function flagPost($post_id$flag)
  830.     {
  831.         $token $this->oauth->getToken();
  832.  
  833.         // Set parameters.
  834.         $parameters array(
  835.             'oauth_token' => $token['key']
  836.         );
  837.  
  838.         // Set the success response code.
  839.         $this->oauth->setOption('success_code'204);
  840.  
  841.         // Set the API base
  842.         $base '/v1/posts/' $post_id '/category/code';
  843.  
  844.         // Build xml.
  845.         $xml '<code>' $flag '</code>';
  846.  
  847.         // Build the request path.
  848.         $path $this->getOption('api.url'$base;
  849.  
  850.         $header['Content-Type''text/xml';
  851.  
  852.         // Send the request.
  853.         $response $this->oauth->oauthRequest($path'PUT'$parameters$xml$header);
  854.  
  855.         return $response;
  856.     }
  857.  
  858.     /**
  859.      * Method to delete a post if the current user is the creator or flag it as inappropriate otherwise.
  860.      *
  861.      * @param   string  $post_id  The unique identifier for a group.
  862.      *
  863.      * @return  array  The decoded JSON response
  864.      *
  865.      * @since   13.1
  866.      */
  867.     public function deletePost($post_id)
  868.     {
  869.         $token $this->oauth->getToken();
  870.  
  871.         // Set parameters.
  872.         $parameters array(
  873.             'oauth_token' => $token['key']
  874.         );
  875.  
  876.         // Set the success response code.
  877.         $this->oauth->setOption('success_code'204);
  878.  
  879.         // Set the API base
  880.         $base '/v1/posts/' $post_id;
  881.  
  882.         // Build the request path.
  883.         $path $this->getOption('api.url'$base;
  884.  
  885.         // Send the request.
  886.         $response $this->oauth->oauthRequest($path'DELETE'$parameters);
  887.  
  888.         return $response;
  889.     }
  890.  
  891.     /**
  892.      * Method to access the comments resource.
  893.      *
  894.      * @param   string  $comment_id  The unique identifier for a comment.
  895.      * @param   string  $fields      Request fields beyond the default ones.
  896.      *
  897.      * @return  array  The decoded JSON response
  898.      *
  899.      * @since   13.1
  900.      */
  901.     public function getComment($comment_id$fields null)
  902.     {
  903.         $token $this->oauth->getToken();
  904.  
  905.         // Set parameters.
  906.         $parameters array(
  907.             'oauth_token' => $token['key']
  908.         );
  909.  
  910.         // Set the API base
  911.         $base '/v1/comments/' $comment_id;
  912.  
  913.         $data['format''json';
  914.  
  915.         // Check if fields is specified.
  916.         if ($fields)
  917.         {
  918.             $base .= ':' $fields;
  919.         }
  920.  
  921.         // Build the request path.
  922.         $path $this->getOption('api.url'$base;
  923.  
  924.         // Send the request.
  925.         $response $this->oauth->oauthRequest($path'GET'$parameters$data);
  926.  
  927.         return json_decode($response->body);
  928.     }
  929.  
  930.     /**
  931.      * Method to add a comment to a post
  932.      *
  933.      * @param   string  $post_id  The unique identifier for a group.
  934.      * @param   string  $comment  The post comment's text.
  935.      *
  936.      * @return  string   The created comment's id.
  937.      *
  938.      * @since   13.1
  939.      */
  940.     public function addComment($post_id$comment)
  941.     {
  942.         $token $this->oauth->getToken();
  943.  
  944.         // Set parameters.
  945.         $parameters array(
  946.             'oauth_token' => $token['key']
  947.         );
  948.  
  949.         // Set the success response code.
  950.         $this->oauth->setOption('success_code'201);
  951.  
  952.         // Set the API base
  953.         $base '/v1/posts/' $post_id '/comments';
  954.  
  955.         // Build xml.
  956.         $xml '<comment><text>' $comment '</text></comment>';
  957.  
  958.         // Build the request path.
  959.         $path $this->getOption('api.url'$base;
  960.  
  961.         $header['Content-Type''text/xml';
  962.  
  963.         // Send the request.
  964.         $response $this->oauth->oauthRequest($path'POST'$parameters$xml$header);
  965.  
  966.         // Return the comment id.
  967.         $response explode('comments/'$response->headers['Location']);
  968.  
  969.         return $response[1];
  970.     }
  971.  
  972.     /**
  973.      * Method to delete a comment if the current user is the creator or flag it as inappropriate otherwise.
  974.      *
  975.      * @param   string  $comment_id  The unique identifier for a group.
  976.      *
  977.      * @return  array  The decoded JSON response
  978.      *
  979.      * @since   13.1
  980.      */
  981.     public function deleteComment($comment_id)
  982.     {
  983.         $token $this->oauth->getToken();
  984.  
  985.         // Set parameters.
  986.         $parameters array(
  987.             'oauth_token' => $token['key']
  988.         );
  989.  
  990.         // Set the success response code.
  991.         $this->oauth->setOption('success_code'204);
  992.  
  993.         // Set the API base
  994.         $base '/v1/comments/' $comment_id;
  995.  
  996.         // Build the request path.
  997.         $path $this->getOption('api.url'$base;
  998.  
  999.         // Send the request.
  1000.         $response $this->oauth->oauthRequest($path'DELETE'$parameters);
  1001.  
  1002.         return $response;
  1003.     }
  1004.  
  1005.     /**
  1006.      * Method to get suggested groups for a user.
  1007.      *
  1008.      * @param   string  $person_id  The unique identifier for a user.
  1009.      * @param   string  $fields     Request fields beyond the default ones.
  1010.      *
  1011.      * @return  array  The decoded JSON response
  1012.      *
  1013.      * @since   13.1
  1014.      */
  1015.     public function getSuggested($person_id null$fields null)
  1016.     {
  1017.         $token $this->oauth->getToken();
  1018.  
  1019.         // Set parameters.
  1020.         $parameters array(
  1021.             'oauth_token' => $token['key']
  1022.         );
  1023.  
  1024.         // Set the API base
  1025.         $base '/v1/people/';
  1026.  
  1027.         // Check if person_id is specified.
  1028.         if ($person_id)
  1029.         {
  1030.             $base .= $person_id '/suggestions/groups';
  1031.         }
  1032.         else
  1033.         {
  1034.             $base .= '~/suggestions/groups';
  1035.         }
  1036.  
  1037.         $data['format''json';
  1038.  
  1039.         // Check if fields is specified.
  1040.         if ($fields)
  1041.         {
  1042.             $base .= ':' $fields;
  1043.         }
  1044.  
  1045.         // Build the request path.
  1046.         $path $this->getOption('api.url'$base;
  1047.  
  1048.         // Send the request.
  1049.         $response $this->oauth->oauthRequest($path'GET'$parameters$data);
  1050.  
  1051.         return json_decode($response->body);
  1052.     }
  1053.  
  1054.     /**
  1055.      * Method to delete a group suggestion for a user.
  1056.      *
  1057.      * @param   string  $suggestion_id  The unique identifier for a suggestion.
  1058.      * @param   string  $person_id      The unique identifier for a user.
  1059.      *
  1060.      * @return  array  The decoded JSON response
  1061.      *
  1062.      * @since   13.1
  1063.      */
  1064.     public function deleteSuggestion($suggestion_id$person_id null)
  1065.     {
  1066.         $token $this->oauth->getToken();
  1067.  
  1068.         // Set parameters.
  1069.         $parameters array(
  1070.             'oauth_token' => $token['key']
  1071.         );
  1072.  
  1073.         // Set the success response code.
  1074.         $this->oauth->setOption('success_code'204);
  1075.  
  1076.         // Set the API base
  1077.         $base '/v1/people/';
  1078.  
  1079.         // Check if person_id is specified.
  1080.         if ($person_id)
  1081.         {
  1082.             $base .= $person_id '/suggestions/groups/' $suggestion_id;
  1083.         }
  1084.         else
  1085.         {
  1086.             $base .= '~/suggestions/groups/' $suggestion_id;
  1087.         }
  1088.  
  1089.         // Build the request path.
  1090.         $path $this->getOption('api.url'$base;
  1091.  
  1092.         // Send the request.
  1093.         $response $this->oauth->oauthRequest($path'DELETE'$parameters);
  1094.  
  1095.         return $response;
  1096.     }
  1097. }

Documentation generated on Tue, 19 Nov 2013 15:04:09 +0100 by phpDocumentor 1.4.3