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