diff --git a/README.md b/README.md index 7e0230d..e8364eb 100644 --- a/README.md +++ b/README.md @@ -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"; diff --git a/composer.json b/composer.json index 7ee4ca8..9e25e0b 100644 --- a/composer.json +++ b/composer.json @@ -4,5 +4,8 @@ "autoload": { "classmap": ["src/"] }, - "minimum-stability": "stable" + "minimum-stability": "stable", + "require": { + "nategood/httpful": "*" + } } diff --git a/src/RocketChatChannel.php b/src/RocketChatChannel.php index 75d2938..a7454d5 100644 --- a/src/RocketChatChannel.php +++ b/src/RocketChatChannel.php @@ -1,7 +1,7 @@ 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; + } + } + } diff --git a/src/RocketChatClient.php b/src/RocketChatClient.php index 4f853bd..f619ff0 100644 --- a/src/RocketChatClient.php +++ b/src/RocketChatClient.php @@ -1,7 +1,7 @@ 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; } @@ -41,7 +41,7 @@ public function me() { return false; } } - + /** * List all of the users and their information. * diff --git a/src/RocketChatGroup.php b/src/RocketChatGroup.php index 4079e5a..2ef13b6 100644 --- a/src/RocketChatGroup.php +++ b/src/RocketChatGroup.php @@ -1,7 +1,7 @@ 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; + } + } + } diff --git a/src/RocketChatSettings.php b/src/RocketChatSettings.php index 21deea4..cda4a5a 100644 --- a/src/RocketChatSettings.php +++ b/src/RocketChatSettings.php @@ -1,7 +1,7 @@ $value){ $check_val = $this->get($id); - + if(is_object($value) && is_object($check_val) && $value == $check_val) { // object comparison continue; diff --git a/src/RocketChatUser.php b/src/RocketChatUser.php index 0f24053..fd21dae 100644 --- a/src/RocketChatUser.php +++ b/src/RocketChatUser.php @@ -1,7 +1,7 @@ api . 'users.create' ) - ->body(array( + ->body(array( 'name' => $this->nickname, 'email' => $this->email, 'username' => $this->username, diff --git a/src/lib/httpful.phar b/src/lib/httpful.phar deleted file mode 100644 index 87fb392..0000000 Binary files a/src/lib/httpful.phar and /dev/null differ