<commit_before># php-openfire-restapi
Easy Php REST API Client to manage [Openfire Server] (http://www.igniterealtime.org/projects/openfire/)

## VERSION
current version: 1.2.0

##### CHANGELOG

- v1.2.0 (29/09/2016)  
-- Added debug mode  
-- Improved logic of Settings  

- v1.1.0 (16/07/2016)  
-- Renamed some methods into API class

- v1.0.4 (21/05/2016)  
-- first release

## LICENSE
PhpOpenFireRestAPI is licensed under Apache License 2.0, see LICENCE for further information.

## REQUIREMENTS
- PHP 5.3+

## INSTALLATION
### Composer
The best way to install php-openfire-restapi is to use Composer, you do that:

1) Add the following to your project's ```composer.json``` file:
```json
{
    "require": {
        "gnello/php-openfire-restapi": "dev-master"
    }
}
```

2) Run ```composer install``` or ```composer update``` command

Read more about how to install and use Composer on your local machine [here] (https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx).

## CONFIGURATION
Just change these constants into src/Settings/Settings.php
```php
const HOST = 'your_host';
const PORT = '9090';
const PLUGIN = '/plugins/restapi/v1';
const SECRET = 'your_secret';
const SERVER_NAME = 'your_server_name';
```

or you can dynamically configure it at any point of the project in this way
```php
include "vendor/autoload.php";

//Set the required config parameters
$settings = \Gnello\OpenFireRestAPI\Settings\Settings::getInstance();
$settings->setSecret("your_secret");
$settings->setHost("your_host");
$settings->setServerName("your_servername");

//Default values
$settings->->setPort("9090");
$settings->->setSSL(false);
$settings->->setPlugin("/plugins/restapi/v1");
```

## USAGE
### Start
```php
include "vendor/autoload.php";

$api = new \Gnello\OpenFireRestAPI\API();
```
### Check result
```php
if($result['response']) {
    echo $result['output'];
} else {
    echo 'Error!';
}
```
### Users
```php
//Add a new user
$properties = array('key1' => 'value1', 'key2' => 'value2');
$result = $api->Users()->createUser('Username', 'Password', 'Full Name', '<EMAIL>', $properties);

//Delete a user
$result = $api->Users()->deleteUser('Username');

//Ban a user
$result = $api->Users()->lockoutUser('Username');

//Unban a user
$result = $api->Users()->unlockUser('Username');
```
### Rosters
```php
//Add to roster
use \Gnello\OpenFireRestAPI\Settings\SubscriptionType;
$result = $api->Users()->createUserRosterEntry('Username', 'Jid', 'Full Name', SubscriptionType::BOTH, array('group1','group2'));

//Update roster
use \Gnello\OpenFireRestAPI\Settings\SubscriptionType;
$result = $api->Users()->updateUserRosterEntry('Username', 'Jid', 'Full Name', SubscriptionType::BOTH, array('group1'));

//Delete from roster
$result = $api->Users()->deleteUserRosterEntry('Username', 'Jid');
```
### Groups
```php
//Create group
$result = $api->Groups()->createGroup('groupname', 'description');

//Add to Groups
$result = $api->Users()->addUserToGroup('Username', array('groupname1', 'groupname2', 'groupname3'));

//Delete from Groups
$result = $api->Users()->deleteUserFromGroup('Username', array('groupname1','groupname2'));
```
### Messages
```php
//Send message to all online users
$result = $api->Messages()->sendBroadcastMessage('Hello everybody!');
```
### ChatRooms
```php
//Create a new ChatRoom
$payload = new \Gnello\OpenFireRestAPI\Payloads\ChatRoom();
$payload->setRoomName('myfirstchatroom');
$payload->setNaturalName('my_first_chat_room');
$payload->setDescription('This is my first chat room!');
$result = $api->ChatRooms()->createChatRoom($payload);

//Add user with role to chat room
$result = $api->ChatRooms()->addUserWithRoleToChatRoom('myfirstchatroom','members','username');

//Add group with role to chat room
$result = $api->ChatRooms()->addGroupWithRoleToChatRoom('myfirstchatroom','outcasts','groupname');

//Delete a user from a chat room
$result = $api->ChatRooms()->deleteUserFromChatRoom('myfirstchatroom','members','username');

//Delete a chat room
$result = $api->ChatRooms()->deleteChatRoom('myfirstchatroom');
```
## DEBUG
Under development you may need access to some useful information of the execution of software they're not normally available. 
To do this just enable debug mode like this
```php
//Enable debug mode
$settings->setDebug(true);
```
At the moment is only available the register of requests with its server responses, you can access it in this way
```php
$requests = \Gnello\OpenFireRestAPI\Debug\Request::getRequests();
```

