diff --git a/README.md b/README.md index a69b679..2a00d12 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ require 'rocketchat' rocket_server = RocketChat::Server.new('http://your.server.address/') session = rocket_server.login('username', 'password') -session.users.create('new_username', 'user@example.com', 'New User', '123456', +user = session.users.create('new_username', 'user@example.com', 'New User', '123456', active: true, send_welcome_email: false) ``` @@ -91,7 +91,7 @@ require 'rocketchat' rocket_server = RocketChat::Server.new('http://your.server.address/') session = rocket_server.login('username', 'password') -session.users.update('LAjzCDLqggCT7B82M', +user = session.users.update('LAjzCDLqggCT7B82M', email: 'updated@example.com', name: 'Updated Name', roles: ['user', 'moderator'] @@ -110,12 +110,23 @@ require 'rocketchat' rocket_server = RocketChat::Server.new('http://your.server.address/') session = rocket_server.login('username', 'password') -session.users.info(username: 'some_username') +user = session.users.info(username: 'some_username') ``` Either user_id (RocketChat's ID) or username can be used. -Deleting a user can be done with the same options. + +To delete a user, the same options as an info request can be used (`user_id` or `username`). + +To search for (list) users: + +```ruby +require 'rocketchat' + +rocket_server = RocketChat::Server.new('http://your.server.address/') +session = rocket_server.login('username', 'password') +users = session.users.list(query: { email: 'foo@example.com' }) +``` To set a user's avatar: @@ -125,7 +136,7 @@ require 'rocketchat' rocket_server = RocketChat::Server.new('http://your.server.address/') session = rocket_server.login('username', 'password') -session.users.set_avatar('http://image_url') +success = session.users.set_avatar('http://image_url') ``` There is an optional parameter user_id, that works if the setting user is allowed to set other's avatar. diff --git a/lib/rocket_chat/gem_version.rb b/lib/rocket_chat/gem_version.rb index e0161c3..fd9a67f 100644 --- a/lib/rocket_chat/gem_version.rb +++ b/lib/rocket_chat/gem_version.rb @@ -1,3 +1,3 @@ module RocketChat - VERSION = '0.0.6'.freeze + VERSION = '0.0.7'.freeze end diff --git a/lib/rocket_chat/messages/user.rb b/lib/rocket_chat/messages/user.rb index 3a0c3f6..0a25e4a 100644 --- a/lib/rocket_chat/messages/user.rb +++ b/lib/rocket_chat/messages/user.rb @@ -70,6 +70,32 @@ def delete(user_id: nil, username: nil) )['success'] end + # + # users.list REST API + # @param [Integer] offset Query offset + # @param [Integer] count Query count/limit + # @param [Hash] sort Query field sort hash. eg `{ active: 1, email: -1 }` + # @param [Hash] fields Query fields to return. eg `{ name: 1, email: 0 }` + # @param [Hash] query The query. `{ active: true, type: { $in: ['user', 'bot'] } }` + # @return [User[]] + # @raise [HTTPError, StatusError] + # + def list(offset: nil, count: nil, sort: nil, fields: nil, query: nil) + body = {} + body[:offset] = offset.to_i if offset.is_a? Integer + body[:count] = count.to_i if count.is_a? Integer + body[:sort] = sort.to_json if sort.is_a? Hash + body[:fields] = fields.to_json if fields.is_a? Hash + body[:query] = query.to_json if query.is_a? Hash + + response = session.request_json( + '/api/v1/users.list', + body: body + ) + + response['users'].map { |hash| RocketChat::User.new hash } if response['success'] + end + # # users.info REST API # @param [String] user_id Rocket.Chat user id