Skip to content

Commit

Permalink
Bumped to v0.0.7
Browse files Browse the repository at this point in the history
Implemented users.list
  • Loading branch information
abrom committed Apr 29, 2017
1 parent 37b23fd commit 63b58af
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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', '[email protected]', 'New User', '123456',
user = session.users.create('new_username', '[email protected]', 'New User', '123456',
active: true, send_welcome_email: false)
```

Expand All @@ -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: '[email protected]',
name: 'Updated Name',
roles: ['user', 'moderator']
Expand All @@ -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: '[email protected]' })
```


To set a user's avatar:
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/rocket_chat/gem_version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RocketChat
VERSION = '0.0.6'.freeze
VERSION = '0.0.7'.freeze
end
26 changes: 26 additions & 0 deletions lib/rocket_chat/messages/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 63b58af

Please sign in to comment.