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