## CONTACT
- gnello <EMAIL><commit_msg>mod readme<commit_after># php-openfire-restapi
Easy Php REST API Client to manage [Openfire Server] (http://www.igniterealtime.org/projects/openfire/)

## VERSION
current version: 1.2.0

##### CHANGELOG

- v1.2.0 (29/09/2016)  
-- Added debug mode  
-- Improved logic of Settings  

- v1.1.0 (16/07/2016)  
-- Renamed some methods into API class

- v1.0.4 (21/05/2016)  
-- first release

## LICENSE
PhpOpenFireRestAPI is licensed under Apache License 2.0, see LICENCE for further information.

## REQUIREMENTS
- PHP 5.3+

## INSTALLATION
### Composer
The best way to install php-openfire-restapi is to use Composer, you do that:

1) Add the following to your project's ```composer.json``` file:
```json
{
    "require": {
        "gnello/php-openfire-restapi": "dev-master"
    }
}
```

2) Run ```composer install``` or ```composer update``` command

Read more about how to install and use Composer on your local machine [here] (https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx).

## CONFIGURATION
Just change these constants into src/Settings/Settings.php
```php
const HOST = 'your_host';
const PORT = '9090';
const PLUGIN = '/plugins/restapi/v1';
const SECRET = 'your_secret';
const SERVER_NAME = 'your_server_name';
```

or you can dynamically configure it at any point of the project in this way
```php
include "vendor/autoload.php";

//Set the required config parameters
$api->Settings()->setSecret("your_secret");
$api->Settings()->setHost("your_host");
$api->Settings()->setServerName("your_servername");

//Default values
$api->Settings()->setPort("9090");
$api->Settings()->setSSL(false);
$api->Settings()->setPlugin("/plugins/restapi/v1");
```

## USAGE
### Start
```php
include "vendor/autoload.php";

$api = new \Gnello\OpenFireRestAPI\API();
```
### Check result
```php
if($result['response']) {
    echo $result['output'];
} else {
    echo 'Error!';
}
```
### Users
```php
//Add a new user
$properties = array('key1' => 'value1', 'key2' => 'value2');
$result = $api->Users()->createUser('Username', 'Password', 'Full Name', '<EMAIL>', $properties);

//Delete a user
$result = $api->Users()->deleteUser('Username');

//Ban a user
$result = $api->Users()->lockoutUser('Username');

//Unban a user
$result = $api->Users()->unlockUser('Username');
```
### Rosters
```php
//Add to roster
use \Gnello\OpenFireRestAPI\Settings\SubscriptionType;
$result = $api->Users()->createUserRosterEntry('Username', 'Jid', 'Full Name', SubscriptionType::BOTH, array('group1','group2'));

//Update roster
use \Gnello\OpenFireRestAPI\Settings\SubscriptionType;
$result = $api->Users()->updateUserRosterEntry('Username', 'Jid', 'Full Name', SubscriptionType::BOTH, array('group1'));

//Delete from roster
$result = $api->Users()->deleteUserRosterEntry('Username', 'Jid');
```
### Groups
```php
//Create group
$result = $api->Groups()->createGroup('groupname', 'description');

//Add to Groups
$result = $api->Users()->addUserToGroup('Username', array('groupname1', 'groupname2', 'groupname3'));

//Delete from Groups
$result = $api->Users()->deleteUserFromGroup('Username', array('groupname1','groupname2'));
```
### Messages
```php
//Send message to all online users
$result = $api->Messages()->sendBroadcastMessage('Hello everybody!');
```
### ChatRooms
```php
//Create a new ChatRoom
$payload = new \Gnello\OpenFireRestAPI\Payloads\ChatRoom();
$payload->setRoomName('myfirstchatroom');
$payload->setNaturalName('my_first_chat_room');
$payload->setDescription('This is my first chat room!');
$result = $api->ChatRooms()->createChatRoom($payload);

//Add user with role to chat room
$result = $api->ChatRooms()->addUserWithRoleToChatRoom('myfirstchatroom','members','username');

//Add group with role to chat room
$result = $api->ChatRooms()->addGroupWithRoleToChatRoom('myfirstchatroom','outcasts','groupname');

//Delete a user from a chat room
$result = $api->ChatRooms()->deleteUserFromChatRoom('myfirstchatroom','members','username');

//Delete a chat room
$result = $api->ChatRooms()->deleteChatRoom('myfirstchatroom');
```
## DEBUG
Under development you may need access to some useful information of the execution of software they're not normally available. 
To do this just enable debug mode like this
```php
//Enable debug mode
$api->Settings()->setDebug(true);
```
At the moment is only available the register of requests with its server responses, you can access it in this way
```php
$requests = \Gnello\OpenFireRestAPI\Debug\Request::getRequests();
```

## CONTACT
- gnello <EMAIL>
{'fraction_non_alphanumeric': 0.1776083112290009, 'fraction_numerical': 0.014588859416445624, 'mean_word_length': 5.458957887223412, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 105, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1233491', 'n_tokens_mistral': 2985, 'n_tokens_neox': 2848, 'n_words': 772}