stream-chat-ruby 2.2.0 → 2.8.0

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
  SHA256:
3
- metadata.gz: 431753dd911d42b0ca289bc4ca1b35f0043dca65d0bc846bb1af6128c491f386
4
- data.tar.gz: 7f48350204e9bad4de4a975c2d88339934e8cf195c7b38fc876a22bdd9139c63
3
+ metadata.gz: 6bd69ddcd8703b0afb1c93208ed7c42112f3daaa6b61e2d80ab86606be615151
4
+ data.tar.gz: acd7af4d4b43ed330b6bd7f95a73b4aff60593d52cf9133032e9e1b4adc66736
5
5
  SHA512:
6
- metadata.gz: fbf182d9dd41639610ac84a3e34b80a2620b707f4f5ebe67f947b7cffd1cd8b69dd43add8025177958a8be80bb521805ee8c36f564a4059a47723eb935f424b5
7
- data.tar.gz: d32a9947b564c61a9918ed72dbbf1ec38e160c754f6105213dd1d3595c53bcb8bacdf75581056d2aea9b6a27635127836fd7688c9b2b8cf0753cde99947e66ef
6
+ metadata.gz: 765c5deea378177673be188e11eefb4da985597459922b6043df2c6701f8637312f2c9c77848ab2b07f77747840ca586032a8eda442ded7b043616419e2f39d0
7
+ data.tar.gz: fc9300507e09e346b7bdaacf0dd0754f5ecf3c054140ed1409082eb009dec5efba880675ef1c464ce3450f8d5a15ff5cec2ba6223db63dce376417b1c5119379
@@ -6,9 +6,10 @@ jobs:
6
6
  build:
7
7
  runs-on: ubuntu-latest
8
8
  strategy:
9
+ max-parallel: 1
9
10
  matrix:
10
- ruby: [ '2.5', '2.6', '2.7' ]
11
- name: Ruby ${{ matrix.ruby }} sample
11
+ ruby: ['2.5', '2.6', '2.7', '3.0']
12
+ name: Ruby ${{ matrix.ruby }}
12
13
  steps:
13
14
  - uses: actions/checkout@v2
14
15
  - uses: actions/setup-ruby@v1
data/.gitignore CHANGED
@@ -48,3 +48,4 @@ Gemfile.lock
48
48
 
49
49
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
50
  .rvmrc
51
+ .envrc
data/CHANGELOG.md CHANGED
@@ -1,4 +1,34 @@
1
+ ## May 21st, 2021 - 2.8.0
2
+
3
+ - Add query message flags support
4
+
5
+ ## March 17th, 2021 - 2.7.0
6
+
7
+ - Add Ruby 3.x support
8
+ - Update CI to run all tests for all versions
9
+
10
+ ## March 9th, 2021 - 2.6.0
11
+
12
+ - Add get_rate_limits endpoint
13
+
14
+ ## February 3rd, 2021 - 2.5.0
15
+
16
+ - Add channel partial update
17
+ - Increase convenience in query members
18
+ - Improve internal symbol conversions
19
+
20
+ ## January 20th, 2021 - 2.4.0
21
+
22
+ - Add query_members to channel
23
+ - Use post endpoint for query channels instead of get
24
+ - Extract common code for sorting into a helper for query calls
25
+
26
+ ## January 5th, 2021 - 2.3.0
27
+
28
+ - Add check SQS helper
29
+
1
30
  ## January 4th, 2021 - 2.2.0
31
+
2
32
  - Add support for export channels
3
33
  - Improve readme for blocklist and export channels
4
34
  - Improve running tests for multiple versions of ruby
@@ -6,19 +36,24 @@
6
36
  - Move to GitHub Actions
7
37
 
8
38
  ## October 5th, 2020 - 2.1.0
39
+
9
40
  - Add support for blocklist
10
41
 
11
42
  ## October 2nd, 2020 - 2.0.0
43
+
12
44
  - Drop EOL Ruby versions: 2.3 && 2.4
13
45
  - Setup Rubocop and mark string literals as frozen
