2017 © Pedro Peláez
 

library php-mattermost-driver

Completed Php Driver to interact with the Mattermost Web Service API

image

gnello/php-mattermost-driver

Completed Php Driver to interact with the Mattermost Web Service API

  • Tuesday, April 17, 2018
  • by gnello
  • Repository
  • 4 Watchers
  • 24 Stars
  • 3,347 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 8 Forks
  • 1 Open issues
  • 14 Versions
  • 16 % Grown

The README.md

php-mattermost-driver

Latest Stable Version Scrutinizer Code Quality [Total Downloads][12], (*1)

The PHP Driver to interact with the Mattermost Web Service API., (*2)

Please read the api documentation for further information on using this application., (*3)

Installation

Composer

The best way to install php-mattermost-driver is to use Composer:, (*4)

composer require gnello/php-mattermost-driver

Read more about how to install and use Composer on your local machine here., (*5)

Laravel

If you are going to install this library on laravel maybe you prefer to install the laravel-mattermost-driver., (*6)

V3

If you want to install the V3 Driver instead of the V4 one you should do:, (*7)

composer require gnello/php-mattermost-driver:1.*

Usage

Authentication

Login id and password

 use \Gnello\Mattermost\Driver;

 $container = new \Pimple\Container([
     'driver' => [
         'url' => 'your_chat_url',
         'login_id' => 'your_login_id',
         'password' => 'your_password',
     ]
 ]);

 $driver = new Driver($container);
 $result = $driver->authenticate();
 ```

#### Token
```php
 use \Gnello\Mattermost\Driver;

 $container = new \Pimple\Container([
     'driver' => [
         'url' => 'your_chat_url',
         'token' => 'your_token',
     ]
 ]);

 $driver = new Driver($container);
 $result = $driver->authenticate();
 ```

### Options
Below a list of all the Driver available options, for the Guzzle options
please refer to its [official documentation][13].

| Option   | Default value | Description                                                                                |
|:---------|:--------------|:-------------------------------------------------------------------------------------------|
| scheme   | "https"       | The URI scheme.                                                                            |
| basePath | "/api/v4"     | The base path of the API endpoint.                                                         |
| url      | "localhost"   | The URL of the Mattermost server, without the scheme (es. "www.mydomain.com").             |
| login_id | null          | The account username to use with the API.                                                  |
| password | null          | The account password to use with the API.                                                  |
| token    | null          | The account token to use with the API, if specified it override the login_id and password. |

You can specify the options as shown in the following example:
```php
 use \Gnello\Mattermost\Driver;

 $container = new \Pimple\Container([
     'driver' => [
         //put here any options for the driver
     ],
     'guzzle' => [
         //put here any options for Guzzle
     ]
 ]);

 $driver = new Driver($container);
 $result = $driver->authenticate();
 ```

### Check results
This Driver follows the [PSR-7][2] document therefore any response is a ResponseInterface type:

```php
if ($result->getStatusCode() == 200) {
    echo "Everything is ok.";
    var_dump(json_decode($result->getBody()));
} else {
    echo "HTTP ERROR " . $result->getStatusCode();
}

Users endpoint

//Add a new user
$result = $driver->getUserModel()->createUser([
    'email'    => 'test@test.com', 
    'username' => 'test', 
    'password' => 'testpsw'
]);

//Get a user
$result = $driver->getUserModel()->getUserByUsername('username');

//Please read the UserModel class or refer to the api documentation for a complete list of available methods.

Channels endpoint

//Create a channel
$result = $driver->getChannelModel()->createChannel([
    'name'         => 'new_channel',
    'display_name' => 'New Channel',
    'type'         => 'O',
]);


//Get a channel
$result = $driver->getChannelModel()->getChannelByName('team_id_of_the_channel_to_return', 'new_channel');

//Search a channel
$result = $driver->getChannelModel()->searchChannels($teamId, [
    'term' => "full or partial name or display name of channels"
]);

//Please read the ChannelModel class or refer to the api documentation for a complete list of available methods.

Posts endpoint

