Skip to content

Commit

Permalink
added PreferenceModel
Browse files Browse the repository at this point in the history
  • Loading branch information
gnello committed Apr 25, 2017
1 parent 8b4100c commit 379c0fb
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 17 deletions.
18 changes: 1 addition & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,13 @@ $postId = 'post_id_of_the_post_to_return';
$result = $driver->getPostModel($teamId)->getPost($channelId, $postId);
```

### File data model
```php
//Upload a file
$teamId = 'the_id_of_one_of_the_current_users_teams';
$requestOptions = [
'files' => 'a file to be uploaded',
'channel_id' => 'the id of the channel that this file will be uploaded to'
];
$result = $driver->getFileModel()->uploadFile($teamId, $requestOptions);


//Get a file
$fileId = 'the_id_of_the_file_to_get';
$result = $driver->getFileModel()->getFile($fileId);
```

## ToDo
[x] Add Team data model
[x] Add Channel data model
[x] Add Post data model
[x] Add File data model
[ ] Add Admin data model (in development)
[ ] Add Preference data model
[x] Add Preference data model

## Contact
- [email protected]
Expand Down
13 changes: 13 additions & 0 deletions src/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Gnello\Mattermost\Models\ChannelModel;
use Gnello\Mattermost\Models\FileModel;
use Gnello\Mattermost\Models\PostModel;
use Gnello\Mattermost\Models\PreferenceModel;
use Gnello\Mattermost\Models\TeamModel;
use Gnello\Mattermost\Models\UserModel;
use Pimple\Container;
Expand Down Expand Up @@ -149,4 +150,16 @@ public function getFileModel()

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

/**
* @return PreferenceModel
*/
public function getPreferenceModel()
{
if (!isset($this->models['preference'])) {
$this->models['preference'] = new PreferenceModel($this->container['client']);
}

return $this->models['preference'];
}
}
67 changes: 67 additions & 0 deletions src/Models/PreferenceModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* 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 <[email protected]>
* @link https://api.mattermost.com/
*/

namespace Gnello\Mattermost\Models;

/**
* Class PreferenceModel
*
* @package Gnello\Mattermost\Models
*/
class PreferenceModel extends AbstractModel
{
/**
* @var string
*/
public static $endpoint = '/preferences';

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

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

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

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

}

0 comments on commit 379c0fb

Please sign in to comment.