14
46
 
15
47
  ## August 3rd, 2020 - 1.1.3
48
+
16
49
  - Fixed Argument Error on delete_user
17
50
 
18
51
  ## April 23th, 2020 - 1.1.2
52
+
19
53
  - Fixed ArgumentError when no users was passed
20
54
 
21
55
  ## March 30th, 2020 - 1.1.1
56
+
22
57
  - Fixed few minor issues
23
58
 
24
59
  ## Oct 27th, 2019 - 1.1.0
data/README.md CHANGED
@@ -1,20 +1,20 @@
1
1
  # stream-chat-ruby
2
2
 
3
- [![build](https://github.com/GetStream/stream-chat-ruby/workflows/build/badge.svg)](https://github.com/GetStream/stream-chat-ruby/actions) [![Gem Version](https://badge.fury.io/rb/stream-chat-ruby.svg)](http://badge.fury.io/rb/stream-chat-ruby)
3
+ [![build](https://github.com/GetStream/stream-chat-ruby/workflows/build/badge.svg)](https://github.com/GetStream/stream-chat-ruby/actions) [![Gem Version](https://badge.fury.io/rb/stream-chat-ruby.svg)](http://badge.fury.io/rb/stream-chat-ruby)
4
4
 
5
5
  stream-chat-ruby is the official Ruby client for [Stream chat](https://getstream.io/chat/) a service for building chat applications.
6
6
 
7
7
  You can sign up for a Stream account at https://getstream.io/chat/get_started/.
8
8
 
9
9
  You can use this library to access chat API endpoints server-side. For the
10
- client-side integrations (web and mobile) have a look at the Javascript, iOS and
10
+ client-side integrations (web and mobile) have a look at the JavaScript, iOS and
11
11
  Android SDK libraries (https://getstream.io/chat/).
12
12
 
13
13
  ### Installation
14
14
 
15
15
  stream-chat-ruby supports:
16
16
 
17
- - Ruby (2.7, 2.6, 2.5)
17
+ - Ruby (3.0, 2.7, 2.6, 2.5)
18
18
 
19
19
  #### Install
20
20
 
@@ -28,9 +28,8 @@ gem install stream-chat-ruby
28
28
 
29
29
  ### Supported features
30
30
 
31
- - Chat channels
31
+ - Chat channel type, channels and members
32
32
  - Messages
33
- - Chat channel types
34
33
  - User management
35
34
  - Moderation API
36
35
  - Push configuration
@@ -131,6 +130,17 @@ chan.unban_user('bob-1')
131
130
 
132
131
  # Query channel state
133
132
  chan.query({'messages' => { 'limit' => 10, 'id_lte' => m1['id']}})
133
+
134
+ # Update metadata (overwrite)
135
+ chan.update({'motd' => 'one apple a day....'})
136
+
137
+ # Update partial
138
+ # 1. key-value pairs to set
139
+ # 2. keys to unset (remove)
140
+ chan.update_partial({color: 'blue', age: 30}, ['motd'])
141
+
142
+ # Query channel members
143
+ chan.query_members({name: {'$autocomplete': 'test'}}, sort: {last_created_at: -1}, offset: 5, limit: 5)
134
144
  ```
135
145
 
136
146
  ### Messages
@@ -155,6 +165,7 @@ client.remove_device(jane_phone['id'], jane_phone['user_id'])
155
165
  ```
156
166
 
157
167
  ### Blocklists
168
+
158
169
  ```ruby
159
170
  # Create a blocklist
160
171
  client.create_blocklist('my_blocker', %w[fudge cream sugar])
@@ -170,6 +181,7 @@ client.delete_blocklist('my_blocker')
170
181
  ```
171
182
 
172
183
  ### Export Channels
184
+
173
185
  ```ruby
174
186
  # Register an export
175
187
  response = client.export_channels({type: 'messaging', id: 'jane'})
@@ -179,6 +191,19 @@ status_response = client.get_export_channel_status(response['task_id'])
179
191
  # status_response['status'] == 'pending', 'completed'
180
192
  ```
181
193
 
194
+ ### Rate limits
195
+
196
+ ```ruby
197
+ # Get all rate limits
198
+ limits = client.get_rate_limits
199
+
200
+ # Get rate limits for specific platform(s)
201
+ limits = client.get_rate_limits(server_side: true)
202
+
203
+ # Get rate limits for specific platforms and endpoints
204
+ limits = client.get_rate_limits(android: true, ios: true, endpoints: ['QueryChannels', 'SendMessage'])
205
+ ```
206
+
182
207
  ### Example Rails application
183
208
 
184
209
  See [an example rails application using the Ruby SDK](https://github.com/GetStream/rails-chat-example).
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'stream-chat/errors'
4
+ require 'stream-chat/util'
4
5
 
5
6
  module StreamChat
6
7
  class Channel # rubocop:todo Metrics/ClassLength # rubocop:todo Style/Documentation
7
8
  attr_reader :id
8
9
  attr_reader :channel_type
9
10
  attr_reader :custom_data
11
+ attr_reader :members
10
12
 
11
13
  def initialize(client, channel_type, channel_id = nil, custom_data = nil)
12
14
  @channel_type = channel_type
@@ -23,7 +25,7 @@ module StreamChat
23
25
  end
24
26
 
25
27
  def send_message(message, user_id)
26
- payload = { "message": add_user_id(message, user_id) }
28
+ payload = { message: add_user_id(message, user_id) }
27
29
  @client.post("#{url}/message", data: payload)
28
30
  end
29
31
 
@@ -33,24 +35,24 @@ module StreamChat
33
35
  end
34
36
 
35
37
  def send_reaction(message_id, reaction, user_id)
36
- payload = { "reaction": add_user_id(reaction, user_id) }
38
+ payload = { reaction: add_user_id(reaction, user_id) }
37
39
  @client.post("messages/#{message_id}/reaction", data: payload)
38
40
  end
39
41
 
40
42
  def delete_reaction(message_id, reaction_type, user_id)
41
43
  @client.delete(
42
44
  "messages/#{message_id}/reaction/#{reaction_type}",
43
- params: { "user_id": user_id }
45
+ params: { user_id: user_id }
44
46
  )
45
47
  end
46
48
 
47
49
  def create(user_id)
48
- @custom_data['created_by'] = { "id": user_id }
50
+ @custom_data['created_by'] = { id: user_id }
49
51
  query(watch: false, state: false, presence: false)
50
52
  end
51
53
 
52
54
  def query(**options)
53
- payload = { "state": true, "data": @custom_data }.merge(options)
55
+ payload = { state: true, data: @custom_data }.merge(options)
54
56
  url = "channels/#{@channel_type}"
55
57
  url = "#{url}/#{@id}" unless @id.nil?
56
58
 
@@ -59,11 +61,36 @@ module StreamChat
59
61
  state
60
62
  end
61
63
 
64
+ def query_members(filter_conditions = {}, sort: nil, **options)
65
+ params = {}.merge(options).merge({
66
+ id: @id,
67
+ type: @channel_type,
68
+ filter_conditions: filter_conditions,
69
+ sort: get_sort_fields(sort)
70
+ })
71
+
72
+ if @id == '' && @members.length.positive?
73
+ params['members'] = []
74
+ @members&.each do |m|
75
+ params['members'] << m['user'].nil? ? m['user_id'] : m['user']['id']
76
+ end
77
+ end
78
+
79
+ @client.get('members', params: { payload: params.to_json })
80
+ end
81
+
62
82
  def update(channel_data, update_message = nil)
63
- payload = { "data": channel_data, "message": update_message }
83
+ payload = { data: channel_data, message: update_message }
64
84
  @client.post(url, data: payload)
65
85
  end
66
86
 
87
+ def update_partial(set = nil, unset = nil)
88
+ raise StreamChannelException 'set or unset is needed' if set.nil? && unset.nil?
89
+
90
+ payload = { set: set, unset: unset }
91
+ @client.patch(url, data: payload)
92
+ end
93
+
67
94
  def delete
68
95
  @client.delete(url)
69
96
  end
@@ -73,23 +100,23 @@ module StreamChat
73
100
  end
74
101
 
75
102
  def add_members(user_ids)
76
- @client.post(url, data: { "add_members": user_ids })
103
+ @client.post(url, data: { add_members: user_ids })
77
104
  end
78
105
 
79
106
  def invite_members(user_ids)
80
- @client.post(url, data: { "invites": user_ids })
107
+ @client.post(url, data: { invites: user_ids })
81
108
  end
82
109
 
83
110
  def add_moderators(user_ids)
84
- @client.post(url, data: { "add_moderators": user_ids })
111
+ @client.post(url, data: { add_moderators: user_ids })
85
112
  end
86
113
 
87
114
  def remove_members(user_ids)
88
- @client.post(url, data: { "remove_members": user_ids })
115
+ @client.post(url, data: { remove_members: user_ids })
89
116
  end
90
117
 
91
118
  def demote_moderators(user_ids)
92
- @client.post(url, data: { "demote_moderators": user_ids })
119
+ @client.post(url, data: { demote_moderators: user_ids })
93
120
  end
94
121
 
95
122
  def mark_read(user_id, **options)
@@ -130,17 +157,17 @@ module StreamChat
130
157
  end
131
158
 
132
159
  def delete_file(url)
133
- @client.delete("#{self.url}/file", params: { "url": url })
160
+ @client.delete("#{self.url}/file", params: { url: url })
134
161
  end
135
162
 
136
163
  def delete_image(url)
137
- @client.delete("#{self.url}/image", params: { "url": url })
164
+ @client.delete("#{self.url}/image", params: { url: url })
138
165
  end
139
166
 
140
167
  private
141
168
 
142
169
  def add_user_id(payload, user_id)
143
- payload.merge({ "user": { "id": user_id } })
170
+ payload.merge({ user: { id: user_id } })
144
171
  end
145
172
  end
146
173
  end
@@ -7,6 +7,7 @@ require 'jwt'
7
7
  require 'stream-chat/channel'
8
8
  require 'stream-chat/errors'
9
9
  require 'stream-chat/version'
10
+ require 'stream-chat/util'
10
11
 
11
12
  module StreamChat
12
13
  DEFAULT_BLOCKLIST = 'profanity_en_2020_v1'
@@ -59,22 +60,29 @@ module StreamChat
59
60
  end
60
61
 
61
62
  def flag_message(id, **options)
62
- payload = { 'target_message_id': id }.merge(options)
63
+ payload = { target_message_id: id }.merge(options)
63
64
  post('moderation/flag', data: payload)
64
65
  end
65
66
 
66
67
  def unflag_message(id, **options)
67
- payload = { 'target_message_id': id }.merge(options)
68
+ payload = { target_message_id: id }.merge(options)
68
69
  post('moderation/unflag', data: payload)
69
70
  end
70
71
 
72
+ def query_message_flags(filter_conditions, **options)
73
+ params = options.merge({
74
+ filter_conditions: filter_conditions
75
+ })
76
+ get('moderation/flags/message', params: { payload: params.to_json })
77
+ end
78
+
71
79
  def flag_user(id, **options)
72
- payload = { 'target_user_id': id }.merge(options)
80
+ payload = { target_user_id: id }.merge(options)
73
81
  post('moderation/flag', data: payload)
74
82
  end
75
83
 
76
84
  def unflag_user(id, **options)
77
- payload = { 'target_user_id': id }.merge(options)
85
+ payload = { target_user_id: id }.merge(options)
78
86
  post('moderation/unflag', data: payload)
79
87
  end
80
88
 
@@ -84,11 +92,11 @@ module StreamChat
84
92
 
85
93
  def search(filter_conditions, query, **options)
86
94
  params = options.merge({
87
- "filter_conditions": filter_conditions,
88
- "query": query
95
+ filter_conditions: filter_conditions,
96
+ query: query
89
97
  })
90
98
 
91
- get('search', params: { "payload": params.to_json })
99
+ get('search', params: { payload: params.to_json })
92
100
  end
93
101
 
94
102
  def update_users(users)
@@ -99,7 +107,7 @@ module StreamChat
99
107
 
100
108
  payload[id] = user
101
109
  end
102
- post('users', data: { 'users': payload })
110
+ post('users', data: { users: payload })
103
111
  end
104
112
 
105
113
  def update_user(user)
@@ -107,7 +115,7 @@ module StreamChat
107
115
  end
108
116
 
109
117
  def update_users_partial(updates)
110
- patch('users', data: { 'users': updates })
118
+ patch('users', data: { users: updates })
111
119
  end
112
120
 
113
121
  def update_user_partial(update)
@@ -131,34 +139,34 @@ module StreamChat
131
139
  end
132
140
 
133
141
  def ban_user(target_id, **options)
134
- payload = { 'target_user_id': target_id }.merge(options)
142
+ payload = { target_user_id: target_id }.merge(options)
135
143
  post('moderation/ban', data: payload)
136
144
  end
137
145
 
138
146
  def unban_user(target_id, **options)
139
- params = { 'target_user_id': target_id }.merge(options)
147
+ params = { target_user_id: target_id }.merge(options)
140
148
  delete('moderation/ban', params: params)
141
149
  end
142
150
 
143
151
  def mute_user(target_id, user_id)
144
- payload = { 'target_id': target_id, 'user_id': user_id }
152
+ payload = { target_id: target_id, user_id: user_id }
145
153
  post('moderation/mute', data: payload)
146
154
  end
147
155
 
148
156
  def unmute_user(target_id, user_id)
149
- payload = { 'target_id': target_id, 'user_id': user_id }
157
+ payload = { target_id: target_id, user_id: user_id }
150
158
  post('moderation/unmute', data: payload)
151
159
  end
152
160
 
153
161
  def mark_all_read(user_id)
154
- payload = { 'user': { 'id': user_id } }
162
+ payload = { user: { id: user_id } }
155
163
  post('channels/read', data: payload)
156
164
  end
157
165
 
158
166
  def update_message(message)
159
167
  raise ArgumentError 'message must have an id' unless message.key? 'id'
160
168
 
161
- post("messages/#{message['id']}", data: { 'message': message })
169
+ post("messages/#{message['id']}", data: { message: message })
162
170
  end
163
171
 
164
172
  def delete_message(message_id)
@@ -166,28 +174,20 @@ module StreamChat
166
174
  end
167
175
 
168
176
  def query_users(filter_conditions, sort: nil, **options)
169
- sort_fields = []
170
- sort&.each do |k, v|
171
- sort_fields << { "field": k, "direction": v }
172
- end
173
177
  params = options.merge({
174
- "filter_conditions": filter_conditions,
175
- "sort": sort_fields
178
+ filter_conditions: filter_conditions,
179
+ sort: get_sort_fields(sort)
176
180
  })
177
- get('users', params: { "payload": params.to_json })
181
+ get('users', params: { payload: params.to_json })
178
182
  end
179
183
 
180
184
  def query_channels(filter_conditions, sort: nil, **options)
181
- params = { "state": true, "watch": false, "presence": false }
182
- sort_fields = []
183
- sort&.each do |k, v|
184
- sort_fields << { "field": k, "direction": v }
185
- end
186
- params = params.merge(options).merge({
187
- "filter_conditions": filter_conditions,
188
- "sort": sort_fields
189
- })
190
- get('channels', params: { "payload": params.to_json })
185
+ data = { state: true, watch: false, presence: false }
186
+ data = data.merge(options).merge({
187
+ filter_conditions: filter_conditions,
188
+ sort: get_sort_fields(sort)
189
+ })
190
+ post('channels', data: data)
191
191
  end
192
192
 
193
193
  def create_channel_type(data)
@@ -225,18 +225,29 @@ module StreamChat
225
225
 
226
226
  def add_device(device_id, push_provider, user_id)
227
227
  post('devices', data: {
228
- "id": device_id,
229
- "push_provider": push_provider,
230
- "user_id": user_id
228
+ id: device_id,
229
+ push_provider: push_provider,
230
+ user_id: user_id
231
231
  })
232
232
  end
233
233
 
234
234
  def delete_device(device_id, user_id)
235
- delete('devices', params: { "id": device_id, "user_id": user_id })
235
+ delete('devices', params: { id: device_id, user_id: user_id })
236
236
  end
237
237
 
238
238
  def get_devices(user_id)
239
- get('devices', params: { "user_id": user_id })
239
+ get('devices', params: { user_id: user_id })
240
+ end
241
+
242
+ def get_rate_limits(server_side: false, android: false, ios: false, web: false, endpoints: [])
243
+ params = {}
244
+ params['server_side'] = server_side if server_side
245
+ params['android'] = android if android
246
+ params['ios'] = ios if ios
247
+ params['web'] = web if web
248
+ params['endpoints'] = endpoints.join(',') unless endpoints.empty?
249
+
250
+ get('rate_limits', params: params)
240
251
  end
241
252
 
242
253
  def verify_webhook(request_body, x_signature)
@@ -253,11 +264,11 @@ module StreamChat
253
264
  end
254
265
 
255
266
  def create_blocklist(name, words)
256
- post('blocklists', data: { "name": name, "words": words })
267
+ post('blocklists', data: { name: name, words: words })
257
268
  end
258
269
 
259
270
  def update_blocklist(name, words)
260
- put("blocklists/#{name}", data: { "words": words })
271
+ put("blocklists/#{name}", data: { words: words })
261
272
  end
262
273
 
263
274
  def delete_blocklist(name)
@@ -265,7 +276,7 @@ module StreamChat
265
276
  end
266
277
 
267
278
  def export_channels(*channels)
268
- post('export_channels', data: { "channels": channels })
279
+ post('export_channels', data: { channels: channels })
269
280
  end
270
281
 
271
282
  def get_export_channel_status(task_id)
@@ -311,6 +322,10 @@ module StreamChat
311
322
  parse_response(response)
312
323
  end
313
324
 
325
+ def check_sqs(sqs_key = nil, sqs_secret = nil, sqs_url = nil)
326
+ post('check_sqs', data: { sqs_key: sqs_key, sqs_secret: sqs_secret, sqs_url: sqs_url })
327
+ end
328
+
314
329
  private
315
330
 
316
331
  def get_default_params
@@ -345,7 +360,7 @@ module StreamChat
345
360
  headers['stream-auth-type'] = 'jwt'
346
361
  url = [@base_url, relative_url].join('/')
347
362
  params = params.nil? ? {} : params
348
- params = Hash[get_default_params.merge(params).sort_by { |k, _v| k.to_s }]
363
+ params = (get_default_params.merge(params).sort_by { |k, _v| k.to_s }).to_h
349
364
  url = "#{url}?#{URI.encode_www_form(params)}"
350
365
 
351
366
  body = data.to_json if %w[patch post put].include? method.to_s
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/util.rb
4
+
5
+ def get_sort_fields(sort)
6
+ sort_fields = []
7
+ sort&.each do |k, v|
8
+ sort_fields << { field: k, direction: v }
9
+ end
10
+ sort_fields
11
+ end
@@ -3,5 +3,5 @@
3
3
  # lib/version.rb
4
4
 
5
5
  module StreamChat
6
- VERSION = '2.2.0'
6
+ VERSION = '2.8.0'
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stream-chat-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mircea Cosbuc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-05 00:00:00.000000000 Z
11
+ date: 2021-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -99,6 +99,7 @@ files:
99
99
  - lib/stream-chat/channel.rb
100
100
  - lib/stream-chat/client.rb
101
101
  - lib/stream-chat/errors.rb
102
+ - lib/stream-chat/util.rb
102
103
  - lib/stream-chat/version.rb
103
104
  - stream-chat.gemspec
104
105
  homepage: http://github.com/GetStream/stream-chat-ruby