Skip to content

Sidlegionair/php-openfire-restapi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-openfire-restapi

Build Status Latest Stable Version Scrutinizer Code Quality

Easy Php REST API Client for the Openfire REST API Plugin which provides the ability to manage Openfire instance by sending an REST/HTTP request to the server

Please read documentation for further information on using this application.

License

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

Requirements

  • PHP 5.3+

Dependencies

The REST API plugin need to be installed and configured on the Openfire server.

Installation

Composer

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

composer require gnello/php-openfire-restapi

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

Usage

Authentication

There are two ways to authenticate:

  • Basic HTTP Authentication
$authenticationToken = new \Gnello\OpenFireRestAPI\AuthenticationToken('your_user', 'your_password');
  • Shared secret key
$authenticationToken = new \Gnello\OpenFireRestAPI\AuthenticationToken('your_secret_key');

Start

$api = new \Gnello\OpenFireRestAPI\API('your_host', 9090, $authenticationToken);

Configuration

Usually you do not need to change anything, otherwise you can do it this way

$api->Settings()->setServerName("your_servername");
$api->Settings()->setHost("your_host");
$api->Settings()->setPort("9090");
$api->Settings()->setSSL(false);
$api->Settings()->setPlugin("/plugins/restapi/v1");

Check result

if($result['response']) {
    echo $result['output'];
} else {
    echo 'Error!';
}

Users

//Add a new user
$properties = array('key1' => 'value1', 'key2' => 'value2');
$result = $api->Users()->createUser('Username', 'Password', 'Full Name', '[email protected]', $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

//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

//Create group
$result = $api->Groups()->createGroup('groupname', 'description');

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

//Delete from Groups
$result = $api->Users()->deleteUserFromGroups('Username', array('groupname1','groupname2'));

Messages

//Send message to all online users
$result = $api->Messages()->sendBroadcastMessage('Hello everybody!');

ChatRooms

//Create a new ChatRoom
$payload = $api->Payloads()->createChatRoomPayload();
$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

//Enable debug mode
$api->Settings()->setDebug(true);

At the moment it's available the register of requests (with its server responses) and the curl info. You can access it in this way

$requests = $api->Debugger()->getRequests();
$curlInfo = $api->Debugger()->getCurlInfo();

please note that if you do not make requests, these variables will be empty ;)

Contact

About

Easy Full Php REST API Client to manage Openfire Server

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%