2017 © Pedro Peláez
 

library rocket-chat-rest-client

Rocket Chat REST API client in PHP.

image

fab1en/rocket-chat-rest-client

Rocket Chat REST API client in PHP.

  • Wednesday, May 3, 2017
  • by Fabien
  • Repository
  • 4 Watchers
  • 20 Stars
  • 1,495 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 17 Forks
  • 9 Open issues
  • 2 Versions
  • 51 % Grown

The README.md

Rocket Chat REST API client in PHP

Use this client if you need to connect to Rocket Chat with a software written in PHP, such as WordPress or Drupal., (*1)

How to use

This Rocket Chat client is installed via Composer. To install, simply add it to your composer.json file:, (*2)

{
    "require": {
        "fab1en/rocket-chat-rest-client": "dev-master"
    }
}

And run composer to update your dependencies:, (*3)

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update

Then, import the autoload.php from your vendor folder., (*4)

After this, you have to define some constants to point to your Rocket Chat instance, (*5)

define('REST_API_ROOT', '/api/v1/');
define('ROCKET_CHAT_INSTANCE', 'https://my-rocket-chat-instance.example.org');

Finally, instance the classes you need:, (*6)

$api = new \RocketChat\Client();
echo $api->version(); echo "\n";

// login as the main admin user
$admin = new \RocketChat\User('my-admin-name', 'my-admin-password');
if( $admin->login() ) {
    echo "admin user logged in\n";
};
$admin->info();
echo "I'm {$admin->nickname} ({$admin->id}) "; echo "\n";

Manage user

// create a new user
$newuser = new \RocketChat\User('new_user_name', 'new_user_password', array(
    'nickname' => 'New user nickname',
    'email' => 'newuser@example.org',
));
if( !$newuser->login(false) ) {
    // actually create the user if it does not exist yet
  $newuser->create();
}
echo "user {$newuser->nickname} created ({$newuser->id})\n";

Post a message

// create a new channel
$channel = new \RocketChat\Channel( 'my_new_channel', array($newuser, $admin) );
$channel->create();
// post a message
$channel->postMessage('Hello world');

Credits

This REST client uses the excellent Httpful PHP library by Nate Good (github repo is here)., (*7)

The Versions

03/05 2017

dev-master

9999999-dev

Rocket Chat REST API client in PHP.

  Sources   Download

The Requires

 

06/04 2017

1.0

1.0.0.0

Rocket Chat REST API client in PHP.

  Sources   Download

The Requires