Skip to content

Commit

Permalink
Merge pull request #5 from alekseykuleshov/feature/update-readme/kule…
Browse files Browse the repository at this point in the history
…shov

Update README, move httpful into dependencies, add "invite" for groups and channels
  • Loading branch information
Fab1en authored Apr 6, 2017
2 parents e530ecf + 9e0b410 commit 097b148
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 20 deletions.
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,32 @@ in PHP, such as WordPress or Drupal.

## How to use

First, you have to define some constants to point to your Rocket Chat instance
This Rocket Chat client is installed via [Composer](http://getcomposer.org/). To install, simply add it
to your `composer.json` file:

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

And run composer to update your dependencies:

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

Then, import the `autoload.php` from your `vendor` folder.

After this, you have to define some constants to point to your Rocket Chat instance

```php
define('REST_API_ROOT', '/api/v1/');
define('ROCKET_CHAT_INSTANCE', 'https://my-rocket-chat-instance.example.org');
```
Then, import the files you need (TODO : implement autoloading)
```php
require_once 'src/RocketChatClient.php';
require_once 'src/RocketChatUser.php';
require_once 'src/RocketChatGroup.php';
require_once 'src/RocketChatChannel.php';
require_once 'src/RocketChatSettings.php';
```
Finaly, instance the classes you need :

Finally, instance the classes you need:
```php
$api = new \RocketChat\Client();
echo $api->version(); echo "\n";
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
"autoload": {
"classmap": ["src/"]
},
"minimum-stability": "stable"
"minimum-stability": "stable",
"require": {
"nategood/httpful": "*"
}
}
21 changes: 20 additions & 1 deletion src/RocketChatChannel.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

namespace RocketChat;
require_once 'lib/httpful.phar';

use Httpful\Request;
use RocketChat\Client;

Expand Down Expand Up @@ -128,5 +128,24 @@ public function kick( $user ){
}
}

/**
* Adds user to channel.
*/
public function invite( $user ) {

$userId = is_string($user) ? $user : $user->id;

$response = Request::post( $this->api . 'channels.invite' )
->body(array('roomId' => $this->id, 'userId' => $userId))
->send();

if( $response->code == 200 && isset($response->body->success) && $response->body->success == true ) {
return true;
} else {
echo( $response->body->error . "\n" );
return false;
}
}

}

6 changes: 3 additions & 3 deletions src/RocketChatClient.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

namespace RocketChat;
require_once 'lib/httpful.phar';

use Httpful\Request;

class Client{
Expand Down Expand Up @@ -32,7 +32,7 @@ public function version() {
public function me() {
$response = Request::get( $this->api . 'me' )->send();

if( $response->body->status != 'error' ) {
if( $response->body->status != 'error' ) {
if( isset($response->body->success) && $response->body->success == true ) {
return $response->body;
}
Expand All @@ -41,7 +41,7 @@ public function me() {
return false;
}
}

/**
* List all of the users and their information.
*
Expand Down
21 changes: 20 additions & 1 deletion src/RocketChatGroup.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

namespace RocketChat;
require_once 'lib/httpful.phar';

use Httpful\Request;
use RocketChat\Client;

Expand Down Expand Up @@ -128,5 +128,24 @@ public function kick( $user ){
}
}

/**
* Adds user to the private group.
*/
public function invite( $user ) {

$userId = is_string($user) ? $user : $user->id;

$response = Request::post( $this->api . 'groups.invite' )
->body(array('roomId' => $this->id, 'userId' => $userId))
->send();

if( $response->code == 200 && isset($response->body->success) && $response->body->success == true ) {
return true;
} else {
echo( $response->body->error . "\n" );
return false;
}
}

}

4 changes: 2 additions & 2 deletions src/RocketChatSettings.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

namespace RocketChat;
require_once 'lib/httpful.phar';

use Httpful\Request;
use RocketChat\Client;

Expand Down Expand Up @@ -65,7 +65,7 @@ public function check(){

foreach($settings as $id => $value){
$check_val = $this->get($id);

if(is_object($value) && is_object($check_val) && $value == $check_val) {
// object comparison
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/RocketChatUser.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

namespace RocketChat;
require_once 'lib/httpful.phar';

use Httpful\Request;
use RocketChat\Client;

Expand Down Expand Up @@ -70,7 +70,7 @@ public function info() {
*/
public function create() {
$response = Request::post( $this->api . 'users.create' )
->body(array(
->body(array(
'name' => $this->nickname,
'email' => $this->email,
'username' => $this->username,
Expand Down
Binary file removed src/lib/httpful.phar
Binary file not shown.

0 comments on commit 097b148

Please sign in to comment.