rocketchat 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/README.md +12 -0
- data/lib/rocket_chat/gem_version.rb +1 -1
- data/lib/rocket_chat/messages/channel.rb +28 -0
- data/lib/rocket_chat/messages/group.rb +27 -0
- data/lib/rocket_chat/messages/list_support.rb +27 -0
- data/lib/rocket_chat/messages/room.rb +100 -0
- data/lib/rocket_chat/messages/user.rb +3 -13
- data/lib/rocket_chat/room.rb +94 -0
- data/lib/rocket_chat/session.rb +10 -4
- data/lib/rocketchat.rb +5 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1ece9d7db49aaf491be028d4b226e4735ac74a6
|
4
|
+
data.tar.gz: 0fb9b1d7cafbe4c2bde83f23fc4f21f4f75c48ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c9db4af0f670500137e109f276c911d67517d7b8677c5999405fe7f7f0f3c5cf77e3659fdf30087085e5db7d9f36f66bfb8d398c18fa7be36ac1a57c0ad4e2f
|
7
|
+
data.tar.gz: 9e391cff6561058ebbbe366dcd9e9b8c06dd1e3221cee2673a21568f94a91da45c330950ca36966846163a3ee7360fe5c727d7e52a90022de92f9566d1e33a9b
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -35,6 +35,18 @@ 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
|
+
#### Channels
|
39
|
+
* [/api/v1/channels.create](docs/channels.md#channelscreate)
|
40
|
+
* [/api/v1/channels.info](docs/channels.md#channelsinfo)
|
41
|
+
* [/api/v1/channels.list](docs/channels.md#channelslist)
|
42
|
+
* [/api/v1/channels.rename](docs/channels.md#channelsrename)
|
43
|
+
|
44
|
+
#### Groups
|
45
|
+
* /api/v1/groups.create
|
46
|
+
* /api/v1/groups.info
|
47
|
+
* [/api/v1/groups.list](docs/groups.md#groupslist)
|
48
|
+
* /api/v1/groups.rename
|
49
|
+
|
38
50
|
#### Users
|
39
51
|
* [/api/v1/users.create](docs/users.md#userscreate)
|
40
52
|
* [/api/v1/users.delete](docs/users.md#usersdelete)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module RocketChat
|
2
|
+
module Messages
|
3
|
+
#
|
4
|
+
# Rocket.Chat Channel messages
|
5
|
+
#
|
6
|
+
class Channel < Room
|
7
|
+
include ListSupport
|
8
|
+
|
9
|
+
# channels.list REST API
|
10
|
+
# @param [Integer] offset Query offset
|
11
|
+
# @param [Integer] count Query count/limit
|
12
|
+
# @param [Hash] sort Query field sort hash. eg `{ msgs: 1, name: -1 }`
|
13
|
+
# @param [Hash] fields Query fields to return. eg `{ name: 1, ro: 0 }`
|
14
|
+
# @param [Hash] query The query. `{ active: true, type: { '$in': ['name', 'general'] } }`
|
15
|
+
# @return [Room[]]
|
16
|
+
# @raise [HTTPError, StatusError]
|
17
|
+
#
|
18
|
+
def list(offset: nil, count: nil, sort: nil, fields: nil, query: nil)
|
19
|
+
response = session.request_json(
|
20
|
+
'/api/v1/channels.list',
|
21
|
+
body: build_list_body(offset, count, sort, fields, query)
|
22
|
+
)
|
23
|
+
|
24
|
+
response['channels'].map { |hash| RocketChat::Room.new hash } if response['success']
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module RocketChat
|
2
|
+
module Messages
|
3
|
+
#
|
4
|
+
# Rocket.Chat Group messages
|
5
|
+
#
|
6
|
+
class Group < Room
|
7
|
+
include ListSupport
|
8
|
+
|
9
|
+
# groups.list REST API
|
10
|
+
# @param [Integer] offset Query offset
|
11
|
+
# @param [Integer] count Query count/limit
|
12
|
+
# @param [Hash] sort Query field sort hash. eg `{ msgs: 1, name: -1 }`
|
13
|
+
# @param [Hash] fields Query fields to return. eg `{ name: 1, ro: 0 }`
|
14
|
+
# @return [Room[]]
|
15
|
+
# @raise [HTTPError, StatusError]
|
16
|
+
#
|
17
|
+
def list(offset: nil, count: nil, sort: nil, fields: nil)
|
18
|
+
response = session.request_json(
|
19
|
+
'/api/v1/groups.list',
|
20
|
+
body: build_list_body(offset, count, sort, fields)
|
21
|
+
)
|
22
|
+
|
23
|
+
response['groups'].map { |hash| RocketChat::Room.new hash } if response['success']
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module RocketChat
|
2
|
+
module Messages
|
3
|
+
#
|
4
|
+
# Support methods for *.list calls
|
5
|
+
#
|
6
|
+
module ListSupport
|
7
|
+
private
|
8
|
+
|
9
|
+
def build_list_body(offset, count, sort, fields, query = nil)
|
10
|
+
body = {}
|
11
|
+
|
12
|
+
body[:offset] = offset.to_i if offset.is_a? Integer
|
13
|
+
body[:count] = count.to_i if count.is_a? Integer
|
14
|
+
[[:sort, sort], [:fields, fields], [:query, query]].each do |field, val|
|
15
|
+
case val
|
16
|
+
when Hash
|
17
|
+
body[field] = val.to_json
|
18
|
+
when String
|
19
|
+
body[field] = val
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
body
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module RocketChat
|
2
|
+
module Messages
|
3
|
+
#
|
4
|
+
# Rocket.Chat Room messages template (groups&channels)
|
5
|
+
#
|
6
|
+
class Room
|
7
|
+
def self.inherited(subclass)
|
8
|
+
field = subclass.name.split('::')[-1].downcase
|
9
|
+
collection = field + 's'
|
10
|
+
subclass.send(:define_singleton_method, :field) { field }
|
11
|
+
subclass.send(:define_singleton_method, :collection) { collection }
|
12
|
+
end
|
13
|
+
|
14
|
+
#
|
15
|
+
# @param [Session] session Session
|
16
|
+
#
|
17
|
+
def initialize(session)
|
18
|
+
@session = session
|
19
|
+
end
|
20
|
+
|
21
|
+
# Full API path to call
|
22
|
+
def self.api_path(method)
|
23
|
+
"/api/v1/#{collection}.#{method}"
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# *.create REST API
|
28
|
+
# @param [String] name Room name
|
29
|
+
# @param [Hash] options Additional options
|
30
|
+
# @return [Room]
|
31
|
+
# @raise [HTTPError, StatusError]
|
32
|
+
#
|
33
|
+
def create(name, options = {})
|
34
|
+
response = session.request_json(
|
35
|
+
self.class.api_path('create'),
|
36
|
+
method: :post,
|
37
|
+
body: {
|
38
|
+
name: name
|
39
|
+
}.merge(room_option_hash(options))
|
40
|
+
)
|
41
|
+
RocketChat::Room.new response[self.class.field]
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# *.info REST API
|
46
|
+
# @param [String] room_id Rocket.Chat room id
|
47
|
+
# @param [String] name Room name (channels since 0.56)
|
48
|
+
# @return [Room]
|
49
|
+
# @raise [HTTPError, StatusError]
|
50
|
+
#
|
51
|
+
def info(room_id: nil, name: nil)
|
52
|
+
response = session.request_json(
|
53
|
+
self.class.api_path('info'),
|
54
|
+
body: room_params(room_id, name),
|
55
|
+
upstreamed_errors: ['error-room-not-found']
|
56
|
+
)
|
57
|
+
|
58
|
+
RocketChat::Room.new response[self.class.field] if response['success']
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# *.rename REST API
|
63
|
+
# @param [String] room_id Rocket.Chat room id
|
64
|
+
# @param [String] new_name New room name
|
65
|
+
# @return [Boolean]
|
66
|
+
# @raise [HTTPError, StatusError]
|
67
|
+
#
|
68
|
+
def rename(room_id, new_name)
|
69
|
+
session.request_json(
|
70
|
+
self.class.api_path('rename'),
|
71
|
+
method: :post,
|
72
|
+
body: { roomId: room_id, name: new_name }
|
73
|
+
)['success']
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
attr_reader :session
|
79
|
+
|
80
|
+
def room_params(id, name)
|
81
|
+
if id
|
82
|
+
{ roomId: id }
|
83
|
+
elsif name
|
84
|
+
{ roomName: name }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def room_option_hash(options)
|
89
|
+
args = [options, :members, :read_only, :custom_fields]
|
90
|
+
|
91
|
+
options = Util.slice_hash(*args)
|
92
|
+
return {} if options.empty?
|
93
|
+
|
94
|
+
new_hash = {}
|
95
|
+
options.each { |key, value| new_hash[Util.camelize(key)] = value }
|
96
|
+
new_hash
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -4,6 +4,8 @@ module RocketChat
|
|
4
4
|
# Rocket.Chat User messages
|
5
5
|
#
|
6
6
|
class User
|
7
|
+
include ListSupport
|
8
|
+
|
7
9
|
#
|
8
10
|
# @param [Session] session Session
|
9
11
|
#
|
@@ -76,7 +78,7 @@ module RocketChat
|
|
76
78
|
# @param [Integer] count Query count/limit
|
77
79
|
# @param [Hash] sort Query field sort hash. eg `{ active: 1, email: -1 }`
|
78
80
|
# @param [Hash] fields Query fields to return. eg `{ name: 1, email: 0 }`
|
79
|
-
# @param [Hash] query The query. `{ active: true, type: { $in: ['user', 'bot'] } }`
|
81
|
+
# @param [Hash] query The query. `{ active: true, type: { '$in': ['user', 'bot'] } }`
|
80
82
|
# @return [User[]]
|
81
83
|
# @raise [HTTPError, StatusError]
|
82
84
|
#
|
@@ -156,18 +158,6 @@ module RocketChat
|
|
156
158
|
new_hash
|
157
159
|
end
|
158
160
|
|
159
|
-
def build_list_body(offset, count, sort, fields, query)
|
160
|
-
body = {}
|
161
|
-
|
162
|
-
body[:offset] = offset.to_i if offset.is_a? Integer
|
163
|
-
body[:count] = count.to_i if count.is_a? Integer
|
164
|
-
body[:sort] = sort.to_json if sort.is_a? Hash
|
165
|
-
body[:fields] = fields.to_json if fields.is_a? Hash
|
166
|
-
body[:query] = query.to_json if query.is_a? Hash
|
167
|
-
|
168
|
-
body
|
169
|
-
end
|
170
|
-
|
171
161
|
def user_params(id, username)
|
172
162
|
if id
|
173
163
|
{ userId: id }
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module RocketChat
|
2
|
+
#
|
3
|
+
# Rocket.Chat Room
|
4
|
+
#
|
5
|
+
class Room
|
6
|
+
# Raw user data
|
7
|
+
attr_reader :data
|
8
|
+
|
9
|
+
TYPES = {
|
10
|
+
'c' => 'public',
|
11
|
+
'p' => 'private',
|
12
|
+
'd' => 'IM'
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
#
|
16
|
+
# @param [Hash] data Raw user data
|
17
|
+
#
|
18
|
+
def initialize(data)
|
19
|
+
@data = Util.stringify_hash_keys data
|
20
|
+
end
|
21
|
+
|
22
|
+
# Channel ID
|
23
|
+
def id
|
24
|
+
data['_id']
|
25
|
+
end
|
26
|
+
|
27
|
+
# Channel name
|
28
|
+
def name
|
29
|
+
data['name']
|
30
|
+
end
|
31
|
+
|
32
|
+
# Channel owner
|
33
|
+
def owner
|
34
|
+
data['u']
|
35
|
+
end
|
36
|
+
|
37
|
+
def created_at
|
38
|
+
data['ts']
|
39
|
+
end
|
40
|
+
|
41
|
+
def last_update
|
42
|
+
data['_updatedAt']
|
43
|
+
end
|
44
|
+
|
45
|
+
def topic
|
46
|
+
data['topic']
|
47
|
+
end
|
48
|
+
|
49
|
+
def description
|
50
|
+
data['description']
|
51
|
+
end
|
52
|
+
|
53
|
+
# Channel members
|
54
|
+
def members
|
55
|
+
data['usernames'] || []
|
56
|
+
end
|
57
|
+
|
58
|
+
# Read-only status
|
59
|
+
def read_only
|
60
|
+
data['ro']
|
61
|
+
end
|
62
|
+
|
63
|
+
# Message count
|
64
|
+
def message_count
|
65
|
+
data['msgs']
|
66
|
+
end
|
67
|
+
|
68
|
+
# Last message timestamp
|
69
|
+
def last_message
|
70
|
+
data['lm']
|
71
|
+
end
|
72
|
+
|
73
|
+
# Channel type
|
74
|
+
def type
|
75
|
+
TYPES[data['t']] || data['t']
|
76
|
+
end
|
77
|
+
|
78
|
+
# System messages (user left, got invited, room renamed, etc)
|
79
|
+
def system_messages
|
80
|
+
data['sysMes']
|
81
|
+
end
|
82
|
+
|
83
|
+
def inspect
|
84
|
+
format(
|
85
|
+
'#<%s:0x%p @id="%s" @name="%s" @type="%s">',
|
86
|
+
self.class.name,
|
87
|
+
object_id,
|
88
|
+
id,
|
89
|
+
name,
|
90
|
+
type
|
91
|
+
)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/lib/rocket_chat/session.rb
CHANGED
@@ -40,10 +40,16 @@ module RocketChat
|
|
40
40
|
User.new request_json('/api/v1/me', method: :get)
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
### Message proxies
|
44
|
+
|
45
|
+
def channels
|
46
|
+
@channels ||= RocketChat::Messages::Channel.new(self)
|
47
|
+
end
|
48
|
+
|
49
|
+
def groups
|
50
|
+
@groups ||= RocketChat::Messages::Group.new(self)
|
51
|
+
end
|
52
|
+
|
47
53
|
def users
|
48
54
|
@users ||= RocketChat::Messages::User.new(self)
|
49
55
|
end
|
data/lib/rocketchat.rb
CHANGED
@@ -6,12 +6,17 @@ require 'rocket_chat/error'
|
|
6
6
|
require 'rocket_chat/util'
|
7
7
|
require 'rocket_chat/request_helper'
|
8
8
|
|
9
|
+
require 'rocket_chat/messages/list_support'
|
9
10
|
require 'rocket_chat/messages/user'
|
10
11
|
require 'rocket_chat/messages/settings'
|
12
|
+
require 'rocket_chat/messages/room'
|
13
|
+
require 'rocket_chat/messages/channel'
|
14
|
+
require 'rocket_chat/messages/group'
|
11
15
|
|
12
16
|
require 'rocket_chat/server'
|
13
17
|
require 'rocket_chat/session'
|
14
18
|
require 'rocket_chat/info'
|
15
19
|
require 'rocket_chat/token'
|
16
20
|
require 'rocket_chat/presence_status'
|
21
|
+
require 'rocket_chat/room'
|
17
22
|
require 'rocket_chat/user'
|
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.2
|
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: 2017-
|
12
|
+
date: 2017-05-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -115,10 +115,15 @@ 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/messages/channel.rb
|
119
|
+
- lib/rocket_chat/messages/group.rb
|
120
|
+
- lib/rocket_chat/messages/list_support.rb
|
121
|
+
- lib/rocket_chat/messages/room.rb
|
118
122
|
- lib/rocket_chat/messages/settings.rb
|
119
123
|
- lib/rocket_chat/messages/user.rb
|
120
124
|
- lib/rocket_chat/presence_status.rb
|
121
125
|
- lib/rocket_chat/request_helper.rb
|
126
|
+
- lib/rocket_chat/room.rb
|
122
127
|
- lib/rocket_chat/server.rb
|
123
128
|
- lib/rocket_chat/session.rb
|
124
129
|
- lib/rocket_chat/token.rb
|