Coder Social home page Coder Social logo

php-openfire-restapi's Introduction

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

php-openfire-restapi's People

Contributors

gnello avatar

Watchers

Ishmael Dos avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.