10 defined(
'JPATH_PLATFORM') or die();
33 public function getGroup($id, $fields = null, $start = 0, $count = 5)
35 $token = $this->oauth->getToken();
39 'oauth_token' => $token[
'key']
43 $base =
'/v1/groups/' . $id;
45 $data[
'format'] =
'json';
50 $base .=
':' . $fields;
56 $data[
'start'] = $start;
62 $data[
'count'] = $count;
66 $path = $this->getOption(
'api.url') . $base;
69 $response = $this->oauth->oauthRequest($path,
'GET', $parameters, $data);
71 return json_decode($response->body);
88 public function getMemberships($id = null, $fields = null, $start = 0, $count = 5, $membership_state = null)
90 $token = $this->oauth->getToken();
94 'oauth_token' => $token[
'key']
98 $base =
'/v1/people/';
103 $base .= $id .
'/group-memberships';
107 $base .=
'~/group-memberships';
110 $data[
'format'] =
'json';
115 $base .=
':' . $fields;
121 $data[
'start'] = $start;
127 $data[
'count'] = $count;
131 if ($membership_state)
133 $data[
'membership-state'] = $membership_state;
137 $path = $this->getOption(
'api.url') . $base;
140 $response = $this->oauth->oauthRequest($path,
'GET', $parameters, $data);
142 return json_decode($response->body);
158 public function getSettings($person_id = null, $group_id = null, $fields = null, $start = 0, $count = 5)
160 $token = $this->oauth->getToken();
164 'oauth_token' => $token[
'key']
168 $base =
'/v1/people/';
173 $base .= $person_id .
'/group-memberships';
177 $base .=
'~/group-memberships';
183 $base .=
'/' . $group_id;
186 $data[
'format'] =
'json';
191 $base .=
':' . $fields;
197 $data[
'start'] = $start;
203 $data[
'count'] = $count;
207 $path = $this->getOption(
'api.url') . $base;
210 $response = $this->oauth->oauthRequest($path,
'GET', $parameters, $data);
212 return json_decode($response->body);
229 public function changeSettings($group_id, $show_logo = null, $digest_frequency = null, $announcements = null,
230 $allow_messages = null, $new_post = null)
232 $token = $this->oauth->getToken();
236 'oauth_token' => $token[
'key']
240 $base =
'/v1/people/~/group-memberships/' . $group_id;
243 $xml =
'<group-membership>';
245 if (!is_null($show_logo))
247 $xml .=
'<show-group-logo-in-profile>' . $this->booleanToString($show_logo) .
'</show-group-logo-in-profile>';
250 if ($digest_frequency)
252 $xml .=
'<email-digest-frequency><code>' . $digest_frequency .
'</code></email-digest-frequency>';
255 if (!is_null($announcements))
257 $xml .=
'<email-announcements-from-managers>' . $this->booleanToString($announcements) .
'</email-announcements-from-managers>';
260 if (!is_null($allow_messages))
262 $xml .=
'<allow-messages-from-members>' . $this->booleanToString($allow_messages) .
'</allow-messages-from-members>';
265 if (!is_null($new_post))
267 $xml .=
'<email-for-every-new-post>' . $this->booleanToString($new_post) .
'</email-for-every-new-post>';
270 $xml .=
'</group-membership>';
273 $path = $this->getOption(
'api.url') . $base;
275 $header[
'Content-Type'] =
'text/xml';
278 $response = $this->oauth->oauthRequest($path,
'PUT', $parameters, $xml, $header);
297 public function joinGroup($group_id, $show_logo = null, $digest_frequency = null, $announcements = null,
298 $allow_messages = null, $new_post = null)
300 $token = $this->oauth->getToken();
304 'oauth_token' => $token[
'key']
308 $this->oauth->setOption(
'success_code', 201);
311 $base =
'/v1/people/~/group-memberships';
314 $xml =
'<group-membership><group><id>' . $group_id .
'</id></group>';
316 if (!is_null($show_logo))
318 $xml .=
'<show-group-logo-in-profile>' . $this->booleanToString($show_logo) .
'</show-group-logo-in-profile>';
321 if ($digest_frequency)
323 $xml .=
'<email-digest-frequency><code>' . $digest_frequency .
'</code></email-digest-frequency>';
326 if (!is_null($announcements))
328 $xml .=
'<email-announcements-from-managers>' . $this->booleanToString($announcements) .
'</email-announcements-from-managers>';
331 if (!is_null($allow_messages))
333 $xml .=
'<allow-messages-from-members>' . $this->booleanToString($allow_messages) .
'</allow-messages-from-members>';
336 if (!is_null($new_post))
338 $xml .=
'<email-for-every-new-post>' . $this->booleanToString($new_post) .
'</email-for-every-new-post>';
341 $xml .=
'<membership-state><code>member</code></membership-state></group-membership>';
344 $path = $this->getOption(
'api.url') . $base;
346 $header[
'Content-Type'] =
'text/xml';
349 $response = $this->oauth->oauthRequest($path,
'POST', $parameters, $xml, $header);
363 public function leaveGroup($group_id)
365 $token = $this->oauth->getToken();
369 'oauth_token' => $token[
'key']
373 $this->oauth->setOption(
'success_code', 204);
376 $base =
'/v1/people/~/group-memberships/' . $group_id;
379 $path = $this->getOption(
'api.url') . $base;
382 $response = $this->oauth->oauthRequest($path,
'DELETE', $parameters);
402 public function getDiscussions($id, $fields = null, $start = 0, $count = 0, $order = null, $category =
'discussion', $modified_since = null)
404 $token = $this->oauth->getToken();
408 'oauth_token' => $token[
'key']
412 $base =
'/v1/groups/' . $id .
'/posts';
414 $data[
'format'] =
'json';
419 $base .=
':' . $fields;
425 $data[
'start'] = $start;
431 $data[
'count'] = $count;
437 $data[
'order'] = $order;
443 $data[
'category'] = $category;
449 $data[
'modified-since'] = $modified_since;
453 $path = $this->getOption(
'api.url') . $base;
456 $response = $this->oauth->oauthRequest($path,
'GET', $parameters, $data);
458 return json_decode($response->body);
478 public function getUserPosts($group_id, $role, $person_id = null, $fields = null, $start = 0, $count = 0,
479 $order = null, $category =
'discussion', $modified_since = null)
481 $token = $this->oauth->getToken();
485 'oauth_token' => $token[
'key']
489 $base =
'/v1/people/';
501 $base .=
'/group-memberships/' . $group_id .
'/posts';
503 $data[
'format'] =
'json';
504 $data[
'role'] = $role;
509 $base .=
':' . $fields;
515 $data[
'start'] = $start;
521 $data[
'count'] = $count;
527 $data[
'order'] = $order;
533 $data[
'category'] = $category;
539 $data[
'modified-since'] = $modified_since;
543 $path = $this->getOption(
'api.url') . $base;
546 $response = $this->oauth->oauthRequest($path,
'GET', $parameters, $data);
548 return json_decode($response->body);
561 public function getPost($post_id, $fields = null)
563 $token = $this->oauth->getToken();
567 'oauth_token' => $token[
'key']
571 $base =
'/v1/posts/' . $post_id;
573 $data[
'format'] =
'json';
578 $base .=
':' . $fields;
582 $path = $this->getOption(
'api.url') . $base;
585 $response = $this->oauth->oauthRequest($path,
'GET', $parameters, $data);
587 return json_decode($response->body);
602 public function getPostComments($post_id, $fields = null, $start = 0, $count = 0)
604 $token = $this->oauth->getToken();
608 'oauth_token' => $token[
'key']
612 $base =
'/v1/posts/' . $post_id .
'/comments';
614 $data[
'format'] =
'json';
619 $base .=
':' . $fields;
625 $data[
'start'] = $start;
631 $data[
'count'] = $count;
635 $path = $this->getOption(
'api.url') . $base;
638 $response = $this->oauth->oauthRequest($path,
'GET', $parameters, $data);
640 return json_decode($response->body);
654 public function createPost($group_id, $title, $summary)
656 $token = $this->oauth->getToken();
660 'oauth_token' => $token[
'key']
664 $this->oauth->setOption(
'success_code', 201);
667 $base =
'/v1/groups/' . $group_id .
'/posts';
670 $xml =
'<post><title>' . $title .
'</title><summary>' . $summary .
'</summary></post>';
673 $path = $this->getOption(
'api.url') . $base;
675 $header[
'Content-Type'] =
'text/xml';
678 $response = $this->oauth->oauthRequest($path,
'POST', $parameters, $xml, $header);
681 $response = explode(
'posts/', $response->headers[
'Location']);
696 private function _likeUnlike($post_id, $like)
698 $token = $this->oauth->getToken();
702 'oauth_token' => $token[
'key']
706 $this->oauth->setOption(
'success_code', 204);
709 $base =
'/v1/posts/' . $post_id .
'/relation-to-viewer/is-liked';
712 $xml =
'<is-liked>' . $this->booleanToString($like) .
'</is-liked>';
715 $path = $this->getOption(
'api.url') . $base;
717 $header[
'Content-Type'] =
'text/xml';
720 $response = $this->oauth->oauthRequest($path,
'PUT', $parameters, $xml, $header);
734 public function likePost($post_id)
736 return $this->_likeUnlike($post_id,
true);
748 public function unlikePost($post_id)
750 return $this->_likeUnlike($post_id,
false);
763 private function _followUnfollow($post_id, $follow)
765 $token = $this->oauth->getToken();
769 'oauth_token' => $token[
'key']
773 $this->oauth->setOption(
'success_code', 204);
776 $base =
'/v1/posts/' . $post_id .
'/relation-to-viewer/is-following';
779 $xml =
'<is-following>' . $this->booleanToString($follow) .
'</is-following>';
782 $path = $this->getOption(
'api.url') . $base;
784 $header[
'Content-Type'] =
'text/xml';
787 $response = $this->oauth->oauthRequest($path,
'PUT', $parameters, $xml, $header);
801 public function followPost($post_id)
803 return $this->_followUnfollow($post_id,
true);
815 public function unfollowPost($post_id)
817 return $this->_followUnfollow($post_id,
false);
830 public function flagPost($post_id, $flag)
832 $token = $this->oauth->getToken();
836 'oauth_token' => $token[
'key']
840 $this->oauth->setOption(
'success_code', 204);
843 $base =
'/v1/posts/' . $post_id .
'/category/code';
846 $xml =
'<code>' . $flag .
'</code>';
849 $path = $this->getOption(
'api.url') . $base;
851 $header[
'Content-Type'] =
'text/xml';
854 $response = $this->oauth->oauthRequest($path,
'PUT', $parameters, $xml, $header);
868 public function deletePost($post_id)
870 $token = $this->oauth->getToken();
874 'oauth_token' => $token[
'key']
878 $this->oauth->setOption(
'success_code', 204);
881 $base =
'/v1/posts/' . $post_id;
884 $path = $this->getOption(
'api.url') . $base;
887 $response = $this->oauth->oauthRequest($path,
'DELETE', $parameters);
902 public function getComment($comment_id, $fields = null)
904 $token = $this->oauth->getToken();
908 'oauth_token' => $token[
'key']
912 $base =
'/v1/comments/' . $comment_id;
914 $data[
'format'] =
'json';
919 $base .=
':' . $fields;
923 $path = $this->getOption(
'api.url') . $base;
926 $response = $this->oauth->oauthRequest($path,
'GET', $parameters, $data);
928 return json_decode($response->body);
941 public function addComment($post_id, $comment)
943 $token = $this->oauth->getToken();
947 'oauth_token' => $token[
'key']
951 $this->oauth->setOption(
'success_code', 201);
954 $base =
'/v1/posts/' . $post_id .
'/comments';
957 $xml =
'<comment><text>' . $comment .
'</text></comment>';
960 $path = $this->getOption(
'api.url') . $base;
962 $header[
'Content-Type'] =
'text/xml';
965 $response = $this->oauth->oauthRequest($path,
'POST', $parameters, $xml, $header);
968 $response = explode(
'comments/', $response->headers[
'Location']);
982 public function deleteComment($comment_id)
984 $token = $this->oauth->getToken();
988 'oauth_token' => $token[
'key']
992 $this->oauth->setOption(
'success_code', 204);
995 $base =
'/v1/comments/' . $comment_id;
998 $path = $this->getOption(
'api.url') . $base;
1001 $response = $this->oauth->oauthRequest($path,
'DELETE', $parameters);
1016 public function getSuggested($person_id = null, $fields = null)
1018 $token = $this->oauth->getToken();
1021 $parameters = array(
1022 'oauth_token' => $token[
'key']
1026 $base =
'/v1/people/';
1031 $base .= $person_id .
'/suggestions/groups';
1035 $base .=
'~/suggestions/groups';
1038 $data[
'format'] =
'json';
1043 $base .=
':' . $fields;
1047 $path = $this->getOption(
'api.url') . $base;
1050 $response = $this->oauth->oauthRequest($path,
'GET', $parameters, $data);
1052 return json_decode($response->body);
1065 public function deleteSuggestion($suggestion_id, $person_id = null)
1067 $token = $this->oauth->getToken();
1070 $parameters = array(
1071 'oauth_token' => $token[
'key']
1075 $this->oauth->setOption(
'success_code', 204);
1078 $base =
'/v1/people/';
1083 $base .= $person_id .
'/suggestions/groups/' . $suggestion_id;
1087 $base .=
'~/suggestions/groups/' . $suggestion_id;
1091 $path = $this->getOption(
'api.url') . $base;
1094 $response = $this->oauth->oauthRequest($path,
'DELETE', $parameters);