Code Monkey home page Code Monkey logo

php-openfire-restapi's Introduction

php-openfire-restapi

Join the chat at https:#gitter.im/gidkom/php-openfire-restapi

Build Status

A simple PHP class designed to work with Openfire Rest Api plugin. It is used to remote manage the Openfire server.

LICENSE

php-openfire-restapi is licensed under MIT style license, see LICENCE for further information.

DEPENDENCIES

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

REQUIREMENTS

  • PHP 5.4+

INSTALLATION

With Composer


The easiest way to install is via composer. Create the following composer.json file and run the composer.phar install command to install it.

composer require gidkom/php-openfire-restapi:v1.1.0

OR

{
    "require": {
        "gidkom/php-openfire-restapi": "v1.1.0"
    }
}

EXAMPLE

SETUP

include "vendor/autoload.php";

SET PARAMETERS

# Create the Openfire Rest api object
$api = new Gidkom\OpenFireRestApi\OpenFireRestApi;

# Set the required config parameters
$api->secret = "MySecret";
$api->host = "jabber.myserver.com";
$api->port = "9090";  # default 9090

# Optional parameters (showing default values)

$api->useSSL = false;
$api->plugin = "/plugins/restapi/v1";  # plugin 

Response format

# Check result if command is succesful
if($result['status']) {
    # Display result
    print_r($result['data']);
} else {
    # Something went wrong
    echo 'Error: ';
    echo $result['data'];
}

User related examples

# Retrieve users
$options = ['search'=> 'John']; # optional
$result = $api->getUsers($options);

# Retrieve a user
$result = $api->getUser($username);

# Add a new user to OpenFire and add to a group
$result = $api->addUser('Username', 'Password', 'Real Name', '[email protected]', array('Group 1'));

#Delete a user from OpenFire
$result = $api->deleteUser($username);

# Update a user
# The $password, $name, $email, $groups arguments are optional
$result = $api->updateUser($username, $password, $name, $email, $groups);

# Add user to a group
$result = $api->addToGroup($username, $groupName);

# Delete user from a group
$result = $api->deleteFromGroup($username, $groupName);

# Disable/lockout a user
$result = $api->lockoutUser($username);

# Enable a user
$result = $api->unlockUser($username);

# Retrieve a user roster
$api->userRosters($username);

# Create a user roster entry
$api->addToRoster($username, $jid);

# Delete from roster
$api->deleteFromRoster($username, $jid);

# Update user roster
$api->updateRoster($username, $jid, $nickname, $subscription]);


Chat room related Endpoints

# Get all chat rooms
$api->getAllChatRooms();

# Retrieve a chat room
$api->getChatRoom($name);

# Create a chat room
# $params  = ['naturalName'=>'myroom', 'roomName'=>'myroom', 'description'=>'my chat room']; 
$api->createChatRoom($params);

# Delete a chat room
$api->deleteChatRoom($roomName);

# Update a chat room
# $params  = ['naturalName'=>'myroom', 'roomName'=>'myroom', 'description'=>'my fav chat room'];  
$api->createChatRoom($roomName =>$params);

# Add user with role to chat room
$api->addUserRoleToChatRoom($roomName, $name, $role);

System related Endpoints

# Retrieve all system properties
$api->getSystemProperties();

# Retrieve a system property
$api->getSystemProperty('plugin.restapi.httpAuth');

# Create a system property
$api->createSystemProperty(['key'=>'test', 'value'=>'testname']);

# Update a system property
$api->updateSystemProperty(['key'=>'test', 'value'=>'testname']);

# Delete a system property
$api->deleteSystemProperty('test');

# Retrieve concurrent sessions
$api->getConcurrentSessons();

Group related Endpoints

# Get all groups
$api->getGroups();

# Retrieve group 
$api->getGroup($groupName);

# Create a group
$api->createGroup($groupName, $description);

# Update a group description
$api->updateGroup($groupName, $description);

# Delete a group
$api->deleteGroup($groupName);

Session related Endpoints

# Retrieve all users sessions
$api->getSessions();

# Retrieve all users sessions
$api->getUserSessions($username);

# Close all user sessions
$api->closeUserSessions($username);

Message related Endpoints

# Send a broadcast message to all online users
$api->broadcastMessage('hello');

CONTACT

php-openfire-restapi's People

Contributors

alfredog1976 avatar emamirazavi avatar gidkom avatar gitter-badger avatar ottoszika avatar tibo9 avatar umpirsky 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.