Skip to content

Commit

Permalink
Updates README.md, adds funtion Client::getGroupMembers(), minor chan…
Browse files Browse the repository at this point in the history
…ges in requesting group details
  • Loading branch information
rgaida committed Oct 7, 2015
1 parent 5bc3a42 commit 4babedb
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 29 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ public function unlikeDirectMessage($other_user_id, $message_id)

##### Group methods
```php
public function getAllGroups($page=1, $per_page=10)
public function getAllGroups()
public function getGroups($page = 1, $per_page = 10)
public function getGroupByName($name)
public function getGroupById($group_id)
public function getFormerGroups()
public function createGroup($name, $description='', $image_url='', $share=false)
public function getGroupDetails($group_id)
Expand All @@ -52,12 +55,16 @@ public function getMyLikes($group_id)
public function getMyHits($group_id)
public function addMembersToGroup($group_id, array $members)
public function getAddMembersToGroupResult($group_id, $results_id)
public function getGroupMembers($group_id)
public function updateMyGroupMembership($group_id, $nickname)
public function removeGroupMember($group_id, $user_id)
public function getLatestGroupMessages($group_id, $limit=20)
public function getGroupMessagesBefore($group_id, $message_id, $limit=20)
public function getGroupMessagesAfter($group_id, $message_id, $limit=20)
public function getGroupMessagesSince($group_id, $message_id, $limit=20)
public function getGroupNameById($id)
public function getGroupIdByName($name)
public function isMemberOfGroup($grp)
public function sendGroupMessage($group_id, $text, array $attachments=array(), $source_guid=null)
```

Expand Down
88 changes: 60 additions & 28 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,24 +250,6 @@ public function unlikeDirectMessage($other_user_id, $message_id) {

// GROUP METHODS

/**
* Gets a group id by the group name
*
* @param string $name Group name
*
* @return mixed Group id or FALSE
*/
public function getGroupIdByName($name) {
$res = $this->getAllGroups();

if($res['meta']['code'] == self::HTTP_OK)
foreach($res['response'] as $group) {
if ($group['name'] == $name) return $group['id'];
}

return FALSE;
}

/**
* Checks if the authenticated user is a member
* of a certain group
Expand All @@ -289,20 +271,53 @@ public function isMemberOfGroup($grp) {
return FALSE;
}

function getGroupById($group_id) {
return $this->get("/groups/$group_id");
}

function getGroupByName($name) {
$res = $this->getAllGroups();

if($res['meta']['code'] == self::HTTP_OK)
foreach($res['response'] as $group) {
if ($group['name'] == $name)
return array(
'meta' => $res['meta'],
'response' => $group
);
}

return $res;
}

/**
* Gets a group id by the group name
*
* @param string $name Group name
*
* @return mixed Group id or FALSE
*/
public function getGroupIdByName($name) {
$res = $this->getGroupByName($name);

if($res['meta']['code'] == self::HTTP_OK)
return $res['response']['id'];

return FALSE;
}

/**
* Gets a group name by its id
*
* @param int $id Group id
* @param int $group_id Group id
*
* @return mixed Group name or FALSE
*/
public function getGroupNameById($id) {
$res = $this->getAllGroups();
public function getGroupNameById($group_id) {
$res = $this->getGroupById($group_id);

if($res['meta']['code'] == self::HTTP_OK)
foreach($res['response'] as $group) {
if ($group['id'] == $id) return $group['name'];
}
return $res['response']['name'];

return FALSE;
}
Expand Down Expand Up @@ -366,14 +381,16 @@ public function createGroup($name, $description='', $image_url='', $share=false)
}

/**
* Retrieves a specific group
* Retrieves group details
*
* @param string $group_id Group id
* @param string $group Group id or group name
*
* @return mixed
*/
public function getGroupDetails($group_id) {
return $this->get("/groups/$group_id");
public function getGroupDetails($group) {
if (is_numeric($group)) return $this->getGroupById($group);
if (is_string($group)) return $this->getGroupByName($group);
return array();
}

/**
Expand Down Expand Up @@ -562,6 +579,21 @@ public function updateMyGroupMembership($group_id, $nickname) {
return $this->post("/groups/$group_id/memberships/update", $payload);
}

/**
* Gets all members of a group
*
* @param int $group_id Group id
*
* @return array Group members or empty array
*/
public function getGroupMembers($group_id) {
$group = $this->getGroupDetails($group_id);
if (is_array($group['response']['members']))
return $group['response']['members'];

return array();
}

/**
* Removes a member (or yourself) from a group
*
Expand Down

0 comments on commit 4babedb

Please sign in to comment.