From 972f06fb0ec77244402c69f8087fda4704c6892b Mon Sep 17 00:00:00 2001 From: Andrew Bromwich Date: Fri, 8 Sep 2017 15:26:13 +1000 Subject: [PATCH] Version bump to v0.1.13 Added support for channel/group addAll endpoint --- README.md | 10 ++++++++ docs/channels.md | 44 ++++++++++++++++++++++++++++++++ docs/groups.md | 44 ++++++++++++++++++++++++++++++++ lib/rocket_chat/gem_version.rb | 2 +- lib/rocket_chat/messages/room.rb | 31 ++++++++++++++++++++-- 5 files changed, 128 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 49197ad..a936608 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,11 @@ This gem supports the following Rocket.Chat APIs (Tested against Rocket.Chat v0. * /api/v1/channels.archive * [/api/v1/channels.create](docs/channels.md#channelscreate) * [/api/v1/channels.delete](docs/channels.md#channelsdelete) +* [/api/v1/channels.addAll](docs/channels.md#channelsaddall) +* [/api/v1/channels.addOwner](docs/channels.md#channelsaddowner) +* [/api/v1/channels.removeOwner](docs/channels.md#channelsremoveowner) +* [/api/v1/channels.addModerator](docs/channels.md#channelsaddmoderator) +* [/api/v1/channels.removeModerator](docs/channels.md#channelsremovemoderator) * [/api/v1/channels.info](docs/channels.md#channelsinfo) * [/api/v1/channels.invite](docs/channels.md#channelsinvite) * [/api/v1/channels.join](docs/channels.md#channelsjoin) @@ -63,6 +68,11 @@ This gem supports the following Rocket.Chat APIs (Tested against Rocket.Chat v0. * /api/v1/groups.archive * /api/v1/groups.create * /api/v1/groups.delete +* [/api/v1/groups.addAll](docs/groups.md#groupsaddall) +* [/api/v1/groups.addOwner](docs/groups.md#groupsaddowner) +* [/api/v1/groups.removeOwner](docs/groups.md#groupsremoveowner) +* [/api/v1/groups.addModerator](docs/groups.md#groupsaddmoderator) +* [/api/v1/groups.removeModerator](docs/groups.md#groupsremovemoderator) * /api/v1/groups.info * /api/v1/groups.invite * /api/v1/groups.leave diff --git a/docs/channels.md b/docs/channels.md index e38222e..de704d9 100644 --- a/docs/channels.md +++ b/docs/channels.md @@ -36,6 +36,50 @@ Either room_id (RocketChat's ID) or name can be used. To delete a channel, the same options as an info request can be used (`room_id` or `name`). +#### channels.addAll + +```ruby +require 'rocketchat' + +rocket_server = RocketChat::Server.new('http://your.server.address/') +session = rocket_server.login('username', 'password') +success = session.channels.add_all(room_id: 'ByehQjC44FwMeiLbX') +``` + +Optional parameter for add_all is `active_users_only` (default false) + +_N.B. the addAll API endpoint requires the calling user to have the `admin` role_ + + +#### channels.addOwner + +```ruby +require 'rocketchat' + +rocket_server = RocketChat::Server.new('http://your.server.address/') +session = rocket_server.login('username', 'password') +success = session.channels.add_owner(name: 'some_channelname', username: 'some_username') +``` + +Either room_id (RocketChat's ID) or name can be used. +The same applies to user_id and username. + + +#### channels.removeOwner + +To remove an owner from a channel, the same options as an `add_owner` request can be used. + + +#### channels.addModerator + +To add a moderator to a channel, the same options as an `add_owner` request can be used. + + +#### channels.removeModerator + +To remove a moderator from a channel, the same options as an `add_owner` request can be used. + + #### channels.invite ```ruby diff --git a/docs/groups.md b/docs/groups.md index 2ed9c38..cb8ac09 100644 --- a/docs/groups.md +++ b/docs/groups.md @@ -13,3 +13,47 @@ rocket_server = RocketChat::Server.new('http://your.server.address/') session = rocket_server.login('username', 'password') groups = session.groups.list(offset: 40) ``` + + +#### groups.addAll + +```ruby +require 'rocketchat' + +rocket_server = RocketChat::Server.new('http://your.server.address/') +session = rocket_server.login('username', 'password') +success = session.groups.add_all(room_id: 'ByehQjC44FwMeiLbX') +``` + +Optional parameter for add_all is `active_users_only` (default false) + +_N.B. the addAll API endpoint requires the calling user to have the `admin` role_ + + +#### groups.addOwner + +```ruby +require 'rocketchat' + +rocket_server = RocketChat::Server.new('http://your.server.address/') +session = rocket_server.login('username', 'password') +success = session.groups.add_owner(name: 'some_groupname', username: 'some_username') +``` + +Either room_id (RocketChat's ID) or name can be used. +The same applies to user_id and username. + + +#### groups.removeOwner + +To remove an owner from a group, the same options as an `add_owner` request can be used. + + +#### groups.addModerator + +To add a moderator to a group, the same options as an `add_owner` request can be used. + + +#### groups.removeModerator + +To remove a moderator from a group, the same options as an `add_owner` request can be used. diff --git a/lib/rocket_chat/gem_version.rb b/lib/rocket_chat/gem_version.rb index eb11a4c..d22b8ab 100644 --- a/lib/rocket_chat/gem_version.rb +++ b/lib/rocket_chat/gem_version.rb @@ -1,3 +1,3 @@ module RocketChat - VERSION = '0.1.12'.freeze + VERSION = '0.1.13'.freeze end diff --git a/lib/rocket_chat/messages/room.rb b/lib/rocket_chat/messages/room.rb index 0cb5df5..24aa15d 100644 --- a/lib/rocket_chat/messages/room.rb +++ b/lib/rocket_chat/messages/room.rb @@ -60,10 +60,29 @@ def delete(room_id: nil, name: nil) )['success'] end + # + # *.addAll REST API + # @param [String] room_id Rocket.Chat room id + # @param [String] name Rocket.Chat room name (coming soon) + # @param [String] active_users_only Add active users only + # @return [Boolean] + # @raise [HTTPError, StatusError] + # + def add_all(room_id: nil, name: nil, active_users_only: false) + session.request_json( + self.class.api_path('addAll'), + method: :post, + body: room_params(room_id, name) + .merge(activeUsersOnly: active_users_only) + )['success'] + end + # # *.add_owner REST API # @param [String] room_id Rocket.Chat room id + # @param [String] name Rocket.Chat room name (coming soon) # @param [String] user_id Rocket.Chat user id + # @param [String] username Rocket.Chat username # @return [Boolean] # @raise [HTTPError, StatusError] # @@ -79,7 +98,9 @@ def add_owner(room_id: nil, name: nil, user_id: nil, username: nil) # # *.remove_owner REST API # @param [String] room_id Rocket.Chat room id + # @param [String] name Rocket.Chat room name (coming soon) # @param [String] user_id Rocket.Chat user id + # @param [String] username Rocket.Chat username # @return [Boolean] # @raise [HTTPError, StatusError] # @@ -95,7 +116,9 @@ def remove_owner(room_id: nil, name: nil, user_id: nil, username: nil) # # *.add_moderator REST API # @param [String] room_id Rocket.Chat room id + # @param [String] name Rocket.Chat room name (coming soon) # @param [String] user_id Rocket.Chat user id + # @param [String] username Rocket.Chat username # @return [Boolean] # @raise [HTTPError, StatusError] # @@ -111,7 +134,9 @@ def add_moderator(room_id: nil, name: nil, user_id: nil, username: nil) # # *.remove_moderator REST API # @param [String] room_id Rocket.Chat room id + # @param [String] name Rocket.Chat room name (coming soon) # @param [String] user_id Rocket.Chat user id + # @param [String] username Rocket.Chat username # @return [Boolean] # @raise [HTTPError, StatusError] # @@ -146,7 +171,7 @@ def info(room_id: nil, name: nil) # @param [String] room_id Rocket.Chat room id # @param [String] name Rocket.Chat room name (coming soon) # @param [String] user_id Rocket.Chat user id - # @param [String] username Username + # @param [String] username Rocket.Chat username # @return [Boolean] # @raise [HTTPError, StatusError] # @@ -162,6 +187,7 @@ def invite(room_id: nil, name: nil, user_id: nil, username: nil) # # *.archive REST API # @param [String] room_id Rocket.Chat room id + # @param [String] name Rocket.Chat room name (coming soon) # @return [Boolean] # @raise [HTTPError, StatusError] # @@ -176,6 +202,7 @@ def archive(room_id: nil, name: nil) # # *.unarchive REST API # @param [String] room_id Rocket.Chat room id + # @param [String] name Rocket.Chat room name (coming soon) # @return [Boolean] # @raise [HTTPError, StatusError] # @@ -220,7 +247,7 @@ def rename(room_id, new_name) # # *.set* REST API # @param [String] room_id Rocket.Chat room id - # @param [String] new_name New room name + # @param [String] name Rocket.Chat room name (coming soon) # @param [Hash] setting Single key-value # @return [Boolean] # @raise [ArgumentError, HTTPError, StatusError]