<commit_before># php-mattermost-driver (v4)

[![Latest Stable Version][7]][8] [![Scrutinizer Code Quality][5]][6] [![Total Downloads][11]][12]

The Php Driver to interact with the [Mattermost Web Service API][4].  

Please read [the api documentation][1] for further information on using this application.

## Installation
### Composer
The best way to install php-mattermost-driver is to use Composer:

```
composer require gnello/php-mattermost-driver
```

Read more about how to install and use Composer on your local machine [here][3].

### Laravel
If you are going to install this library on laravel maybe you prefer to install the [laravel-mattermost-driver][10].

#### V3
If you want to install the [V3 Driver][9] instead of the V4 one you should do:

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

## Usage
### Authentication

#### Login id and password
```php
 use \Gnello\Mattermost\Driver;
 
 $container = new \Pimple\Container([
     'driver' => [
         'url' => 'your_chat_url',
         'login_id' => 'your_login_id',
         'password' => '<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 his [official documentation][13].

| Option   | Default     | 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 the with 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<commit_msg>Update the README.<commit_after># php-mattermost-driver (v4)

[![Latest Stable Version][7]][8] [![Scrutinizer Code Quality][5]][6] [![Total Downloads][11]][12]

The Php Driver to interact with the [Mattermost Web Service API][4].  

Please read [the api documentation][1] for further information on using this application.

## Installation
### Composer
The best way to install php-mattermost-driver is to use Composer:

```
composer require gnello/php-mattermost-driver
```

Read more about how to install and use Composer on your local machine [here][3].

### Laravel
If you are going to install this library on laravel maybe you prefer to install the [laravel-mattermost-driver][10].

#### V3
If you want to install the [V3 Driver][9] instead of the V4 one you should do:

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

## Usage
### Authentication

#### Login id and password
```php
 use \Gnello\Mattermost\Driver;
 
 $container = new \Pimple\Container([
     'driver' => [
         'url' => 'your_chat_url',
         'login_id' => 'your_login_id',
         'password' => '<PASSWORD>',
     ]
 ]);
 
 $driver = new Driver($container);
 $result = $driver->authenticate();
 ```

#### Token
```php
 use \Gnello\Mattermost\Driver;
 
 $container = new \Pimple\Container([
     'driver' => [
         'url' => 'your_chat_url',
         'token' => '<PASSWORD>',
     ]
 ]);
 
 $driver = new Driver($container);
 $result = $driver->authenticate();
 ```

### Options
Below a list of all the Driver available options, for the Guzzle options
please refer to his [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 the with 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
{'fraction_non_alphanumeric': 0.15681432319802438, 'fraction_numerical': 0.008334619540052476, 'mean_word_length': 2.020979020979021, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6085516', 'n_tokens_mistral': 1786, 'n_tokens_neox': 1690, 'n_words': 598}