rocketchat 0.1.17 → 0.1.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +63 -8
- data/.travis.yml +3 -4
- data/CHANGELOG.md +41 -13
- data/Gemfile +2 -0
- data/README.md +6 -0
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/lib/rocket_chat/error.rb +6 -0
- data/lib/rocket_chat/gem_version.rb +3 -1
- data/lib/rocket_chat/im_summary.rb +56 -0
- data/lib/rocket_chat/info.rb +2 -0
- data/lib/rocket_chat/message.rb +2 -0
- data/lib/rocket_chat/messages/channel.rb +2 -0
- data/lib/rocket_chat/messages/chat.rb +2 -0
- data/lib/rocket_chat/messages/group.rb +34 -0
- data/lib/rocket_chat/messages/im.rb +101 -0
- data/lib/rocket_chat/messages/list_support.rb +2 -0
- data/lib/rocket_chat/messages/room.rb +24 -1
- data/lib/rocket_chat/messages/room_support.rb +2 -0
- data/lib/rocket_chat/messages/settings.rb +2 -0
- data/lib/rocket_chat/messages/user.rb +9 -4
- data/lib/rocket_chat/messages/user_support.rb +2 -0
- data/lib/rocket_chat/presence_status.rb +2 -0
- data/lib/rocket_chat/request_helper.rb +4 -2
- data/lib/rocket_chat/room.rb +2 -0
- data/lib/rocket_chat/server.rb +2 -0
- data/lib/rocket_chat/session.rb +6 -0
- data/lib/rocket_chat/token.rb +2 -0
- data/lib/rocket_chat/user.rb +17 -0
- data/lib/rocket_chat/util.rb +2 -0
- data/lib/rocketchat.rb +4 -0
- data/rocketchat.gemspec +9 -4
- metadata +47 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0414d925c282330700662c6a617328a2c91610c5969285da247c653a1b512133
|
4
|
+
data.tar.gz: db1fab6b741dd083488e1a1b60f36fff5130e5cff10ee88ed2847ef4853cee14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 002475521b99ee9dcc766622ed1630c08daf488ba68c0f10dd620b568882b022aace8e79a6f2419b8fa6d8780290ea2df442b1537118d97415ca759cb53254bc
|
7
|
+
data.tar.gz: 6f896d0c30470e16702567320ed083c63d6cce9325734295bfd553d710f8669bfd11148d79c590a89465ba06f0e7be870c02679ddab01d60858be9af6ab7b9bb
|
data/.rubocop.yml
CHANGED
@@ -1,24 +1,79 @@
|
|
1
|
-
require:
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rake
|
4
|
+
- rubocop-rspec
|
5
|
+
|
6
|
+
AllCops:
|
7
|
+
NewCops: enable
|
8
|
+
TargetRubyVersion: 2.5
|
9
|
+
|
10
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
11
|
+
Enabled: true
|
12
|
+
|
13
|
+
Layout/LineLength:
|
14
|
+
Max: 120
|
15
|
+
|
16
|
+
Layout/SpaceAroundMethodCallOperator:
|
17
|
+
Enabled: true
|
18
|
+
|
19
|
+
Lint/DeprecatedOpenSSLConstant:
|
20
|
+
Enabled: true
|
21
|
+
|
22
|
+
Lint/MixedRegexpCaptureTypes:
|
23
|
+
Enabled: true
|
24
|
+
|
25
|
+
Lint/RaiseException:
|
26
|
+
Enabled: true
|
27
|
+
|
28
|
+
Lint/StructNewOverride:
|
29
|
+
Enabled: true
|
2
30
|
|
3
31
|
Metrics/BlockLength:
|
4
32
|
Exclude:
|
5
33
|
- "**/*_spec.rb"
|
6
34
|
- "spec/shared/*.rb"
|
7
35
|
|
8
|
-
Metrics/LineLength:
|
9
|
-
Max: 120
|
10
|
-
|
11
36
|
Metrics/MethodLength:
|
12
37
|
Max: 15
|
13
38
|
Exclude:
|
14
39
|
- "**/*_spec.rb"
|
15
40
|
|
16
|
-
Style/NumericLiterals:
|
17
|
-
Exclude:
|
18
|
-
- "**/*_spec.rb"
|
19
|
-
|
20
41
|
RSpec/ExampleLength:
|
21
42
|
Max: 10
|
22
43
|
|
23
44
|
RSpec/MultipleExpectations:
|
24
45
|
Max: 5
|
46
|
+
|
47
|
+
RSpec/MultipleMemoizedHelpers:
|
48
|
+
Max: 15
|
49
|
+
|
50
|
+
RSpec/NestedGroups:
|
51
|
+
Max: 4
|
52
|
+
|
53
|
+
Style/ExponentialNotation:
|
54
|
+
Enabled: true
|
55
|
+
|
56
|
+
Style/HashEachMethods:
|
57
|
+
Enabled: true
|
58
|
+
|
59
|
+
Style/HashTransformKeys:
|
60
|
+
Enabled: true
|
61
|
+
|
62
|
+
Style/HashTransformValues:
|
63
|
+
Enabled: true
|
64
|
+
|
65
|
+
Style/NumericLiterals:
|
66
|
+
Exclude:
|
67
|
+
- "**/*_spec.rb"
|
68
|
+
|
69
|
+
Style/RedundantFetchBlock:
|
70
|
+
Enabled: true
|
71
|
+
|
72
|
+
Style/RedundantRegexpCharacterClass:
|
73
|
+
Enabled: true
|
74
|
+
|
75
|
+
Style/RedundantRegexpEscape:
|
76
|
+
Enabled: true
|
77
|
+
|
78
|
+
Style/SlicingWithRange:
|
79
|
+
Enabled: true
|
data/.travis.yml
CHANGED
@@ -5,11 +5,10 @@ env:
|
|
5
5
|
language: ruby
|
6
6
|
|
7
7
|
rvm:
|
8
|
-
- 2.2
|
9
|
-
- 2.3
|
10
|
-
- 2.4
|
11
8
|
- 2.5
|
12
9
|
- 2.6
|
10
|
+
- 2.7
|
11
|
+
- 3.0
|
13
12
|
|
14
13
|
before_install:
|
15
14
|
- gem update bundler
|
@@ -24,7 +23,7 @@ before_script:
|
|
24
23
|
- ./cc-test-reporter before-build
|
25
24
|
|
26
25
|
script:
|
27
|
-
- rubocop
|
26
|
+
- bundle exec rubocop
|
28
27
|
- bundle exec rake
|
29
28
|
|
30
29
|
after_script:
|
data/CHANGELOG.md
CHANGED
@@ -3,21 +3,40 @@
|
|
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
|
+
|
10
|
+
## [0.1.20](releases/tag/v0.1.20) - 2021-03-29
|
11
|
+
### Added
|
12
|
+
- [#34] Support for channels.members and groups.members ([@alinavancea][])
|
13
|
+
|
14
|
+
### Deprecation
|
15
|
+
- [#35] Drop Ruby 2.3 and 2.4 support ([@abrom][])
|
16
|
+
|
17
|
+
## [0.1.19](releases/tag/v0.1.19) - 2019-03-01
|
18
|
+
### Fixed
|
19
|
+
- Address CVE-2020-8130 - `rake` OS command injection vulnerability ([@abrom][])
|
20
|
+
|
21
|
+
## [0.1.18](releases/tag/v0.1.18) - 2018-01-05
|
22
|
+
### Added
|
23
|
+
- [#29] Support for im.create and im.counters ([@christianmoretti][])
|
24
|
+
|
6
25
|
## [0.1.17](releases/tag/v0.1.17) - 2019-01-05
|
7
26
|
### Deprecation
|
8
|
-
- Drop Ruby 2.1 from build matrix
|
27
|
+
- Drop Ruby 2.1 from build matrix ([@abrom][])
|
9
28
|
|
10
29
|
## [0.1.16](releases/tag/v0.1.16) - 2018-10-3
|
11
30
|
### Deprecation
|
12
|
-
- Drop Ruby 2.0 from build matrix
|
31
|
+
- Drop Ruby 2.0 from build matrix ([@abrom][])
|
13
32
|
|
14
33
|
### Added
|
15
34
|
- [#27] Support for channels.online ([@chrisstime][])
|
16
|
-
- `rubocop-rspec` dependency and fixed new lints
|
35
|
+
- [#28] `rubocop-rspec` dependency and fixed new lints ([@abrom][])
|
17
36
|
|
18
37
|
## [0.1.15](releases/tag/v0.1.15) - 2017-12-21
|
19
38
|
### Fixed
|
20
|
-
- Updated yard to resolve potential security vulnerability
|
39
|
+
- Updated yard to resolve potential security vulnerability ([@abrom][])
|
21
40
|
|
22
41
|
## [0.1.14](releases/tag/v0.1.14) - 2017-10-9
|
23
42
|
### Added
|
@@ -25,16 +44,16 @@
|
|
25
44
|
|
26
45
|
## [0.1.13](releases/tag/v0.1.13) - 2017-10-9
|
27
46
|
### Added
|
28
|
-
- Support for channel/group addAll endpoint
|
47
|
+
- Support for channel/group addAll endpoint ([@abrom][])
|
29
48
|
|
30
49
|
## [0.1.12](releases/tag/v0.1.12) - 2017-08-28
|
31
50
|
### Fixed
|
32
|
-
- GET request parameter encoding
|
51
|
+
- GET request parameter encoding ([@abrom][])
|
33
52
|
|
34
53
|
## [0.1.11](releases/tag/v0.1.11) - 2017-08-22
|
35
54
|
### Fixed
|
36
55
|
- [#15] Response parser improvements ([@reist][],[@danischreiber][])
|
37
|
-
- [#17] Fixed a missing dependency issue with `net/http`
|
56
|
+
- [#17] Fixed a missing dependency issue with `net/http` ([@abrom][])
|
38
57
|
|
39
58
|
### Added
|
40
59
|
- [#14] Add/remove moderator from room ([@danischreiber][])
|
@@ -45,11 +64,11 @@
|
|
45
64
|
|
46
65
|
## [0.1.9](releases/tag/v0.1.9) - 2017-07-16
|
47
66
|
### Fixed
|
48
|
-
- Update chat message handlers to support Ruby 2.0
|
67
|
+
- Update chat message handlers to support Ruby 2.0 ([@abrom][])
|
49
68
|
|
50
69
|
## [0.1.8](releases/tag/v0.1.8) - 2017-07-16
|
51
70
|
### Added
|
52
|
-
- Messages chat API support
|
71
|
+
- Messages chat API support ([@abrom][])
|
53
72
|
|
54
73
|
## [0.1.7](releases/tag/v0.1.7) - 2017-07-16
|
55
74
|
### Added
|
@@ -66,7 +85,7 @@
|
|
66
85
|
|
67
86
|
## [0.1.4](releases/tag/v0.1.4) - 2017-07-9
|
68
87
|
### Fixed
|
69
|
-
- Fixed a missing dependency issue with `uri`
|
88
|
+
- Fixed a missing dependency issue with `uri` ([@abrom][])
|
70
89
|
|
71
90
|
## [0.1.2](releases/tag/v0.1.2) - 2017-05-24
|
72
91
|
### Added
|
@@ -74,15 +93,15 @@
|
|
74
93
|
|
75
94
|
## [0.1.1](releases/tag/v0.1.1) - 2017-05-1
|
76
95
|
### Added
|
77
|
-
- Support for settings get/set endpoints
|
96
|
+
- Support for settings get/set endpoints ([@abrom][])
|
78
97
|
|
79
98
|
## [0.0.8](releases/tag/v0.0.8) - 2017-04-30
|
80
99
|
### Added
|
81
|
-
- Support for Users `getPresence` endpoint
|
100
|
+
- Support for Users `getPresence` endpoint ([@abrom][])
|
82
101
|
|
83
102
|
## [0.0.7](releases/tag/v0.0.7) - 2017-04-30
|
84
103
|
### Added
|
85
|
-
- Support for Users `list` endpoint
|
104
|
+
- Support for Users `list` endpoint ([@abrom][])
|
86
105
|
|
87
106
|
## [0.0.6](releases/tag/v0.0.6) - 2017-04-25
|
88
107
|
### Fixed
|
@@ -91,3 +110,12 @@
|
|
91
110
|
## [0.0.5](releases/tag/v0.0.5) - 2017-04-25
|
92
111
|
### Added
|
93
112
|
- [#1] Added Users `info` and `delete` endpoints ([@reist][])
|
113
|
+
|
114
|
+
[@abrom]: https://github.com/abrom
|
115
|
+
[@reist]: https://github.com/reist
|
116
|
+
[@danischreiber]: https://github.com/danischreiber
|
117
|
+
[@hardik127]: https://github.com/hardik127
|
118
|
+
[@chrisstime]: https://github.com/chrisstime
|
119
|
+
[@christianmoretti]: https://github.com/christianmoretti
|
120
|
+
[@alinavancea]: https://github.com/alinavancea
|
121
|
+
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -42,6 +42,10 @@ This gem supports the following Rocket.Chat APIs (Tested against Rocket.Chat v0.
|
|
42
42
|
* [/api/v1/chat.postMessage](docs/chat.md#postmessage)
|
43
43
|
* [/api/v1/chat.update](docs/chat.md#update)
|
44
44
|
|
45
|
+
#### IM
|
46
|
+
* [/api/v1/im.create](docs/im.md#create)
|
47
|
+
* [/api/v1/im.counters](docs/im.md#counters)
|
48
|
+
|
45
49
|
#### Channels
|
46
50
|
* /api/v1/channels.archive
|
47
51
|
* [/api/v1/channels.create](docs/channels.md#channelscreate)
|
@@ -64,6 +68,7 @@ This gem supports the following Rocket.Chat APIs (Tested against Rocket.Chat v0.
|
|
64
68
|
* [/api/v1/channels.setTopic](docs/channels.md#channelsset_attr)
|
65
69
|
* [/api/v1/channels.setType](docs/channels.md#channelsset_attr)
|
66
70
|
* [/api/v1/channels.online](docs/channels.md#channelsonline)
|
71
|
+
* [/api/v1/channels.members](docs/channels.md#channelsmembers)
|
67
72
|
* /api/v1/channels.unarchive
|
68
73
|
|
69
74
|
#### Groups
|
@@ -85,6 +90,7 @@ This gem supports the following Rocket.Chat APIs (Tested against Rocket.Chat v0.
|
|
85
90
|
* /api/v1/groups.setReadOnly
|
86
91
|
* /api/v1/groups.setTopic
|
87
92
|
* /api/v1/groups.setType
|
93
|
+
* [/api/v1/groups.members](docs/groups.md#groupsmembers)
|
88
94
|
* /api/v1/groups.unarchive
|
89
95
|
|
90
96
|
#### Users
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/lib/rocket_chat/error.rb
CHANGED
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RocketChat
|
4
|
+
#
|
5
|
+
# Rocket.Chat IM Summary
|
6
|
+
#
|
7
|
+
class ImSummary
|
8
|
+
# Raw info data
|
9
|
+
attr_reader :data
|
10
|
+
|
11
|
+
#
|
12
|
+
# @param [Hash] data Raw info data
|
13
|
+
#
|
14
|
+
def initialize(data)
|
15
|
+
@data = Util.stringify_hash_keys data
|
16
|
+
end
|
17
|
+
|
18
|
+
def joined
|
19
|
+
data['joined']
|
20
|
+
end
|
21
|
+
|
22
|
+
# Qty of members in the chat
|
23
|
+
def members
|
24
|
+
data['members']
|
25
|
+
end
|
26
|
+
|
27
|
+
# Qty of unread messages
|
28
|
+
def unreads
|
29
|
+
data['unreads']
|
30
|
+
end
|
31
|
+
|
32
|
+
# Timestamp
|
33
|
+
def unreads_from
|
34
|
+
data['unreadsFrom']
|
35
|
+
end
|
36
|
+
|
37
|
+
# Qty of messages in the chat
|
38
|
+
def msgs
|
39
|
+
data['msgs']
|
40
|
+
end
|
41
|
+
|
42
|
+
# Last message sent
|
43
|
+
def latest
|
44
|
+
data['latest']
|
45
|
+
end
|
46
|
+
|
47
|
+
# Qty of mentions
|
48
|
+
def user_mentions
|
49
|
+
data['userMentions']
|
50
|
+
end
|
51
|
+
|
52
|
+
def success
|
53
|
+
data['success']
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/rocket_chat/info.rb
CHANGED
data/lib/rocket_chat/message.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RocketChat
|
2
4
|
module Messages
|
3
5
|
#
|
@@ -55,6 +57,38 @@ module RocketChat
|
|
55
57
|
response['groups'].map { |hash| RocketChat::Room.new hash } if response['success']
|
56
58
|
end
|
57
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
|
+
|
58
92
|
# Keys for set_attr:
|
59
93
|
# * [String] description A room's description
|
60
94
|
# * [String] purpose Alias for description
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RocketChat
|
4
|
+
module Messages
|
5
|
+
#
|
6
|
+
# Rocket.Chat Direct messages
|
7
|
+
#
|
8
|
+
class Im
|
9
|
+
include ListSupport
|
10
|
+
|
11
|
+
#
|
12
|
+
# @param [Session] session Session
|
13
|
+
#
|
14
|
+
def initialize(session)
|
15
|
+
@session = session
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# im.create REST API
|
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
|
23
|
+
# @return [RocketChat::Room]
|
24
|
+
# @raise [HTTPError, StatusError]
|
25
|
+
#
|
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
|
+
|
36
|
+
response = session.request_json(
|
37
|
+
'/api/v1/im.create',
|
38
|
+
method: :post,
|
39
|
+
body: params
|
40
|
+
)
|
41
|
+
RocketChat::Room.new response['room']
|
42
|
+
end
|
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
|
+
|
78
|
+
#
|
79
|
+
# im.counters REST API
|
80
|
+
# @param [String] room_id Rocket.Chat roomId
|
81
|
+
# @param [String] username Rocket.Chat username
|
82
|
+
# @return [RocketChat::ImSummary]
|
83
|
+
# @raise [HTTPError, StatusError]
|
84
|
+
#
|
85
|
+
def counters(room_id:, username: nil)
|
86
|
+
response = session.request_json(
|
87
|
+
'/api/v1/im.counters',
|
88
|
+
body: {
|
89
|
+
roomId: room_id,
|
90
|
+
username: username
|
91
|
+
}
|
92
|
+
)
|
93
|
+
RocketChat::ImSummary.new response
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
attr_reader :session
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RocketChat
|
2
4
|
module Messages
|
3
5
|
#
|
@@ -9,9 +11,11 @@ module RocketChat
|
|
9
11
|
|
10
12
|
def self.inherited(subclass)
|
11
13
|
field = subclass.name.split('::')[-1].downcase
|
12
|
-
collection = field
|
14
|
+
collection = "#{field}s"
|
13
15
|
subclass.send(:define_singleton_method, :field) { field }
|
14
16
|
subclass.send(:define_singleton_method, :collection) { collection }
|
17
|
+
|
18
|
+
super
|
15
19
|
end
|
16
20
|
|
17
21
|
#
|
@@ -281,6 +285,25 @@ module RocketChat
|
|
281
285
|
)['success']
|
282
286
|
end
|
283
287
|
|
288
|
+
#
|
289
|
+
# *.members* REST API
|
290
|
+
# @param [String] room_id Rocket.Chat room id
|
291
|
+
# @param [String] name Rocket.Chat room name
|
292
|
+
# @param [Integer] offset Query offset
|
293
|
+
# @param [Integer] count Query count/limit
|
294
|
+
# @param [Hash] sort Query field sort hash. eg `{ msgs: 1, name: -1 }`
|
295
|
+
# @return [Users[]]
|
296
|
+
# @raise [HTTPError, StatusError]
|
297
|
+
#
|
298
|
+
def members(room_id: nil, name: nil, offset: nil, count: nil, sort: nil)
|
299
|
+
response = session.request_json(
|
300
|
+
self.class.api_path('members'),
|
301
|
+
body: room_params(room_id, name).merge(build_list_body(offset, count, sort, nil, nil))
|
302
|
+
)
|
303
|
+
|
304
|
+
response['members'].map { |hash| RocketChat::User.new hash } if response['success']
|
305
|
+
end
|
306
|
+
|
284
307
|
private
|
285
308
|
|
286
309
|
attr_reader :session
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RocketChat
|
2
4
|
module Messages
|
3
5
|
#
|
@@ -67,7 +69,7 @@ module RocketChat
|
|
67
69
|
method: :post,
|
68
70
|
body: {
|
69
71
|
userId: id,
|
70
|
-
data: user_option_hash(options, true)
|
72
|
+
data: user_option_hash(options, include_personal_fields: true)
|
71
73
|
}
|
72
74
|
)
|
73
75
|
RocketChat::User.new response['user']
|
@@ -112,13 +114,16 @@ module RocketChat
|
|
112
114
|
# users.info REST API
|
113
115
|
# @param [String] user_id Rocket.Chat user id
|
114
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
|
115
119
|
# @return [User]
|
116
120
|
# @raise [HTTPError, StatusError]
|
117
121
|
#
|
118
|
-
def info(user_id: nil, username: nil)
|
122
|
+
def info(user_id: nil, username: nil, include_rooms: false)
|
119
123
|
response = session.request_json(
|
120
124
|
'/api/v1/users.info',
|
121
|
-
body: user_params(user_id, username)
|
125
|
+
body: user_params(user_id, username)
|
126
|
+
.merge(include_rooms ? { fields: { userRooms: 1 }.to_json } : {}),
|
122
127
|
upstreamed_errors: ['error-invalid-user']
|
123
128
|
)
|
124
129
|
|
@@ -177,7 +182,7 @@ module RocketChat
|
|
177
182
|
|
178
183
|
attr_reader :session
|
179
184
|
|
180
|
-
def user_option_hash(options, include_personal_fields
|
185
|
+
def user_option_hash(options, include_personal_fields: false)
|
181
186
|
args = [options, :active, :roles, :join_default_channels, :require_password_change,
|
182
187
|
:send_welcome_email, :verified, :custom_fields]
|
183
188
|
args += %i[username email name password] if include_personal_fields
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'uri'
|
2
4
|
require 'openssl'
|
3
5
|
require 'net/http'
|
@@ -30,7 +32,7 @@ module RocketChat
|
|
30
32
|
check_response response, fail_unless_ok
|
31
33
|
|
32
34
|
response_json = parse_response(response.body)
|
33
|
-
options[:debug]
|
35
|
+
options[:debug]&.puts("Response: #{response_json.inspect}")
|
34
36
|
check_response_json response_json, upstreamed_errors
|
35
37
|
|
36
38
|
response_json
|
@@ -109,7 +111,7 @@ module RocketChat
|
|
109
111
|
add_body(req, body) if body
|
110
112
|
else
|
111
113
|
uri = path
|
112
|
-
uri +=
|
114
|
+
uri += "?#{body.map { |k, v| "#{k}=#{v}" }.join('&')}" if body
|
113
115
|
req = Net::HTTP::Get.new(uri, headers)
|
114
116
|
end
|
115
117
|
|
data/lib/rocket_chat/room.rb
CHANGED
data/lib/rocket_chat/server.rb
CHANGED
data/lib/rocket_chat/session.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RocketChat
|
2
4
|
#
|
3
5
|
# Rocket.Chat Session
|
@@ -58,6 +60,10 @@ module RocketChat
|
|
58
60
|
@chat ||= RocketChat::Messages::Chat.new(self)
|
59
61
|
end
|
60
62
|
|
63
|
+
def im
|
64
|
+
@im ||= RocketChat::Messages::Im.new(self)
|
65
|
+
end
|
66
|
+
|
61
67
|
#
|
62
68
|
# Settings messages proxy
|
63
69
|
# @return [Messages::Settings]
|
data/lib/rocket_chat/token.rb
CHANGED
data/lib/rocket_chat/user.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RocketChat
|
2
4
|
#
|
3
5
|
# Rocket.Chat User
|
@@ -68,6 +70,21 @@ module RocketChat
|
|
68
70
|
data['roles']
|
69
71
|
end
|
70
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
|
+
|
71
88
|
def inspect
|
72
89
|
format(
|
73
90
|
'#<%<class_name>s:0x%<object_id>p @id="%<id>s" @username="%<username>s" @active="%<active>s">',
|
data/lib/rocket_chat/util.rb
CHANGED
data/lib/rocketchat.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rocket_chat/gem_version'
|
2
4
|
|
3
5
|
require 'json'
|
@@ -16,6 +18,7 @@ require 'rocket_chat/messages/room'
|
|
16
18
|
require 'rocket_chat/messages/channel'
|
17
19
|
require 'rocket_chat/messages/group'
|
18
20
|
require 'rocket_chat/messages/chat'
|
21
|
+
require 'rocket_chat/messages/im'
|
19
22
|
|
20
23
|
require 'rocket_chat/server'
|
21
24
|
require 'rocket_chat/session'
|
@@ -25,3 +28,4 @@ require 'rocket_chat/presence_status'
|
|
25
28
|
require 'rocket_chat/room'
|
26
29
|
require 'rocket_chat/user'
|
27
30
|
require 'rocket_chat/message'
|
31
|
+
require 'rocket_chat/im_summary'
|
data/rocketchat.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
lib = File.expand_path('lib', __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
|
@@ -13,17 +15,20 @@ Gem::Specification.new do |spec|
|
|
13
15
|
spec.description = 'Rocket.Chat REST API v1 for Ruby'
|
14
16
|
spec.homepage = 'https://github.com/abrom/rocketchat-ruby'
|
15
17
|
spec.license = 'MIT'
|
18
|
+
spec.required_ruby_version = ['>= 2.5.0', '< 3.1.0']
|
16
19
|
|
17
20
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|docs)/}) }
|
18
21
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
22
|
spec.require_paths = ['lib']
|
20
23
|
|
21
24
|
spec.add_development_dependency 'bundler', ['>= 1.11', '< 3.0']
|
22
|
-
spec.add_development_dependency 'rake', '
|
25
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
23
26
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
24
|
-
spec.add_development_dependency 'rubocop', '~>
|
25
|
-
spec.add_development_dependency 'rubocop-
|
27
|
+
spec.add_development_dependency 'rubocop', '~> 1.12'
|
28
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.10'
|
29
|
+
spec.add_development_dependency 'rubocop-rake', '~> 0.5'
|
30
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.2'
|
26
31
|
spec.add_development_dependency 'simplecov', '~> 0.16'
|
27
|
-
spec.add_development_dependency 'webmock', '~>
|
32
|
+
spec.add_development_dependency 'webmock', '~> 3.12'
|
28
33
|
spec.add_development_dependency 'yard', '~> 0.9.11'
|
29
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rocketchat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- int512
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -35,16 +35,16 @@ dependencies:
|
|
35
35
|
name: rake
|
36
36
|
requirement: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
type: :development
|
42
42
|
prerelease: false
|
43
43
|
version_requirements: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 12.3.3
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rspec
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -65,28 +65,56 @@ dependencies:
|
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '1.12'
|
69
|
+
type: :development
|
70
|
+
prerelease: false
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.12'
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: rubocop-performance
|
78
|
+
requirement: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.10'
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.10'
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
name: rubocop-rake
|
92
|
+
requirement: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.5'
|
69
97
|
type: :development
|
70
98
|
prerelease: false
|
71
99
|
version_requirements: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
101
|
- - "~>"
|
74
102
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0.
|
103
|
+
version: '0.5'
|
76
104
|
- !ruby/object:Gem::Dependency
|
77
105
|
name: rubocop-rspec
|
78
106
|
requirement: !ruby/object:Gem::Requirement
|
79
107
|
requirements:
|
80
108
|
- - "~>"
|
81
109
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
110
|
+
version: '2.2'
|
83
111
|
type: :development
|
84
112
|
prerelease: false
|
85
113
|
version_requirements: !ruby/object:Gem::Requirement
|
86
114
|
requirements:
|
87
115
|
- - "~>"
|
88
116
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
117
|
+
version: '2.2'
|
90
118
|
- !ruby/object:Gem::Dependency
|
91
119
|
name: simplecov
|
92
120
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,14 +135,14 @@ dependencies:
|
|
107
135
|
requirements:
|
108
136
|
- - "~>"
|
109
137
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
138
|
+
version: '3.12'
|
111
139
|
type: :development
|
112
140
|
prerelease: false
|
113
141
|
version_requirements: !ruby/object:Gem::Requirement
|
114
142
|
requirements:
|
115
143
|
- - "~>"
|
116
144
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
145
|
+
version: '3.12'
|
118
146
|
- !ruby/object:Gem::Dependency
|
119
147
|
name: yard
|
120
148
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,11 +177,13 @@ files:
|
|
149
177
|
- bin/console
|
150
178
|
- lib/rocket_chat/error.rb
|
151
179
|
- lib/rocket_chat/gem_version.rb
|
180
|
+
- lib/rocket_chat/im_summary.rb
|
152
181
|
- lib/rocket_chat/info.rb
|
153
182
|
- lib/rocket_chat/message.rb
|
154
183
|
- lib/rocket_chat/messages/channel.rb
|
155
184
|
- lib/rocket_chat/messages/chat.rb
|
156
185
|
- lib/rocket_chat/messages/group.rb
|
186
|
+
- lib/rocket_chat/messages/im.rb
|
157
187
|
- lib/rocket_chat/messages/list_support.rb
|
158
188
|
- lib/rocket_chat/messages/room.rb
|
159
189
|
- lib/rocket_chat/messages/room_support.rb
|
@@ -182,15 +212,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
182
212
|
requirements:
|
183
213
|
- - ">="
|
184
214
|
- !ruby/object:Gem::Version
|
185
|
-
version:
|
215
|
+
version: 2.5.0
|
216
|
+
- - "<"
|
217
|
+
- !ruby/object:Gem::Version
|
218
|
+
version: 3.1.0
|
186
219
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
220
|
requirements:
|
188
221
|
- - ">="
|
189
222
|
- !ruby/object:Gem::Version
|
190
223
|
version: '0'
|
191
224
|
requirements: []
|
192
|
-
|
193
|
-
rubygems_version: 2.7.6
|
225
|
+
rubygems_version: 3.0.6
|
194
226
|
signing_key:
|
195
227
|
specification_version: 4
|
196
228
|
summary: Rocket.Chat REST API v1 for Ruby
|