stream-chat-ruby 2.0.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7a819d41561a5fe8bf986b1ddcdc093a985a6de19bd256071a88efb4d790d58
4
- data.tar.gz: e5cdc6e77fa5e453afbbbdf482c61f791a6896c47fe903f56acdca9794f662a6
3
+ metadata.gz: cff8888b576ad92ca17c3275504e585b1490e3935e7d86595aad795dfea67a7d
4
+ data.tar.gz: 8aa309ce84be59f966edee13e0e8957f863f59c535bc8df9d41d90484e8b1cb5
5
5
  SHA512:
6
- metadata.gz: 97fce2a3420903a2b9a88e7197a58683a5e3d0d54139350aec0d7c5029fd657352e2102be57fb398f5e389f5d97a500c5a88fce744f19ae2ffab2c5410ce297e
7
- data.tar.gz: c9c2c76a61e874e43778b6181e1a2f68191aec1e0444272f043f6086f83f9151ae5a29d7c1255a60bf695520cdbe6e09bc5f87becda1dac93c461468a8b50539
6
+ metadata.gz: 9ca7b965ba2ca2fdffcb3ff667d93a1081e5aa15f40d3aeb9a167c945f26e54d3e773e826ca583c445c0da02acb5f67f3c450d7fc3fce98fcb958acd7e9077cf
7
+ data.tar.gz: 98b040deb4906b952d393244fb228843e77d669481104fa0ca75512cdcaacfccd75d8733c9ade31854366ab066ff6c58a54d2ff3c89e6c590d5a8c9fdc17c888
@@ -0,0 +1,26 @@
1
+ name: build
2
+
3
+ on: [pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ ruby: [ '2.5', '2.6', '2.7' ]
11
+ name: Ruby ${{ matrix.ruby }} sample
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - uses: actions/setup-ruby@v1
15
+ with:
16
+ ruby-version: ${{ matrix.ruby }}
17
+
18
+ - env:
19
+ STREAM_CHAT_API_KEY: ${{ secrets.STREAM_CHAT_API_KEY }}
20
+ STREAM_CHAT_API_SECRET: ${{ secrets.STREAM_CHAT_API_SECRET }}
21
+ BLOCKLIST: ${{ matrix.ruby == '2.7' }}
22
+ run: |
23
+ gem install bundler
24
+ bundle install --jobs 4 --retry 3
25
+ bundle exec rake rubocop
26
+ bundle exec rake test
data/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ ## February 3rd, 2021 - 2.5.0
2
+ - Add channel partial update
3
+ - Increase convenience in query members
4
+ - Improve internal symbol conversions
5
+
6
+ ## January 20th, 2021 - 2.4.0
7
+ - Add query_members to channel
8
+ - Use post endpoint for query channels instead of get
9
+ - Extract common code for sorting into a helper for query calls
10
+
11
+ ## January 5th, 2021 - 2.3.0
12
+ - Add check SQS helper
13
+
14
+ ## January 4th, 2021 - 2.2.0
15
+ - Add support for export channels
16
+ - Improve readme for blocklist and export channels
17
+ - Improve running tests for multiple versions of ruby
18
+ - Fix issues from the latest version of rubocop
19
+ - Move to GitHub Actions
20
+
21
+ ## October 5th, 2020 - 2.1.0
22
+ - Add support for blocklist
23
+
1
24
  ## October 2nd, 2020 - 2.0.0
2
25
  - Drop EOL Ruby versions: 2.3 && 2.4
3
26
  - Setup Rubocop and mark string literals as frozen
@@ -12,13 +35,11 @@
12
35
  - Fixed few minor issues
13
36
 
14
37
  ## Oct 27th, 2019 - 1.1.0
15
-
16
38
  - Mark gems use for testing as development dependencies
17
39
  - Added `send_file`, `send_image`, `delete_file`, `delete_image`
18
40
  - Added `invite_members`
19
41
 
20
42
  ## Oct 19th, 2019 - 1.0.0
21
-
22
43
  - Added `channel.hide` and `channel.show`
23
44
  - Added `client.flag_message` and `client.unflag_message`
24
45
  - Added `client.flag_user` and `client.unflag_user`
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # stream-chat-ruby
2
2
 
3
- [![Build Status](https://travis-ci.com/GetStream/stream-chat-ruby.svg?branch=master)](https://travis-ci.com/GetStream/stream-chat-ruby) [![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
 
@@ -14,7 +14,7 @@ Android SDK libraries (https://getstream.io/chat/).
14
14
 
15
15
  stream-chat-ruby supports:
16
16
 
17
- - Ruby (2.6, 2.5, 2.4, 2.3)
17
+ - Ruby (2.7, 2.6, 2.5)
18
18
 
19
19
  #### Install
20
20
 
@@ -28,15 +28,16 @@ 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
37
36
  - User devices
38
37
  - User search
39
38
  - Channel search
39
+ - Blocklists
40
+ - Export channels
40
41
 
41
42
  ### Import
42
43
 
@@ -129,6 +130,17 @@ chan.unban_user('bob-1')
129
130
 
130
131
  # Query channel state
131
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)
132
144
  ```
133
145
 
134
146
  ### Messages
@@ -152,6 +164,31 @@ client.get_devices('jane-77')
152
164
  client.remove_device(jane_phone['id'], jane_phone['user_id'])
153
165
  ```
154
166
 
167
+ ### Blocklists
168
+ ```ruby
169
+ # Create a blocklist
170
+ client.create_blocklist('my_blocker', %w[fudge cream sugar])
171
+
172
+ # Enable it on messaging channel type
173
+ client.update_channel_type('messaging', blocklist: 'my_blocker', blocklist_behavior: 'block')
174
+
175
+ # Get the details of the blocklist
176
+ client.get_blocklist('my_blocker')
177
+
178
+ # Delete the blocklist
179
+ client.delete_blocklist('my_blocker')
180
+ ```
181
+
182
+ ### Export Channels
183
+ ```ruby
184
+ # Register an export
185
+ response = client.export_channels({type: 'messaging', id: 'jane'})
186
+
187
+ # Check completion
188
+ status_response = client.get_export_channel_status(response['task_id'])
189
+ # status_response['status'] == 'pending', 'completed'
190
+ ```
191
+
155
192
  ### Example Rails application
156
193
 
157
194
  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,8 +7,11 @@ 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
13
+ DEFAULT_BLOCKLIST = 'profanity_en_2020_v1'
14
+
12
15
  class Client
13
16
  BASE_URL = 'https://chat-us-east-1.stream-io-api.com'
14
17
 
@@ -57,22 +60,22 @@ module StreamChat
57
60
  end
58
61
 
59
62
  def flag_message(id, **options)
60
- payload = { 'target_message_id': id }.merge(options)
63
+ payload = { target_message_id: id }.merge(options)
61
64
  post('moderation/flag', data: payload)
62
65
  end
63
66
 
64
67
  def unflag_message(id, **options)
65
- payload = { 'target_message_id': id }.merge(options)
68
+ payload = { target_message_id: id }.merge(options)
66
69
  post('moderation/unflag', data: payload)
67
70
  end
68
71
 
69
72
  def flag_user(id, **options)
70
- payload = { 'target_user_id': id }.merge(options)
73
+ payload = { target_user_id: id }.merge(options)
71
74
  post('moderation/flag', data: payload)
72
75
  end
73
76
 
74
77
  def unflag_user(id, **options)
75
- payload = { 'target_user_id': id }.merge(options)
78
+ payload = { target_user_id: id }.merge(options)
76
79
  post('moderation/unflag', data: payload)
77
80
  end
78
81
 
@@ -82,11 +85,11 @@ module StreamChat
82
85
 
83
86
  def search(filter_conditions, query, **options)
84
87
  params = options.merge({
85
- "filter_conditions": filter_conditions,
86
- "query": query
88
+ filter_conditions: filter_conditions,
89
+ query: query
87
90
  })
88
91
 
89
- get('search', params: { "payload": params.to_json })
92
+ get('search', params: { payload: params.to_json })
90
93
  end
91
94
 
92
95
  def update_users(users)
@@ -97,7 +100,7 @@ module StreamChat
97
100
 
98
101
  payload[id] = user
99
102
  end
100
- post('users', data: { 'users': payload })
103
+ post('users', data: { users: payload })
101
104
  end
102
105
 
103
106
  def update_user(user)
@@ -105,7 +108,7 @@ module StreamChat
105
108
  end
106
109
 
107
110
  def update_users_partial(updates)
108
- patch('users', data: { 'users': updates })
111
+ patch('users', data: { users: updates })
109
112
  end
110
113
 
111
114
  def update_user_partial(update)
@@ -129,34 +132,34 @@ module StreamChat
129
132
  end
130
133
 
131
134
  def ban_user(target_id, **options)
132
- payload = { 'target_user_id': target_id }.merge(options)
135
+ payload = { target_user_id: target_id }.merge(options)
133
136
  post('moderation/ban', data: payload)
134
137
  end
135
138
 
136
139
  def unban_user(target_id, **options)
137
- params = { 'target_user_id': target_id }.merge(options)
140
+ params = { target_user_id: target_id }.merge(options)
138
141
  delete('moderation/ban', params: params)
139
142
  end
140
143
 
141
144
  def mute_user(target_id, user_id)
142
- payload = { 'target_id': target_id, 'user_id': user_id }
145
+ payload = { target_id: target_id, user_id: user_id }
143
146
  post('moderation/mute', data: payload)
144
147
  end
145
148
 
146
149
  def unmute_user(target_id, user_id)
147
- payload = { 'target_id': target_id, 'user_id': user_id }
150
+ payload = { target_id: target_id, user_id: user_id }
148
151
  post('moderation/unmute', data: payload)
149
152
  end
150
153
 
151
154
  def mark_all_read(user_id)
152
- payload = { 'user': { 'id': user_id } }
155
+ payload = { user: { id: user_id } }
153
156
  post('channels/read', data: payload)
154
157
  end
155
158
 
156
159
  def update_message(message)
157
160
  raise ArgumentError 'message must have an id' unless message.key? 'id'
158
161
 
159
- post("messages/#{message['id']}", data: { 'message': message })
162
+ post("messages/#{message['id']}", data: { message: message })
160
163
  end
161
164
 
162
165
  def delete_message(message_id)
@@ -164,28 +167,20 @@ module StreamChat
164
167
  end
165
168
 
166
169
  def query_users(filter_conditions, sort: nil, **options)
167
- sort_fields = []
168
- sort&.each do |k, v|
169
- sort_fields << { "field": k, "direction": v }
170
- end
171
170
  params = options.merge({
172
- "filter_conditions": filter_conditions,
173
- "sort": sort_fields
171
+ filter_conditions: filter_conditions,
172
+ sort: get_sort_fields(sort)
174
173
  })
175
- get('users', params: { "payload": params.to_json })
174
+ get('users', params: { payload: params.to_json })
176
175
  end
177
176
 
178
177
  def query_channels(filter_conditions, sort: nil, **options)
179
- params = { "state": true, "watch": false, "presence": false }
180
- sort_fields = []
181
- sort&.each do |k, v|
182
- sort_fields << { "field": k, "direction": v }
183
- end
184
- params = params.merge(options).merge({
185
- "filter_conditions": filter_conditions,
186
- "sort": sort_fields
187
- })
188
- get('channels', params: { "payload": params.to_json })
178
+ data = { state: true, watch: false, presence: false }
179
+ data = data.merge(options).merge({
180
+ filter_conditions: filter_conditions,
181
+ sort: get_sort_fields(sort)
182
+ })
183
+ post('channels', data: data)
189
184
  end
190
185
 
191
186
  def create_channel_type(data)
@@ -202,7 +197,7 @@ module StreamChat
202
197
  end
203
198
 
204
199
  def update_channel_type(channel_type, **options)
205
- put("channeltypes/#{channel_type}", **options)
200
+ put("channeltypes/#{channel_type}", data: options)
206
201
  end
207
202
 
208
203
  def delete_channel_type(channel_type)
@@ -223,18 +218,18 @@ module StreamChat
223
218
 
224
219
  def add_device(device_id, push_provider, user_id)
225
220
  post('devices', data: {
226
- "id": device_id,
227
- "push_provider": push_provider,
228
- "user_id": user_id
221
+ id: device_id,
222
+ push_provider: push_provider,
223
+ user_id: user_id
229
224
  })
230
225
  end
231
226
 
232
227
  def delete_device(device_id, user_id)
233
- delete('devices', params: { "id": device_id, "user_id": user_id })
228
+ delete('devices', params: { id: device_id, user_id: user_id })
234
229
  end
235
230
 
236
231
  def get_devices(user_id)
237
- get('devices', params: { "user_id": user_id })
232
+ get('devices', params: { user_id: user_id })
238
233
  end
239
234
 
240
235
  def verify_webhook(request_body, x_signature)
@@ -242,6 +237,34 @@ module StreamChat
242
237
  signature == x_signature
243
238
  end
244
239
 
240
+ def list_blocklists
241
+ get('blocklists')
242
+ end
243
+
244
+ def get_blocklist(name)
245
+ get("blocklists/#{name}")
246
+ end
247
+
248
+ def create_blocklist(name, words)
249
+ post('blocklists', data: { name: name, words: words })
250
+ end
251
+
252
+ def update_blocklist(name, words)
253
+ put("blocklists/#{name}", data: { words: words })
254
+ end
255
+
256
+ def delete_blocklist(name)
257
+ delete("blocklists/#{name}")
258
+ end
259
+
260
+ def export_channels(*channels)
261
+ post('export_channels', data: { channels: channels })
262
+ end
263
+
264
+ def get_export_channel_status(task_id)
265
+ get("export_channels/#{task_id}")
266
+ end
267
+
245
268
  def put(relative_url, params: nil, data: nil)
246
269
  make_http_request(:put, relative_url, params: params, data: data)
247
270
  end
@@ -281,6 +304,10 @@ module StreamChat
281
304
  parse_response(response)
282
305
  end
283
306
 
307
+ def check_sqs(sqs_key = nil, sqs_secret = nil, sqs_url = nil)
308
+ post('check_sqs', data: { sqs_key: sqs_key, sqs_secret: sqs_secret, sqs_url: sqs_url })
309
+ end
310
+
284
311
  private
285
312
 
286
313
  def get_default_params
@@ -314,7 +341,7 @@ module StreamChat
314
341
  headers['Authorization'] = @auth_token
315
342
  headers['stream-auth-type'] = 'jwt'
316
343
  url = [@base_url, relative_url].join('/')
317
- params = !params.nil? ? params : {}
344
+ params = params.nil? ? {} : params
318
345
  params = Hash[get_default_params.merge(params).sort_by { |k, _v| k.to_s }]
319
346
  url = "#{url}?#{URI.encode_www_form(params)}"
320
347
 
@@ -26,5 +26,6 @@ module StreamChat
26
26
  end
27
27
  end
28
28
  end
29
+
29
30
  class StreamChannelException < StandardError; end
30
31
  end
@@ -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.0.0'
6
+ VERSION = '2.5.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.0.0
4
+ version: 2.5.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: 2020-10-05 00:00:00.000000000 Z
11
+ date: 2021-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -86,9 +86,9 @@ executables: []
86
86
  extensions: []
87
87
  extra_rdoc_files: []
88
88
  files:
89
+ - ".github/workflows/ci.yml"
89
90
  - ".gitignore"
90
91
  - ".rubocop.yml"
91
- - ".travis.yml"
92
92
  - CHANGELOG.md
93
93
  - Gemfile
94
94
  - LICENSE
@@ -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
data/.travis.yml DELETED
@@ -1,10 +0,0 @@
1
- language: ruby
2
- before_install:
3
- - gem update bundler
4
- rvm:
5
- - 2.5
6
- - 2.6
7
- - 2.7
8
- script:
9
- - bundle exec rake rubocop
10
- - bundle exec rake test