rocketchat 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/README.md +10 -0
- data/lib/rocket_chat/gem_version.rb +1 -1
- data/lib/rocket_chat/message.rb +72 -0
- data/lib/rocket_chat/messages/chat.rb +94 -0
- data/lib/rocket_chat/messages/room.rb +1 -10
- data/lib/rocket_chat/messages/room_support.rb +18 -0
- data/lib/rocket_chat/session.rb +4 -0
- data/lib/rocket_chat/util.rb +8 -1
- data/lib/rocketchat.rb +4 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21b04d366533b1fbb66982a06d1d62a7e36b6cf3
|
4
|
+
data.tar.gz: 0461e4015cad44bba749c51b75cba313d277b765
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e398ff7c92a611a85dcf154a2b62ac3e97d51fdee28bccfd6286f235c689022dbe90973d21133bb6d2a02ef5feca0b8f65ce3c431f61af7c507d1c51b4517ce
|
7
|
+
data.tar.gz: b15f9cf6e41c60c39f4c58f0328766164c41899ae74cb07b204af6c7e565627d1b32801d80036c1edf48894be73954621ce7aa37175776063fbd10e45b494037
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -35,7 +35,14 @@ This gem supports the following Rocket.Chat APIs (Tested against Rocket.Chat v0.
|
|
35
35
|
* [/api/v1/logout](#authentication)
|
36
36
|
* /api/v1/me
|
37
37
|
|
38
|
+
#### Chat
|
39
|
+
* /api/v1/chat.delete
|
40
|
+
* /api/v1/chat.getMessage
|
41
|
+
* /api/v1/chat.postMessage
|
42
|
+
* /api/v1/chat.update
|
43
|
+
|
38
44
|
#### Channels
|
45
|
+
* /api/v1/channels.archive
|
39
46
|
* [/api/v1/channels.create](docs/channels.md#channelscreate)
|
40
47
|
* [/api/v1/channels.delete](docs/channels.md#channelsdelete)
|
41
48
|
* [/api/v1/channels.info](docs/channels.md#channelsinfo)
|
@@ -50,8 +57,10 @@ This gem supports the following Rocket.Chat APIs (Tested against Rocket.Chat v0.
|
|
50
57
|
* [/api/v1/channels.setReadOnly](docs/channels.md#channelsset_attr)
|
51
58
|
* [/api/v1/channels.setTopic](docs/channels.md#channelsset_attr)
|
52
59
|
* [/api/v1/channels.setType](docs/channels.md#channelsset_attr)
|
60
|
+
* /api/v1/channels.unarchive
|
53
61
|
|
54
62
|
#### Groups
|
63
|
+
* /api/v1/groups.archive
|
55
64
|
* /api/v1/groups.create
|
56
65
|
* /api/v1/groups.delete
|
57
66
|
* /api/v1/groups.info
|
@@ -64,6 +73,7 @@ This gem supports the following Rocket.Chat APIs (Tested against Rocket.Chat v0.
|
|
64
73
|
* /api/v1/groups.setReadOnly
|
65
74
|
* /api/v1/groups.setTopic
|
66
75
|
* /api/v1/groups.setType
|
76
|
+
* /api/v1/groups.unarchive
|
67
77
|
|
68
78
|
#### Users
|
69
79
|
* [/api/v1/users.create](docs/users.md#userscreate)
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module RocketChat
|
2
|
+
#
|
3
|
+
# Rocket.Chat Message
|
4
|
+
#
|
5
|
+
class Message
|
6
|
+
# Raw user data
|
7
|
+
attr_reader :data
|
8
|
+
|
9
|
+
#
|
10
|
+
# @param [Hash] data Raw message data
|
11
|
+
#
|
12
|
+
def initialize(data)
|
13
|
+
@data = Util.stringify_hash_keys data
|
14
|
+
end
|
15
|
+
|
16
|
+
# Message ID
|
17
|
+
def id
|
18
|
+
data['_id']
|
19
|
+
end
|
20
|
+
|
21
|
+
# Timestamp
|
22
|
+
def timestamp
|
23
|
+
DateTime.parse data['ts']
|
24
|
+
end
|
25
|
+
|
26
|
+
# Updated at
|
27
|
+
def updated_at
|
28
|
+
DateTime.parse data['_updatedAt']
|
29
|
+
end
|
30
|
+
|
31
|
+
# Room ID
|
32
|
+
def room_id
|
33
|
+
data['rid']
|
34
|
+
end
|
35
|
+
|
36
|
+
# User
|
37
|
+
def user
|
38
|
+
User.new data['u']
|
39
|
+
end
|
40
|
+
|
41
|
+
# Message
|
42
|
+
def message
|
43
|
+
data['msg']
|
44
|
+
end
|
45
|
+
|
46
|
+
# Alias
|
47
|
+
def alias
|
48
|
+
data['alias']
|
49
|
+
end
|
50
|
+
|
51
|
+
# Parse URLs
|
52
|
+
def parse_urls
|
53
|
+
data['parseUrls']
|
54
|
+
end
|
55
|
+
|
56
|
+
# Groupable
|
57
|
+
def groupable
|
58
|
+
data['groupable']
|
59
|
+
end
|
60
|
+
|
61
|
+
def inspect
|
62
|
+
format(
|
63
|
+
'#<%s:0x%p @id="%s" @room="%s" @msg="%s">',
|
64
|
+
self.class.name,
|
65
|
+
object_id,
|
66
|
+
id,
|
67
|
+
room_id,
|
68
|
+
message
|
69
|
+
)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module RocketChat
|
2
|
+
module Messages
|
3
|
+
#
|
4
|
+
# Rocket.Chat Chat messages
|
5
|
+
#
|
6
|
+
class Chat
|
7
|
+
include RoomSupport
|
8
|
+
|
9
|
+
#
|
10
|
+
# @param [Session] session Session
|
11
|
+
#
|
12
|
+
def initialize(session)
|
13
|
+
@session = session
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# chat.delete REST API
|
18
|
+
# @param [String] room_id Rocket.Chat room id
|
19
|
+
# @param [String] name Rocket.Chat room name (coming soon)
|
20
|
+
# @param [String] msg_id The message id to delete
|
21
|
+
# @param [Boolean] as_user Message deleted as user who sent (optional - default: false)
|
22
|
+
# @return [Boolean]
|
23
|
+
# @raise [HTTPError, StatusError]
|
24
|
+
#
|
25
|
+
def delete(room_id: nil, name: nil, msg_id:, as_user: nil)
|
26
|
+
session.request_json(
|
27
|
+
'/api/v1/chat.delete',
|
28
|
+
method: :post,
|
29
|
+
body:
|
30
|
+
room_params(room_id, name).tap do |h|
|
31
|
+
h[:msgId] = msg_id
|
32
|
+
h[:asUser] = as_user unless as_user.nil?
|
33
|
+
end
|
34
|
+
)['success']
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# chat.getMessage REST API
|
39
|
+
# @param [String] msg_id The message id to return
|
40
|
+
# @return [RocketChat::Message]
|
41
|
+
# @raise [HTTPError, StatusError]
|
42
|
+
#
|
43
|
+
def get_message(msg_id:)
|
44
|
+
response = session.request_json(
|
45
|
+
'/api/v1/chat.getMessage',
|
46
|
+
body: { msgId: msg_id }
|
47
|
+
)
|
48
|
+
RocketChat::Message.new response['message'] if response['success']
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# chat.postMessage REST API
|
53
|
+
# @param [String] room_id Rocket.Chat room id
|
54
|
+
# @param [String] name Rocket.Chat room name (coming soon)
|
55
|
+
# @param [String] channel Rocket.Chat channel name
|
56
|
+
# @param [Hash] params Optional params (text, alias, emoji, avatar & attachments)
|
57
|
+
# @return [RocketChat::Message]
|
58
|
+
# @raise [HTTPError, StatusError]
|
59
|
+
#
|
60
|
+
def post_message(room_id: nil, name: nil, channel:, **params)
|
61
|
+
response = session.request_json(
|
62
|
+
'/api/v1/chat.postMessage',
|
63
|
+
method: :post,
|
64
|
+
body: room_params(room_id, name)
|
65
|
+
.merge(channel: channel)
|
66
|
+
.merge(Util.slice_hash(params, :text, :alias, :emoji, :avatar, :attachments))
|
67
|
+
)
|
68
|
+
RocketChat::Message.new response['message'] if response['success']
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# chat.update REST API
|
73
|
+
# @param [String] room_id Rocket.Chat room id
|
74
|
+
# @param [String] name Rocket.Chat room name (coming soon)
|
75
|
+
# @param [String] msg_id The message id to update
|
76
|
+
# @param [String] text Updated text for the message
|
77
|
+
# @return [RocketChat::Message]
|
78
|
+
# @raise [HTTPError, StatusError]
|
79
|
+
#
|
80
|
+
def update(room_id: nil, name: nil, msg_id:, text:)
|
81
|
+
response = session.request_json(
|
82
|
+
'/api/v1/chat.update',
|
83
|
+
method: :post,
|
84
|
+
body: room_params(room_id, name).merge(msgId: msg_id, text: text)
|
85
|
+
)
|
86
|
+
RocketChat::Message.new response['message'] if response['success']
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
attr_reader :session
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -4,6 +4,7 @@ module RocketChat
|
|
4
4
|
# Rocket.Chat Room messages template (groups&channels)
|
5
5
|
#
|
6
6
|
class Room # rubocop:disable Metrics/ClassLength
|
7
|
+
include RoomSupport
|
7
8
|
include UserSupport
|
8
9
|
|
9
10
|
def self.inherited(subclass)
|
@@ -213,16 +214,6 @@ module RocketChat
|
|
213
214
|
|
214
215
|
attr_reader :session
|
215
216
|
|
216
|
-
def room_params(id, name)
|
217
|
-
if id
|
218
|
-
{ roomId: id }
|
219
|
-
elsif name
|
220
|
-
{ roomName: name }
|
221
|
-
else
|
222
|
-
{}
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
217
|
def room_option_hash(options)
|
227
218
|
args = [options, :members, :read_only, :custom_fields]
|
228
219
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module RocketChat
|
2
|
+
module Messages
|
3
|
+
#
|
4
|
+
# Room params builder for calls with room parameters
|
5
|
+
#
|
6
|
+
module RoomSupport
|
7
|
+
def room_params(id, name)
|
8
|
+
if id
|
9
|
+
{ roomId: id }
|
10
|
+
elsif name
|
11
|
+
{ roomName: name }
|
12
|
+
else
|
13
|
+
{}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/rocket_chat/session.rb
CHANGED
data/lib/rocket_chat/util.rb
CHANGED
@@ -10,7 +10,14 @@ module RocketChat
|
|
10
10
|
#
|
11
11
|
def stringify_hash_keys(hash)
|
12
12
|
new_hash = {}
|
13
|
-
hash.each
|
13
|
+
hash.each do |key, value|
|
14
|
+
new_hash[key.to_s] =
|
15
|
+
if value.is_a? Hash
|
16
|
+
stringify_hash_keys value
|
17
|
+
else
|
18
|
+
value
|
19
|
+
end
|
20
|
+
end
|
14
21
|
new_hash
|
15
22
|
end
|
16
23
|
module_function :stringify_hash_keys
|
data/lib/rocketchat.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rocket_chat/gem_version'
|
2
2
|
|
3
3
|
require 'json'
|
4
|
+
require 'date'
|
4
5
|
|
5
6
|
require 'rocket_chat/error'
|
6
7
|
require 'rocket_chat/util'
|
@@ -8,11 +9,13 @@ require 'rocket_chat/request_helper'
|
|
8
9
|
|
9
10
|
require 'rocket_chat/messages/list_support'
|
10
11
|
require 'rocket_chat/messages/user_support'
|
12
|
+
require 'rocket_chat/messages/room_support'
|
11
13
|
require 'rocket_chat/messages/user'
|
12
14
|
require 'rocket_chat/messages/settings'
|
13
15
|
require 'rocket_chat/messages/room'
|
14
16
|
require 'rocket_chat/messages/channel'
|
15
17
|
require 'rocket_chat/messages/group'
|
18
|
+
require 'rocket_chat/messages/chat'
|
16
19
|
|
17
20
|
require 'rocket_chat/server'
|
18
21
|
require 'rocket_chat/session'
|
@@ -21,3 +24,4 @@ require 'rocket_chat/token'
|
|
21
24
|
require 'rocket_chat/presence_status'
|
22
25
|
require 'rocket_chat/room'
|
23
26
|
require 'rocket_chat/user'
|
27
|
+
require 'rocket_chat/message'
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- int512
|
@@ -115,10 +115,13 @@ files:
|
|
115
115
|
- lib/rocket_chat/error.rb
|
116
116
|
- lib/rocket_chat/gem_version.rb
|
117
117
|
- lib/rocket_chat/info.rb
|
118
|
+
- lib/rocket_chat/message.rb
|
118
119
|
- lib/rocket_chat/messages/channel.rb
|
120
|
+
- lib/rocket_chat/messages/chat.rb
|
119
121
|
- lib/rocket_chat/messages/group.rb
|
120
122
|
- lib/rocket_chat/messages/list_support.rb
|
121
123
|
- lib/rocket_chat/messages/room.rb
|
124
|
+
- lib/rocket_chat/messages/room_support.rb
|
122
125
|
- lib/rocket_chat/messages/settings.rb
|
123
126
|
- lib/rocket_chat/messages/user.rb
|
124
127
|
- lib/rocket_chat/messages/user_support.rb
|