Skip to content

Commit

Permalink
added ChannelModel
Browse files Browse the repository at this point in the history
  • Loading branch information
gnello committed Apr 23, 2017
1 parent 79b9173 commit 0ee7d4d
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 19 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,27 @@ $result = $driver->getTeamModel()->createTeam($requestOptions);
$result = $driver->getTeamModel()->getTeamByName('new_team');
```

### Channel data model
```php
//Create a channel
$teamID = 'team_id_to_add_the_channel_to';
$requestOptions = [
'name' => 'new_channel',
'display_name' => 'New Channel',
'type' => 'O',
];
$result = $driver->getChannelModel($teamId)->createChannel($requestOptions);


//Get a channel
$teamID = 'team_id_of_the_channels_to_return';
$result = $driver->getChannelModel($teamId)->getChannelByName('new_channel');
```

## ToDo
[x] Add Team data model
[ ] Add Channel data model (in development)
[ ] Add Post data model
[x] Add Channel data model
[ ] Add Post data model (in development)
[ ] Add File data model
[ ] Add Admin data model
[ ] Add Preference data model
Expand Down
18 changes: 14 additions & 4 deletions src/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
* This Driver is based entirely on official documentation of the Mattermost Web
* Services API and you can extend it by following the directives of the documentation.
*
* For the full copyright and license information, please read the LICENSE.txt
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/gnello/php-mattermost-driver/contributors
*
* God bless this mess.
*
* @author Luca Agnello <luca@gnello.com>
Expand All @@ -15,6 +11,7 @@

namespace Gnello\Mattermost;

use Gnello\Mattermost\Models\ChannelModel;
use Gnello\Mattermost\Models\TeamModel;
use Gnello\Mattermost\Models\UserModel;
use Pimple\Container;
Expand Down Expand Up @@ -112,4 +109,17 @@ public function getTeamModel()

return $this->models['team'];
}

/**
* @param $teamId
* @return ChannelModel
*/
public function getChannelModel($teamId)
{
if (!isset($this->models['channel'])) {
$this->models['channel'] = new ChannelModel($this->container['client'], $teamId);
}

return $this->models['channel'];
}
}
170 changes: 167 additions & 3 deletions src/Models/ChannelModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

namespace Gnello\Mattermost\Models;

use Gnello\Mattermost\Client;

/**
* Class ChannelModel
*
Expand All @@ -28,12 +30,174 @@ class ChannelModel extends AbstractModel
public static $endpoint = '/channels';

/**
* @param $teamId
* @var string
*/
private $teamId;

/**
* ChannelModel constructor.
*
* @param Client $client
* @param $teamID
*/
public function __construct(Client $client, $teamID)
{
$this->teamId = $teamID;
parent::__construct($client);
}

/**
* @param array $requestOptions
* @return \Psr\Http\Message\ResponseInterface
*/
public function createChannel(array $requestOptions)
{
return $this->client->post(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/create', $requestOptions);
}

/**
* @param array $requestOptions
* @return \Psr\Http\Message\ResponseInterface
*/
public function updateChannel(array $requestOptions)
{
return $this->client->post(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/update', $requestOptions);
}

/**
* @param array $requestOptions
* @return \Psr\Http\Message\ResponseInterface
*/
public function viewChannel(array $requestOptions)
{
return $this->client->post(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/view', $requestOptions);
}

/**
* @return \Psr\Http\Message\ResponseInterface
*/
public function getChannelsForTheUser()
{
return $this->client->get(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/');
}

/**
* @param $channelName
* @return \Psr\Http\Message\ResponseInterface
*/
public function getChannelByName($channelName)
{
return $this->client->get(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/name/' . $channelName);
}

/**
* @param $offset
* @param $limit
* @return \Psr\Http\Message\ResponseInterface
*/
public function getPageOfChannelsTheUserHasNotJoined($offset, $limit)
{
return $this->client->get(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/more/' . $offset . '/' . $limit);
}

/**
* @return \Psr\Http\Message\ResponseInterface
*/
public function getChannelMembersForTheUser()
{
return $this->client->get(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/members');
}

/**
* @return \Psr\Http\Message\ResponseInterface
*/
public function getChannelsPinnedPosts()
{
return $this->client->get(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/pinned');
}

/**
* @param $channelId
* @return \Psr\Http\Message\ResponseInterface
*/
public function getChannel($channelId)
{
return $this->client->get(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/' . $channelId);
}

/**
* @param $channelId
* @return \Psr\Http\Message\ResponseInterface
*/
public function getStatsOfChannel($channelId)
{
return $this->client->get(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/' . $channelId . '/stats');
}

/**
* @param $channelId
* @return \Psr\Http\Message\ResponseInterface
*/
public function deleteChannel($channelId)
{
return $this->client->post(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/' . $channelId . '/delete');
}

/**
* @param $channelId
* @param array $requestOptions
* @return \Psr\Http\Message\ResponseInterface
*/
public function addUser($channelId, array $requestOptions)
{
return $this->client->post(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/' . $channelId . '/add', $requestOptions);
}

/**
* @param $channelId
* @param $userId
* @return \Psr\Http\Message\ResponseInterface
*/
public function getChannelMember($channelId, $userId)
{
return $this->client->get(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/' . $channelId . '/members/' . $userId);
}

/**
* @param $channelId
* @param array $requestOptions
* @return \Psr\Http\Message\ResponseInterface
*/
public function getChannelMembersByIds($channelId, array $requestOptions)
{
return $this->client->post(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/' . $channelId . '/members/ids', $requestOptions);
}

/**
* @param $channelId
* @param array $requestOptions
* @return \Psr\Http\Message\ResponseInterface
*/
public function updateRolesOfChannelMember($channelId, array $requestOptions)
{
return $this->client->post(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/' . $channelId . '/update_member_roles', $requestOptions);
}

/**
* @param array $requestOptions
* @return \Psr\Http\Message\ResponseInterface
*/
public function autocompleteChannelsInATeam(array $requestOptions)
{
return $this->client->post(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/autocomplete', $requestOptions);
}

/**
* @param array $requestOptions
* @return \Psr\Http\Message\ResponseInterface
*/
public function createChannel($teamId, array $requestOptions)
public function searchForMoreChannels(array $requestOptions)
{
return $this->client->post(TeamModel::$endpoint . '/' . $teamId . '/' . self::$endpoint . '/create', $requestOptions);
return $this->client->post(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/more/search', $requestOptions);
}
}
16 changes: 6 additions & 10 deletions src/Models/UserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
* This Driver is based entirely on official documentation of the Mattermost Web
* Services API and you can extend it by following the directives of the documentation.
*
* For the full copyright and license information, please read the LICENSE.txt
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/gnello/php-mattermost-driver/contributors
*
* God bless this mess.
*
* @author Luca Agnello <luca@gnello.com>
Expand Down Expand Up @@ -127,9 +123,9 @@ public function getUsersListByIds(array $requestOptions)
* @param $limit
* @return \Psr\Http\Message\ResponseInterface
*/
public function getUserOfChannel($team_id, $channel_id, $offset, $limit)
public function getUserInChannel($team_id, $channel_id, $offset, $limit)
{
$uri = TeamModel::$endpoint . '/' . $team_id . ChannelModel::$endpoint . '/' . $channel_id . '/' . self::$endpoint . '/' . $offset . '/' . $limit;
$uri = TeamModel::$endpoint . '/' . $team_id . '/channels/' . $channel_id . '/' . self::$endpoint . '/' . $offset . '/' . $limit;
return $this->client->get($uri);
}

Expand All @@ -140,9 +136,9 @@ public function getUserOfChannel($team_id, $channel_id, $offset, $limit)
* @param $limit
* @return \Psr\Http\Message\ResponseInterface
*/
public function getUserNotOfChannel($team_id, $channel_id, $offset, $limit)
public function getUserNotInChannel($team_id, $channel_id, $offset, $limit)
{
$uri = TeamModel::$endpoint . '/' . $team_id . ChannelModel::$endpoint . '/' . $channel_id . '/' . self::$endpoint . '/not_in_channel/' . $offset . '/' . $limit;
$uri = TeamModel::$endpoint . '/' . $team_id . '/channels/' . $channel_id . '/' . self::$endpoint . '/not_in_channel/' . $offset . '/' . $limit;
return $this->client->post($uri);
}

Expand Down Expand Up @@ -204,7 +200,7 @@ public function sendPasswordResetEmail(array $requestOptions)
* @param $requestOptions
* @return \Psr\Http\Message\ResponseInterface
*/
public function restUserPassword(array $requestOptions)
public function resetUserPassword(array $requestOptions)
{
return $this->client->post(self::$endpoint . '/reset_password', $requestOptions);
}
Expand Down Expand Up @@ -237,7 +233,7 @@ public function autocompleteUsersOfTeam($team_id, array $requestOptions)
*/
public function autocompleteUsersOfChannel($team_id, $channel_id, array $requestOptions)
{
$uri = TeamModel::$endpoint . '/' . $team_id . ChannelModel::$endpoint . '/' . $channel_id . '/' . self::$endpoint . '/autocomplete';
$uri = TeamModel::$endpoint . '/' . $team_id . '/channels/' . $channel_id . '/' . self::$endpoint . '/autocomplete';
return $this->client->get($uri, $requestOptions);
}
}

0 comments on commit 0ee7d4d

Please sign in to comment.