rocketchat 0.1.5 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63395cd09bc2b53e342ce3d90fac28b2891d6021
4
- data.tar.gz: 2be643107b5c947a9d775b208ba1fdeca8ac8d7e
3
+ metadata.gz: ed12cd37565f3e4906733b1023bfac88e5a6f3cb
4
+ data.tar.gz: cd0d89858645ca5385aca940d2ba7efd7f4357a4
5
5
  SHA512:
6
- metadata.gz: 49ff8a992f56000de70631349a03b86d2ecc2b5002b2d430d59fb24ef08176406c40afba5ef1d32a0dc27306cc63f114f54f035b7c4083db572f9c66f3f8b98b
7
- data.tar.gz: a9d75b6c61ccdd46f65241b37484f90a95f90ac9df1f757360ad59718180d7aa5486944c91c005a353099f1f2b53df012e34b814ad7781973c69d7e7db76c1a1
6
+ metadata.gz: a2cbd52d970d141b7938dfbd8ffbbf3bad29b0f38788e1da079b63ac67c78dfb2bd5338d8f87fd10ff98d1ebee97b01495ccf452404e6be381dc1f8e0b277bad
7
+ data.tar.gz: 5879c04d4384ef56ac148c9608a4c7606c1521e4d3b2336021ee43fbe7d76c0a775caead524cb7ca49a66e35f5411faab267bbdbf59c46e35f7a7ecab32d0086
data/README.md CHANGED
@@ -37,15 +37,33 @@ This gem supports the following Rocket.Chat APIs (Tested against Rocket.Chat v0.
37
37
 
38
38
  #### Channels
39
39
  * [/api/v1/channels.create](docs/channels.md#channelscreate)
40
+ * [/api/v1/channels.delete](docs/channels.md#channelsdelete)
40
41
  * [/api/v1/channels.info](docs/channels.md#channelsinfo)
42
+ * [/api/v1/channels.invite](docs/channels.md#channelsinvite)
43
+ * [/api/v1/channels.join](docs/channels.md#channelsjoin)
44
+ * [/api/v1/channels.leave](docs/channels.md#channelsleave)
41
45
  * [/api/v1/channels.list](docs/channels.md#channelslist)
42
46
  * [/api/v1/channels.rename](docs/channels.md#channelsrename)
47
+ * [/api/v1/channels.setDescription](docs/channels.md#channelsset_attr)
48
+ * [/api/v1/channels.setJoinCode](docs/channels.md#channelsset_attr)
49
+ * [/api/v1/channels.setPurpose](docs/channels.md#channelsset_attr)
50
+ * [/api/v1/channels.setReadOnly](docs/channels.md#channelsset_attr)
51
+ * [/api/v1/channels.setTopic](docs/channels.md#channelsset_attr)
52
+ * [/api/v1/channels.setType](docs/channels.md#channelsset_attr)
43
53
 
44
54
  #### Groups
45
55
  * /api/v1/groups.create
56
+ * /api/v1/groups.delete
46
57
  * /api/v1/groups.info
58
+ * /api/v1/groups.invite
59
+ * /api/v1/groups.leave
47
60
  * [/api/v1/groups.list](docs/groups.md#groupslist)
48
61
  * /api/v1/groups.rename
62
+ * /api/v1/groups.setDescription
63
+ * /api/v1/groups.setPurpose
64
+ * /api/v1/groups.setReadOnly
65
+ * /api/v1/groups.setTopic
66
+ * /api/v1/groups.setType
49
67
 
50
68
  #### Users
51
69
  * [/api/v1/users.create](docs/users.md#userscreate)
@@ -1,3 +1,3 @@
1
1
  module RocketChat
2
- VERSION = '0.1.5'.freeze
2
+ VERSION = '0.1.6'.freeze
3
3
  end
@@ -6,6 +6,22 @@ module RocketChat
6
6
  class Channel < Room
7
7
  include ListSupport
8
8
 
9
+ #
10
+ # channels.join REST API
11
+ # @param [String] room_id Rocket.Chat room id
12
+ # @param [String] name Rocket.Chat room name (coming soon)
13
+ # @return [Boolean]
14
+ # @raise [HTTPError, StatusError]
15
+ #
16
+ def join(room_id: nil, name: nil)
17
+ session.request_json(
18
+ '/api/v1/channels.join',
19
+ method: :post,
20
+ body: room_params(room_id, name)
21
+ )['success']
22
+ end
23
+
24
+ #
9
25
  # channels.list REST API
10
26
  # @param [Integer] offset Query offset
11
27
  # @param [Integer] count Query count/limit
@@ -23,6 +39,17 @@ module RocketChat
23
39
 
24
40
  response['channels'].map { |hash| RocketChat::Room.new hash } if response['success']
25
41
  end
42
+
43
+ # Keys for set_attr:
44
+ # * [String] description A room's description
45
+ # * [String] join_code Code to join a channel
46
+ # * [String] purpose Alias for description
47
+ # * [Boolean] read_only Read-only status
48
+ # * [String] topic A room's topic
49
+ # * [Strong] type c (channel) or p (private group)
50
+ def self.settable_attributes
51
+ %i[description join_code purpose read_only topic type]
52
+ end
26
53
  end
27
54
  end
28
55
  end
@@ -6,6 +6,44 @@ module RocketChat
6
6
  class Group < Room
7
7
  include ListSupport
8
8
 
9
+ #
10
+ # *.add_leader REST API
11
+ # @param [String] room_id Rocket.Chat room id
12
+ # @param [String] leader Rocket.Chat user id
13
+ # @return [Boolean]
14
+ # @raise [HTTPError, StatusError]
15
+ #
16
+ def add_leader(room_id: nil, user_id: nil)
17
+ session.request_json(
18
+ self.class.api_path('addLeader'),
19
+ method: :post,
20
+ body: {
21
+ roomId: room_id,
22
+ userId: user_id
23
+ },
24
+ upstreamed_errors: ['error-room-not-found']
25
+ )['success']
26
+ end
27
+
28
+ #
29
+ # *.remove_leader REST API
30
+ # @param [String] room_id Rocket.Chat room id
31
+ # @param [String] leader Rocket.Chat user id
32
+ # @return [Boolean]
33
+ # @raise [HTTPError, StatusError]
34
+ #
35
+ def remove_leader(room_id: nil, user_id: nil)
36
+ session.request_json(
37
+ self.class.api_path('removeLeader'),
38
+ method: :post,
39
+ body: {
40
+ roomId: room_id,
41
+ userId: user_id
42
+ },
43
+ upstreamed_errors: ['error-room-not-found']
44
+ )['success']
45
+ end
46
+
9
47
  # groups.list REST API
10
48
  # @param [Integer] offset Query offset
11
49
  # @param [Integer] count Query count/limit
@@ -22,6 +60,16 @@ module RocketChat
22
60
 
23
61
  response['groups'].map { |hash| RocketChat::Room.new hash } if response['success']
24
62
  end
63
+
64
+ # Keys for set_attr:
65
+ # * [String] description A room's description
66
+ # * [String] purpose Alias for description
67
+ # * [Boolean] read_only Read-only status
68
+ # * [String] topic A room's topic
69
+ # * [Strong] type c (channel) or p (private group)
70
+ def self.settable_attributes
71
+ %i[description purpose read_only topic type]
72
+ end
25
73
  end
26
74
  end
27
75
  end
@@ -3,7 +3,9 @@ module RocketChat
3
3
  #
4
4
  # Rocket.Chat Room messages template (groups&channels)
5
5
  #
6
- class Room
6
+ class Room # rubocop:disable Metrics/ClassLength
7
+ include UserSupport
8
+
7
9
  def self.inherited(subclass)
8
10
  field = subclass.name.split('::')[-1].downcase
9
11
  collection = field + 's'
@@ -41,6 +43,60 @@ module RocketChat
41
43
  RocketChat::Room.new response[self.class.field]
42
44
  end
43
45
 
46
+ #
47
+ # *.delete REST API
48
+ # @param [String] room_id Rocket.Chat room id
49
+ # @param [String] name Rocket.Chat room name (coming soon)
50
+ # @return [Boolean]
51
+ # @raise [HTTPError, StatusError]
52
+ #
53
+ def delete(room_id: nil, name: nil)
54
+ session.request_json(
55
+ self.class.api_path('delete'),
56
+ method: :post,
57
+ body: room_params(room_id, name),
58
+ upstreamed_errors: ['error-room-not-found']
59
+ )['success']
60
+ end
61
+
62
+ #
63
+ # *.add_owner REST API
64
+ # @param [String] room_id Rocket.Chat room id
65
+ # @param [String] user_id Rocket.Chat user id
66
+ # @return [Boolean]
67
+ # @raise [HTTPError, StatusError]
68
+ #
69
+ def add_owner(room_id: nil, user_id: nil)
70
+ session.request_json(
71
+ self.class.api_path('addOwner'),
72
+ method: :post,
73
+ body: {
74
+ roomId: room_id,
75
+ userId: user_id
76
+ },
77
+ upstreamed_errors: ['error-room-not-found']
78
+ )['success']
79
+ end
80
+
81
+ #
82
+ # *.remove_owner REST API
83
+ # @param [String] room_id Rocket.Chat room id
84
+ # @param [String] user_id Rocket.Chat user id
85
+ # @return [Boolean]
86
+ # @raise [HTTPError, StatusError]
87
+ #
88
+ def remove_owner(room_id: nil, user_id: nil)
89
+ session.request_json(
90
+ self.class.api_path('removeOwner'),
91
+ method: :post,
92
+ body: {
93
+ roomId: room_id,
94
+ userId: user_id
95
+ },
96
+ upstreamed_errors: ['error-room-not-found']
97
+ )['success']
98
+ end
99
+
44
100
  #
45
101
  # *.info REST API
46
102
  # @param [String] room_id Rocket.Chat room id
@@ -58,6 +114,39 @@ module RocketChat
58
114
  RocketChat::Room.new response[self.class.field] if response['success']
59
115
  end
60
116
 
117
+ #
118
+ # *.invite REST API
119
+ # @param [String] room_id Rocket.Chat room id
120
+ # @param [String] name Rocket.Chat room name (coming soon)
121
+ # @param [String] user_id Rocket.Chat user id
122
+ # @param [String] username Username
123
+ # @return [Boolean]
124
+ # @raise [HTTPError, StatusError]
125
+ #
126
+ def invite(room_id: nil, name: nil, user_id: nil, username: nil)
127
+ session.request_json(
128
+ self.class.api_path('invite'),
129
+ method: :post,
130
+ body: room_params(room_id, name)
131
+ .merge(user_params(user_id, username))
132
+ )['success']
133
+ end
134
+
135
+ #
136
+ # *.leave REST API
137
+ # @param [String] room_id Rocket.Chat room id
138
+ # @param [String] name Rocket.Chat room name (coming soon)
139
+ # @return [Boolean]
140
+ # @raise [HTTPError, StatusError]
141
+ #
142
+ def leave(room_id: nil, name: nil)
143
+ session.request_json(
144
+ self.class.api_path('leave'),
145
+ method: :post,
146
+ body: room_params(room_id, name)
147
+ )['success']
148
+ end
149
+
61
150
  #
62
151
  # *.rename REST API
63
152
  # @param [String] room_id Rocket.Chat room id
@@ -73,6 +162,25 @@ module RocketChat
73
162
  )['success']
74
163
  end
75
164
 
165
+ #
166
+ # *.set* REST API
167
+ # @param [String] room_id Rocket.Chat room id
168
+ # @param [String] new_name New room name
169
+ # @param [Hash] setting Single key-value
170
+ # @return [Boolean]
171
+ # @raise [ArgumentError, HTTPError, StatusError]
172
+ #
173
+ def set_attr(room_id: nil, name: nil, **setting)
174
+ attribute, value = setting.first
175
+ validate_attribute(attribute)
176
+ session.request_json(
177
+ self.class.api_path(Util.camelize("set_#{attribute}")),
178
+ method: :post,
179
+ body: room_params(room_id, name)
180
+ .merge(Util.camelize(attribute) => value)
181
+ )['success']
182
+ end
183
+
76
184
  private
77
185
 
78
186
  attr_reader :session
@@ -82,6 +190,8 @@ module RocketChat
82
190
  { roomId: id }
83
191
  elsif name
84
192
  { roomName: name }
193
+ else
194
+ {}
85
195
  end
86
196
  end
87
197
 
@@ -95,6 +205,11 @@ module RocketChat
95
205
  options.each { |key, value| new_hash[Util.camelize(key)] = value }
96
206
  new_hash
97
207
  end
208
+
209
+ def validate_attribute(attribute)
210
+ raise ArgumentError, "Unsettable attribute: #{attribute || 'nil'}" unless \
211
+ self.class.settable_attributes.include?(attribute)
212
+ end
98
213
  end
99
214
  end
100
215
  end
@@ -3,8 +3,9 @@ module RocketChat
3
3
  #
4
4
  # Rocket.Chat User messages
5
5
  #
6
- class User # rubocop:disable Metrics/ClassLength
6
+ class User
7
7
  include ListSupport
8
+ include UserSupport
8
9
 
9
10
  #
10
11
  # @param [Session] session Session
@@ -188,14 +189,6 @@ module RocketChat
188
189
  options.each { |key, value| new_hash[Util.camelize(key)] = value }
189
190
  new_hash
190
191
  end
191
-
192
- def user_params(id, username)
193
- if id
194
- { userId: id }
195
- elsif username
196
- { username: username }
197
- end
198
- end
199
192
  end
200
193
  end
201
194
  end
@@ -0,0 +1,18 @@
1
+ module RocketChat
2
+ module Messages
3
+ #
4
+ # User params builder for calls with user parameters
5
+ #
6
+ module UserSupport
7
+ def user_params(id, username)
8
+ if id
9
+ { userId: id }
10
+ elsif username
11
+ { username: username }
12
+ else
13
+ {}
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -7,6 +7,7 @@ require 'rocket_chat/util'
7
7
  require 'rocket_chat/request_helper'
8
8
 
9
9
  require 'rocket_chat/messages/list_support'
10
+ require 'rocket_chat/messages/user_support'
10
11
  require 'rocket_chat/messages/user'
11
12
  require 'rocket_chat/messages/settings'
12
13
  require 'rocket_chat/messages/room'
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.5
4
+ version: 0.1.6
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-07-09 00:00:00.000000000 Z
12
+ date: 2017-07-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -121,6 +121,7 @@ files:
121
121
  - lib/rocket_chat/messages/room.rb
122
122
  - lib/rocket_chat/messages/settings.rb
123
123
  - lib/rocket_chat/messages/user.rb
124
+ - lib/rocket_chat/messages/user_support.rb
124
125
  - lib/rocket_chat/presence_status.rb
125
126
  - lib/rocket_chat/request_helper.rb
126
127
  - lib/rocket_chat/room.rb