Skip to content

Commit

Permalink
Minor communities refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklaw5 committed Feb 21, 2017
1 parent b41511f commit a3bf487
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This library aims to support `v3`, `v4` and `v5` of the Twitch API until each on
- [x] Channels
- [x] Chat
- [x] Clips
- [ ] Communities
- [x] Communities
- [x] Games
- [x] Ingests
- [x] Search
Expand All @@ -23,6 +23,8 @@ This library aims to support `v3`, `v4` and `v5` of the Twitch API until each on
- [x] Users
- [x] Videos

Any endpoints missing? Open an [issue here](https://github.com/nicklaw5/twitch-api-php/issues).

**Other Features:**
- [ ] IRC Client
- [ ] Pub/Sub (ie. Bits & Whispers)
Expand Down
36 changes: 28 additions & 8 deletions src/Api/Communities.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ public function getCommunityByName($name)
/**
* Get community by ID
*
* @param string $id
* @param string $communityId
* @throws InvalidTypeException
* @throws EndpointNotSupportedByApiVersionException
* @return array|json
*/
public function getCommunityById($id)
public function getCommunityById($communityId)
{
if (!$this->apiVersionIsGreaterThanV4()) {
throw new EndpointNotSupportedByApiVersionException('communities');
}

if (!is_string($id)) {
throw new InvalidTypeException('ID', 'string', gettype($id));
if (!is_string($communityId)) {
throw new InvalidTypeException('Community ID', 'string', gettype($communityId));
}

return $this->get(sprintf('communities/%s', $id));
return $this->get(sprintf('communities/%s', $communityId));
}

/**
Expand Down Expand Up @@ -222,6 +222,7 @@ public function getBannedCommunityUsers($communityId, $accessToken, $limit = 10,
* @param string $userId
* @param string $accessToken
* @throws EndpointNotSupportedByApiVersionException
* @throws InvalidIdentifierException
* @return array|json
*/
public function banCommunityUser($communityId, $userId, $accessToken)
Expand All @@ -230,6 +231,10 @@ public function banCommunityUser($communityId, $userId, $accessToken)
throw new EndpointNotSupportedByApiVersionException('communities');
}

if (!is_numeric($userId)) {
throw new InvalidIdentifierException('user');
}

return $this->put(sprintf('communities/%s/bans/%s', $communityId, $userId), [], $accessToken);
}

Expand All @@ -240,6 +245,7 @@ public function banCommunityUser($communityId, $userId, $accessToken)
* @param string $userId
* @param string $accessToken
* @throws EndpointNotSupportedByApiVersionException
* @throws InvalidIdentifierException
* @return array|json
*/
public function unbanCommunityUser($communityId, $userId, $accessToken)
Expand All @@ -248,6 +254,10 @@ public function unbanCommunityUser($communityId, $userId, $accessToken)
throw new EndpointNotSupportedByApiVersionException('communities');
}

if (!is_numeric($userId)) {
throw new InvalidIdentifierException('user');
}

return $this->delete(sprintf('communities/%s/bans/%s', $communityId, $userId), [], $accessToken);
}

Expand Down Expand Up @@ -348,12 +358,13 @@ public function getCommunityModerators($communityId)
}

/**
* Add a community moderator
* Give a community user moderator permissions
*
* @param string $communityId
* @param int $userId
* @param string $accessToken
* @throws EndpointNotSupportedByApiVersionException
* @throws InvalidIdentifierException
* @return null|array|json
*/
public function addCommunityModerator($communityId, $userId, $accessToken)
Expand All @@ -362,24 +373,33 @@ public function addCommunityModerator($communityId, $userId, $accessToken)
throw new EndpointNotSupportedByApiVersionException('communities');
}

if (!is_numeric($userId)) {
throw new InvalidIdentifierException('user');
}

return $this->put(sprintf('communities/%s/moderators/%s', $communityId, $userId), [], $accessToken);
}

/**
* Delete a community moderator
* Remove moderator permission from a community user
*
* @param string $communityId
* @param int $userId
* @param string $accessToken
* @throws EndpointNotSupportedByApiVersionException
* @throws InvalidIdentifierException
* @return null|array|json
*/
public function deleteCommunityModerator($communityId, $userId, $accessToken)
public function removeCommunityModerator($communityId, $userId, $accessToken)
{
if (!$this->apiVersionIsGreaterThanV4()) {
throw new EndpointNotSupportedByApiVersionException('communities');
}

if (!is_numeric($userId)) {
throw new InvalidIdentifierException('user');
}

return $this->delete(sprintf('communities/%s/moderators/%s', $communityId, $userId), [], $accessToken);
}

Expand Down

0 comments on commit a3bf487

Please sign in to comment.