rocketchat 0.1.20 → 0.1.21

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5f446da6cb7e901ef27edc15d4294fdb1db3a7c6386c35aeec2acbf513a2246
4
- data.tar.gz: 19bda5415f803dd4a7cf7bc05ec2ec1fcf925d364e55068f0d7630d28e5da190
3
+ metadata.gz: 0414d925c282330700662c6a617328a2c91610c5969285da247c653a1b512133
4
+ data.tar.gz: db1fab6b741dd083488e1a1b60f36fff5130e5cff10ee88ed2847ef4853cee14
5
5
  SHA512:
6
- metadata.gz: d9c94588357cbeb32f18afe79b3439bded7fc8191b31627a440288642842d971119591cdf47e981836c7ea8b3d4ff76ed36040701b6c0fb24d33e9e7a349ef1a
7
- data.tar.gz: b14f92c34a2b9a6f17d4da573b793268b3c8f83590326b5faca1e1d6b0b4ebba5bbdea73c1ea5bcc406aa5a729988ac6eb230359f1fbbb8de23b2694b60bc652
6
+ metadata.gz: 002475521b99ee9dcc766622ed1630c08daf488ba68c0f10dd620b568882b022aace8e79a6f2419b8fa6d8780290ea2df442b1537118d97415ca759cb53254bc
7
+ data.tar.gz: 6f896d0c30470e16702567320ed083c63d6cce9325734295bfd553d710f8669bfd11148d79c590a89465ba06f0e7be870c02679ddab01d60858be9af6ab7b9bb
data/.rubocop.yml CHANGED
@@ -47,6 +47,9 @@ RSpec/MultipleExpectations:
47
47
  RSpec/MultipleMemoizedHelpers:
48
48
  Max: 15
49
49
 
50
+ RSpec/NestedGroups:
51
+ Max: 4
52
+
50
53
  Style/ExponentialNotation:
51
54
  Enabled: true
52
55
 
@@ -63,6 +66,9 @@ Style/NumericLiterals:
63
66
  Exclude:
64
67
  - "**/*_spec.rb"
65
68
 
69
+ Style/RedundantFetchBlock:
70
+ Enabled: true
71
+
66
72
  Style/RedundantRegexpCharacterClass:
67
73
  Enabled: true
68
74
 
data/CHANGELOG.md CHANGED
@@ -3,6 +3,10 @@
3
3
  ## Unreleased
4
4
  - None
5
5
 