//Create a post
$result = $driver->getPostModel()->createPost([
    'channel_id' => 'The channel ID to post in',
    'message' => 'The message contents, can be formatted with Markdown',
]);


//Get a post
$result = $driver->getPostModel()->getPost('post_id_of_the_post_to_return');

//Please read the PostModel class or refer to the api documentation for a complete list of available methods.

Files endpoint

//Upload a file
$result = $driver->getFileModel()->uploadFile([
    'channel_id' => 'The ID of the channel that this file will be uploaded to',
    'filename' => 'The name of the file to be uploaded',
    'files' => fopen('Path of the file to be uploaded', 'rb'),
]);

//Send a post with the file just uploaded
$result = $driver->getPostModel()->createPost([
    'channel_id' => 'The channel ID to post in',
    'message' => 'The message contents, can be formatted with Markdown',
    'file_ids' => 'A list of file IDs to associate with the post',
]);

//Please read the FileModel class or refer to the api documentation for a complete list of available methods.

Preferences endpoint

//Get a list of the user's preferences
$result = $driver->getPreferenceModel('user_id')->getUserPreference();

//Please read the PreferenceModel class or refer to the api documentation for a complete list of available methods.

Endpoints supported

Don't you see the endpoint you need? Feel free to open an issue or a PR!, (*8)

Contact

  • luca@gnello.com

The Versions

17/04 2018

dev-master

9999999-dev https://github.com/gnello/php-mattermost-driver

Completed Php Driver to interact with the Mattermost Web Service API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luca Agnello

chat mattermost

17/04 2018

v2.5.0

2.5.0.0 https://github.com/gnello/php-mattermost-driver

Completed Php Driver to interact with the Mattermost Web Service API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luca Agnello

chat mattermost

21/02 2018

v2.4.1

2.4.1.0 https://github.com/gnello/php-mattermost-driver

Completed Php Driver to interact with the Mattermost Web Service API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luca Agnello

chat mattermost

04/02 2018

v2.4.0

2.4.0.0 https://github.com/gnello/php-mattermost-driver

Completed Php Driver to interact with the Mattermost Web Service API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luca Agnello

chat mattermost

14/09 2017

v2.3.1

2.3.1.0 https://github.com/gnello/php-mattermost-driver

Completed Php Driver to interact with the Mattermost Web Service API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luca Agnello

chat mattermost

14/09 2017

v2.3.0

2.3.0.0 https://github.com/gnello/php-mattermost-driver

Completed Php Driver to interact with the Mattermost Web Service API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luca Agnello

chat mattermost

13/09 2017

v2.2.0

2.2.0.0 https://github.com/gnello/php-mattermost-driver

Completed Php Driver to interact with the Mattermost Web Service API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luca Agnello

chat mattermost

07/08 2017

v2.1.0

2.1.0.0 https://github.com/gnello/php-mattermost-driver

Completed Php Driver to interact with the Mattermost Web Service API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luca Agnello

chat mattermost

02/08 2017

v2.0.1

2.0.1.0 https://github.com/gnello/php-mattermost-driver

Completed Php Driver to interact with the Mattermost Web Service API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luca Agnello

chat mattermost

14/05 2017

v2.0.0

2.0.0.0 https://github.com/gnello/php-mattermost-driver

Completed Php Driver to interact with the Mattermost Web Service API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luca Agnello

chat mattermost

25/04 2017

v1.3.0

1.3.0.0 https://github.com/gnello/php-mattermost-driver

Completed Php Driver to interact with the Mattermost Web Service API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luca Agnello

chat mattermost

23/04 2017

v1.2.0

1.2.0.0 https://github.com/gnello/php-mattermost-driver

Completed Php Driver to interact with the Mattermost Web Service API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luca Agnello

chat mattermost

21/04 2017

v1.1.0

1.1.0.0 https://github.com/gnello/php-mattermost-driver

Completed Php Driver to interact with the Mattermost Web Service API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luca Agnello

chat mattermost

19/04 2017

v1.0.0

1.0.0.0 https://github.com/gnello/php-mattermost-driver

Completed Php Driver to interact with the Mattermost Web Service API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luca Agnello

chat mattermost