GithubHelp home page GithubHelp logo

php-openfire-restapi's Introduction

php-openfire-restapi

Latest Stable Version Total Downloads

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.

Please read the documentation for further information on using this application.

This client completely supports the >= 1.3.9 version of the REST API Plugin.

Dependencies

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

Installation

Composer

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

composer require gnello/php-openfire-restapi

Read more about how to install and use Composer here.

Usage

Instance and authentication

There are two ways of authentication:

  • 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.

Configuration

You can configure the Client with the following options:

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.

Check the response

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

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" => "[email protected]",
    "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:

Contact

php-openfire-restapi's People

Contributors

dependabot[bot] avatar gnello avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-openfire-restapi's Issues

Failed to install through Composer in Laravel

I am trying to add in laravel 8 project and got this error.

Problem 1 - Can only install one of: guzzlehttp/guzzle[6.5.x-dev, 7.1.1]. - Can only install one of: guzzlehttp/guzzle[7.1.1, 6.5.x-dev]. - Can only install one of: guzzlehttp/guzzle[6.5.x-dev, 7.1.1]. - gnello/php-openfire-restapi 3.0.0 requires guzzlehttp/guzzle ^6.2 -> satisfiable by guzzlehttp/guzzle[6.5.x-dev]. - Installation request for gnello/php-openfire-restapi ^3.0 -> satisfiable by gnello/php-openfire-restapi[3.0.0]. - Installation request for guzzlehttp/guzzle (locked at 7.1.1, required as ^7.0.1) -> satisfiable by guzzlehttp/guzzle[7.1.1].

Screenshot 2020-10-07 at 1 23 33 PM

Retrieving not existing chat rooms returns response == 1

$response = $api->ChatRooms()->retrieveChatRoom('room_' . $e->data->id);

In case the room does not exist it returns an object with default values, but roomName, naturalName and description are 'room_78' for example.
So to check the room exists I have to use workaround:
if ($response['response'] == 1 && $response['output']->roomName !== $response['output']->naturalName) {

Chat room related APIs not working.

$payload = new \Gnello\OpenFireRestAPI\Payload\ChatRoom();

$payload->setRoomName('myfirstchatroom');
$payload->setNaturalName('my_first_chat_room');
$payload->setDescription('This is my first chat room!');
$payload->setAdmins(array('admin'));
$payload->setOutcastGroups(array('outcast1','outcast2'));
$payload->setCanAnyoneDiscoverJID(false);
$payload->setCanOccupantsChangeSubject(false);
$payload->setPassword('12345');

$result = $api->ChatRooms()->createChatRoom(payload);

I found error:
Fatal error: Class 'Gnello\OpenFireRestAPI\Payload\ChatRoom' not found in /opt/lampp/htdocs/openfire/application/controllers/api/V1.php on line 40

i found chatroompayload.php file in payload but it has also a big error
Message: Undefined offset: 0

Filename: Payloads/AbstractPayload.php

Line Number: 28

I don't know what is the error.
Please find and fix the error.

Room not save into database

I have use following code for create chat room

$payload = $api->Payloads()->createChatRoomPayload();
$payload->setRoomName('test_1');
$payload->setNaturalName('est_1');
$payload->setDescription('This is my first chat room!');
$result = $api->ChatRooms()->createChatRoom($payload);

after get success message if I have check in admin console then it's show
but when I check it in my MYSQL database it's not added

after restart openfire server it's deleted

would you please guide me what I need to do?

Not able to create room

Hi,
I am not able to create the room and even I'm not able to add user in the openfire through the script
below I have added the response.

getRequest -- [{"url":"http://144.217.253.67:9009/plugins/restapi/v1/chatrooms?servicename=conference","headers":["Accept: application/json","Authorization: basic YWRtaW46aW50ZWxueHQyMDE3IQ==","Content-Type: application/json"],"method":"POST","postData":"{"roomName":"intellinects","naturalName":"12334545","description":"This is my first chat room!","persistent":true,"canAnyoneDiscoverJID":false,"canOccupantsChangeSubject":false,"broadcastPresenceRoles":{"broadcastPresenceRole":["moderator","participant","visitor"]},"admins":{"admin":["admin"]}}","response":false,"server_output":""}]

getCurlInfo -- {"url":"http://144.217.253.67:9009/plugins/restapi/v1/chatrooms?servicename=conference","content_type":null,"http_code":302,"header_size":325,"request_size":522,"filetime":-1,"ssl_verify_result":0,"redirect_count":0,"total_time":0.594,"namelookup_time":0,"connect_time":0.25,"pretransfer_time":0.25,"size_upload":295,"size_download":0,"speed_download":0,"speed_upload":496,"download_content_length":0,"upload_content_length":295,"starttransfer_time":0.594,"redirect_time":0,"redirect_url":"http://144.217.253.67:9009/login.jsp?url=%2Fplugins%2Frestapi%2Fv1%2Fchatrooms%3Fservicename%3Dconference","primary_ip":"144.217.253.67","certinfo":[],"primary_port":9009,"local_ip":"192.168.0.103","local_port":54040}

please help me.
Thanks!

Issue in printing the requests and connecting to openfire.

I tried connecting this way:
`<?php

include "vendor/autoload.php";

$api = new \Gnello\OpenFireRestAPI\API();

//Set the required config parameters
$api->Settings()->setSecret("YWRtaW46YWRtaW4");
$api->Settings()->setHost("localhost.localdomain ");
$api->Settings()->setServerName(" localhost.localdomain ");

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

$api->Settings()->setDebug(true);
$requests = \Gnello\OpenFireRestAPI\Debug\Request::getRequests();

var_dump($requests);

`

When I var_dump requests it shows empty,

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.