2017 © Pedro Peláez
 

library php-openfire-restapi

Manage OpenFire Server using Rest API

image

gnello/php-openfire-restapi

Manage OpenFire Server using Rest API

  • Saturday, April 22, 2017
  • by gnello
  • Repository
  • 5 Watchers
  • 14 Stars
  • 736 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 8 Forks
  • 2 Open issues
  • 3 Versions
  • 18 % Grown

The README.md

php-openfire-restapi

[![Latest Stable Version][10]][11] [![Total Downloads][14]][15], (*1)

A PHP client for the Openfire REST API Plugin which provides you the ability to manage an Openfire instance by sending a REST/HTTP request to the server., (*2)

Please read the documentation for further information on using this application., (*3)

This client completely supports the >= 1.3.9 version of the REST API Plugin., (*4)

Dependencies

The REST API plugin need to be installed and configured on your Openfire server., (*5)

Installation

Composer

The best way to install php-openfire-restapi is to use Composer, run the following command:, (*6)

composer require gnello/php-openfire-restapi

Read more about how to install and use Composer here., (*7)

Usage

Instance and authentication

There are two ways of authentication:, (*8)

  • Basic HTTP Authentication
use Gnello\OpenFireRestAPI\Client;

$client = new Client([
    'client' => [
        'username' => 'ironman',
        'password' => 'romanoff',
    ]
]);
  • Shared secret key
use Gnello\OpenFireRestAPI\Client;

$client = new Client([
    'client' => [
        'secretKey' => 'hulkstink',
    ]
]);

Make sure to enable one of these authentication methods on your Openfire server., (*9)

Configuration

You can configure the Client with the following options:, (*10)

use Gnello\OpenFireRestAPI\Client;

$client = new Client([
    'client' => [
        'secretKey' => 'hulkstink',
        'scheme' => 'https',
        'basePath' => '/plugins/restapi/v1/',
        'host' => 'localhost',
        'port' => '9090',
    ],
    'guzzle'    => [
         //put here any options for Guzzle
    ]
]);

The only options required are those relating to the chosen authentication method., (*11)

Check the response

This Client follows the PSR-7 document, therefore any response is a ResponseInterface type:, (*12)

if ($response->getStatusCode() == 200) {
    echo "Oh, great.";
    var_dump(json_decode($response->getBody()));
} else {
    echo "HTTP ERROR " . $response->getStatusCode();
}

Users endpoint

//Create a new user
$response = $client->getUserModel()->createUser([
    "username" => "admin",
    "name" => "Administrator",
    "email" => "admin@example.com",
    "password" => "p4ssword",
    "properties" => [
        [
            "key" => "console.order",
            "value" => "session-summary=0"
        ]
    ]
]);

//Delete a user
$response = $client->getUserModel()->deleteUser('ironman');

//Ban a user
$response = $client->getUserModel()->lockoutUser('ironman');

//Unban a user
$response = $client->getUserModel()->unlockUser('ironman');

//Please read the UserModel class for a complete list of available methods.

Chat Rooms endpoint

//Create a chat room
$response = $client->getChatRoomModel()->createChatRoom([
    "roomName" => "global-1",
    "naturalName" => "global-1_test_hello",
    "description" => "Global chat room",
    "subject" => "Global chat room subject",
    "creationDate" => "2012-10-18T16:55:12.803+02:00",
    "modificationDate" => "2014-07-10T09:49:12.411+02:00",
    "maxUsers" => "0",
    "persistent" => "true",
    "publicRoom" => "true",
    "registrationEnabled" => "false",
    "canAnyoneDiscoverJID" => "true",
    "canOccupantsChangeSubject" => "false",
    "canOccupantsInvite" => "false",
    "canChangeNickname" => "false",
    "logEnabled" => "true",
    "loginRestrictedToNickname" => "true",
    "membersOnly" => "false",
    "moderated" => "false",
    "broadcastPresenceRoles" => [
        "moderator",
        "participant",
        "visitor"
    ],
    "owners" => [
       "owner@localhost"
    ],
    "admins" => [
       "admin@localhost"
    ],
    "members" => [
        "member@localhost"
    ],
    "outcasts" => [
        "outcast@localhost"
    ]
]);

//Retrieve a chat room
$response = $client->getChatRoomModel()->retrieveChatRoom('theavengers')

//Add a user with role to a chat room
use \Gnello\OpenFireRestAPI\Models\ChatRoomModel;
$response = $client->getChatRoomModel()->addUserWithRoleToChatRoom('theavengers', 'ironman', ChatRoomModel::ROLE_MEMBER);

//Delete a chat room
$response = $client->getChatRoomModel()->deleteChatRoom('theavengers');

//Please read the ChatRoomModel class for a complete list of available methods.

Groups endpoint

//Create a group
$response = $client->getGroupModel()->createGroup([
    "name" => "theavengers",
    "description" => "team of superheroes appearing in American comic books published by Marvel Comics",
]);

//Retrieve a group
$response = $client->getGroupModel()->retrieveGroup('theavengers')

//Delete a group
$response = $client->getGroupModel()->deleteGroup('theavengers');

//Please read the GroupModel class for a complete list of available methods.

Endpoints supported

All the endpoints are supported:, (*13)

Contact

  • gnello luca@gnello.com

The Versions

22/04 2017

dev-master

9999999-dev https://github.com/gnello/php-openfire-restapi

Manage OpenFire Server using Rest API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0
  • ext-curl *

 

The Development Requires

by Luca Agnello

chat openfire

22/04 2017

v2.0.1

2.0.1.0 https://github.com/gnello/php-openfire-restapi

Manage OpenFire Server using Rest API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0
  • ext-curl *

 

The Development Requires

by Luca Agnello

chat openfire

05/10 2016

v2.0.0

2.0.0.0 https://github.com/gnello/php-openfire-restapi

Manage OpenFire Server using Rest API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0
  • ext-curl *

 

by Luca Agnello

chat openfire