6
+ ## [0.1.21](releases/tag/v0.1.21) - 2021-08-30
7
+ ### Added
8
+ - [#36] Improve support for various REST APIs ([@abrom][])
9
+
6
10
  ## [0.1.20](releases/tag/v0.1.20) - 2021-03-29
7
11
  ### Added
8
12
  - [#34] Support for channels.members and groups.members ([@alinavancea][])
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RocketChat
4
- VERSION = '0.1.20'
4
+ VERSION = '0.1.21'
5
5
  end
@@ -57,6 +57,38 @@ module RocketChat
57
57
  response['groups'].map { |hash| RocketChat::Room.new hash } if response['success']
58
58
  end
59
59
 
60
+ # groups.listAll REST API
61
+ # @param [Integer] offset Query offset
62
+ # @param [Integer] count Query count/limit
63
+ # @param [Hash] sort Query field sort hash. eg `{ msgs: 1, name: -1 }`
64
+ # @param [Hash] fields Query fields to return. eg `{ name: 1, ro: 0 }`
65
+ # @return [Room[]]
66
+ # @raise [HTTPError, StatusError]
67
+ #
68
+ def list_all(offset: nil, count: nil, sort: nil, fields: nil, query: nil)
69
+ response = session.request_json(
70
+ '/api/v1/groups.listAll',
71
+ body: build_list_body(offset, count, sort, fields, query)
72
+ )
73
+
74
+ response['groups'].map { |hash| RocketChat::Room.new hash } if response['success']
75
+ end
76
+
77
+ #
78
+ # groups.online REST API
79
+ # @param [String] room_id Rocket.Chat room id
80
+ # @return [Users[]]
81
+ # @raise [HTTPError, StatusError]
82
+ #
83
+ def online(room_id: nil, name: nil)
84
+ response = session.request_json(
85
+ '/api/v1/groups.online',
86
+ body: room_params(room_id, name)
87
+ )
88
+
89
+ response['online'].map { |hash| RocketChat::User.new hash } if response['success']
90
+ end
91
+
60
92
  # Keys for set_attr:
61
93
  # * [String] description A room's description
62
94
  # * [String] purpose Alias for description
@@ -6,6 +6,8 @@ module RocketChat
6
6
  # Rocket.Chat Direct messages
7
7
  #
8
8
  class Im
9
+ include ListSupport
10
+
9
11
  #
10
12
  # @param [Session] session Session
11
13
  #
@@ -16,18 +18,63 @@ module RocketChat
16
18
  #
17
19
  # im.create REST API
18
20
  # @param [String] username Rocket.Chat username
21
+ # @param [String[]] usernames Array of Rocket.Chat usernames
22
+ # @param [Boolean] exclude_self Flag indicating whether the authenticated user should be included in the group
19
23
  # @return [RocketChat::Room]
20
24
  # @raise [HTTPError, StatusError]
21
25
  #
22
- def create(username:)
26
+ def create(username: nil, usernames: nil, exclude_self: false)
27
+ params =
28
+ if exclude_self
29
+ { usernames: usernames.join(','), excludeSelf: true }
30
+ elsif usernames
31
+ { usernames: usernames.join(',') }
32
+ else
33
+ { username: username }
34
+ end
35
+
23
36
  response = session.request_json(
24
37
  '/api/v1/im.create',
25
38
  method: :post,
26
- body: { username: username }
39
+ body: params
27
40
  )
28
41
  RocketChat::Room.new response['room']
29
42
  end
30
43
 
44
+ #
45
+ # im.delete REST API
46
+ # @param [String] room_id Rocket.Chat direct message room ID
47
+ # @return [Boolean]
48
+ # @raise [HTTPError, StatusError]
49
+ #
50
+ def delete(room_id: nil)
51
+ session.request_json(
52
+ '/api/v1/im.delete',
53
+ method: :post,
54
+ body: { roomId: room_id },
55
+ upstreamed_errors: ['error-room-not-found']
56
+ )['success']
57
+ end
58
+
59
+ #
60
+ # im.list.everyone REST API
61
+ # @param [Integer] offset Query offset
62
+ # @param [Integer] count Query count/limit
63
+ # @param [Hash] sort Query field sort hash. eg `{ msgs: 1, name: -1 }`
64
+ # @param [Hash] fields Query fields to return. eg `{ name: 1, ro: 0 }`
65
+ # @param [Hash] query The query. `{ active: true, type: { '$in': ['name', 'general'] } }`
66
+ # @return [Room[]]
67
+ # @raise [HTTPError, StatusError]
68
+ #
69
+ def list_everyone(offset: nil, count: nil, sort: nil, fields: nil, query: nil)
70
+ response = session.request_json(
71
+ '/api/v1/im.list.everyone',
72
+ body: build_list_body(offset, count, sort, fields, query)
73
+ )
74
+
75
+ response['ims'].map { |hash| RocketChat::Room.new hash } if response['success']
76
+ end
77
+
31
78
  #
32
79
  # im.counters REST API
33
80
  # @param [String] room_id Rocket.Chat roomId
@@ -114,13 +114,16 @@ module RocketChat
114
114
  # users.info REST API
115
115
  # @param [String] user_id Rocket.Chat user id
116
116
  # @param [String] username Username
117
+ # @param [Boolean] include_rooms Whether to include rooms in the response.
118
+ # Requires calling user to have the `view-other-user-channels` permission
117
119
  # @return [User]
118
120
  # @raise [HTTPError, StatusError]
119
121
  #
120
- def info(user_id: nil, username: nil)
122
+ def info(user_id: nil, username: nil, include_rooms: false)
121
123
  response = session.request_json(
122
124
  '/api/v1/users.info',
123
- body: user_params(user_id, username),
125
+ body: user_params(user_id, username)
126
+ .merge(include_rooms ? { fields: { userRooms: 1 }.to_json } : {}),
124
127
  upstreamed_errors: ['error-invalid-user']
125
128
  )
126
129
 
@@ -70,6 +70,21 @@ module RocketChat
70
70
  data['roles']
71
71
  end
72
72
 
73
+ # User rooms
74
+ def rooms
75
+ return [] unless data['rooms'].is_a? Array
76
+
77
+ data['rooms'].map do |hash|
78
+ # the users.info API returns the rooms data with the subscription ID as `_id` and room ID as `rid`
79
+ if hash['rid']
80
+ hash['subscription_id'] = hash['_id']
81
+ hash['_id'] = hash['rid']
82
+ end
83
+
84
+ RocketChat::Room.new hash
85
+ end
86
+ end
87
+
73
88
  def inspect
74
89
  format(
75
90
  '#<%<class_name>s:0x%<object_id>p @id="%<id>s" @username="%<username>s" @active="%<active>s">',
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rocketchat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.20
4
+ version: 0.1.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - int512
8
8
  - abrom
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-03-29 00:00:00.000000000 Z
12
+ date: 2021-08-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -204,7 +204,7 @@ homepage: https://github.com/abrom/rocketchat-ruby
204
204
  licenses:
205
205
  - MIT
206
206
  metadata: {}
207
- post_install_message:
207
+ post_install_message:
208
208
  rdoc_options: []
209
209
  require_paths:
210
210
  - lib
@@ -222,8 +222,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
222
  - !ruby/object:Gem::Version
223
223
  version: '0'
224
224
  requirements: []
225
- rubygems_version: 3.2.3
226
- signing_key:
225
+ rubygems_version: 3.0.6
226
+ signing_key:
227
227
  specification_version: 4
228
228
  summary: Rocket.Chat REST API v1 for Ruby
229
229
  test_files: []