stream-chat-ruby 2.5.0 → 2.11.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: cff8888b576ad92ca17c3275504e585b1490e3935e7d86595aad795dfea67a7d
4
- data.tar.gz: 8aa309ce84be59f966edee13e0e8957f863f59c535bc8df9d41d90484e8b1cb5
3
+ metadata.gz: 99eb51b056c6265c10b7452897fef2ac5691def3e80819692c7755574b7e7672
4
+ data.tar.gz: 644d0384df490767e94588f1f76b0f0f0bd5012a1dfb9b2490c375e67dd6eacf
5
5
  SHA512:
6
- metadata.gz: 9ca7b965ba2ca2fdffcb3ff667d93a1081e5aa15f40d3aeb9a167c945f26e54d3e773e826ca583c445c0da02acb5f67f3c450d7fc3fce98fcb958acd7e9077cf
7
- data.tar.gz: 98b040deb4906b952d393244fb228843e77d669481104fa0ca75512cdcaacfccd75d8733c9ade31854366ab066ff6c58a54d2ff3c89e6c590d5a8c9fdc17c888
6
+ metadata.gz: f172bdeebb0ddde0b55827be7f20ab72af074782ea2af5db7ad0bbda97f6d6abbc8b83e3098fdb34eb5b4312018320df42463a9a7ecc20afec370c8daefb0c0b
7
+ data.tar.gz: 70e907012a5fe56e57b5ec52a76a5ab24dfef914afe27e82eee6c47f22d701354ee2ba1bd057cb00da0dcc39f71d4a0edfcf70a60020aa3215f3aa6fa2907923
@@ -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
@@ -18,7 +19,6 @@ jobs:
18
19
  - env:
19
20
  STREAM_CHAT_API_KEY: ${{ secrets.STREAM_CHAT_API_KEY }}
20
21
  STREAM_CHAT_API_SECRET: ${{ secrets.STREAM_CHAT_API_SECRET }}
21
- BLOCKLIST: ${{ matrix.ruby == '2.7' }}
22
22
  run: |
23
23
  gem install bundler
24
24
  bundle install --jobs 4 --retry 3
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,17 +1,46 @@
1
+ ## June 25th, 2021 - 2.11.0
2
+
3
+ - Add support for improved search
4
+
5
+ ## June 4th, 2021 - 2.10.0
6
+
7
+ - Add custom command CRUD support
8
+
9
+ ## May 31st, 2021 - 2.9.0
10
+
11
+ - Add support for app and user level token revoke
12
+
13
+ ## May 21st, 2021 - 2.8.0
14
+
15
+ - Add query message flags support
16
+
17
+ ## March 17th, 2021 - 2.7.0
18
+
19
+ - Add Ruby 3.x support
20
+ - Update CI to run all tests for all versions
21
+
22
+ ## March 9th, 2021 - 2.6.0
23
+
24
+ - Add get_rate_limits endpoint
25
+
1
26
  ## February 3rd, 2021 - 2.5.0
27
+
2
28
  - Add channel partial update
3
29
  - Increase convenience in query members
4
30
  - Improve internal symbol conversions
5
31
 
6
32
  ## January 20th, 2021 - 2.4.0
33
+
7
34
  - Add query_members to channel
8
35
  - Use post endpoint for query channels instead of get
9
36
  - Extract common code for sorting into a helper for query calls
10
37
 
11
38
  ## January 5th, 2021 - 2.3.0
39
+
12
40
  - Add check SQS helper
13
41
 
14
42
  ## January 4th, 2021 - 2.2.0
43
+
15
44
  - Add support for export channels
16
45
  - Improve readme for blocklist and export channels
17
46
  - Improve running tests for multiple versions of ruby
@@ -19,27 +48,34 @@
19
48
  - Move to GitHub Actions
20
49
 
21
50
  ## October 5th, 2020 - 2.1.0
51
+
22
52
  - Add support for blocklist
23
53
 
24
54
  ## October 2nd, 2020 - 2.0.0
55
+
25
56
  - Drop EOL Ruby versions: 2.3 && 2.4
26
57
  - Setup Rubocop and mark string literals as frozen
27
58
 
28
59
  ## August 3rd, 2020 - 1.1.3
60
+
29
61
  - Fixed Argument Error on delete_user
30
62
 
31
63
  ## April 23th, 2020 - 1.1.2
64
+
32
65
  - Fixed ArgumentError when no users was passed
33
66
 
34
67
  ## March 30th, 2020 - 1.1.1
68
+
35
69
  - Fixed few minor issues
36
70
 
37
71
  ## Oct 27th, 2019 - 1.1.0
72
+
38
73
  - Mark gems use for testing as development dependencies
39
74
  - Added `send_file`, `send_image`, `delete_file`, `delete_image`
40
75
  - Added `invite_members`
41
76
 
42
77
  ## Oct 19th, 2019 - 1.0.0
78
+
43
79
  - Added `channel.hide` and `channel.show`
44
80
  - Added `client.flag_message` and `client.unflag_message`
45
81
  - Added `client.flag_user` and `client.unflag_user`
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
 
@@ -165,6 +165,7 @@ client.remove_device(jane_phone['id'], jane_phone['user_id'])
165
165
  ```
166
166
 
167
167
  ### Blocklists
168
+
168
169
  ```ruby
169
170
  # Create a blocklist
170
171
  client.create_blocklist('my_blocker', %w[fudge cream sugar])
@@ -180,6 +181,7 @@ client.delete_blocklist('my_blocker')
180
181
  ```
181
182
 
182
183
  ### Export Channels
184
+
183
185
  ```ruby
184
186
  # Register an export
185
187
  response = client.export_channels({type: 'messaging', id: 'jane'})
@@ -189,6 +191,19 @@ status_response = client.get_export_channel_status(response['task_id'])
189
191
  # status_response['status'] == 'pending', 'completed'
190
192
  ```
191
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
+
192
207
  ### Example Rails application
193
208
 
194
209
  See [an example rails application using the Ruby SDK](https://github.com/GetStream/rails-chat-example).
@@ -4,6 +4,7 @@
4
4
  require 'open-uri'
5
5
  require 'faraday'
6
6
  require 'jwt'
7
+ require 'time'
7
8
  require 'stream-chat/channel'
8
9
  require 'stream-chat/errors'
9
10
  require 'stream-chat/version'
@@ -45,9 +46,10 @@ module StreamChat
45
46
  end
46
47
  end
47
48
 
48
- def create_token(user_id, exp = nil)
49
+ def create_token(user_id, exp = nil, iat = nil)
49
50
  payload = { user_id: user_id }
50
51
  payload['exp'] = exp unless exp.nil?
52
+ payload['iat'] = iat unless iat.nil?
51
53
  JWT.encode(payload, @api_secret, 'HS256')
52
54
  end
53
55
 
@@ -69,6 +71,13 @@ module StreamChat
69
71
  post('moderation/unflag', data: payload)
70
72
  end
71
73
 
74
+ def query_message_flags(filter_conditions, **options)
75
+ params = options.merge({
76
+ filter_conditions: filter_conditions
77
+ })
78
+ get('moderation/flags/message', params: { payload: params.to_json })
79
+ end
80
+
72
81
  def flag_user(id, **options)
73
82
  payload = { target_user_id: id }.merge(options)
74
83
  post('moderation/flag', data: payload)
@@ -83,13 +92,21 @@ module StreamChat
83
92
  get("messages/#{id}")
84
93
  end
85
94
 
86
- def search(filter_conditions, query, **options)
87
- params = options.merge({
88
- filter_conditions: filter_conditions,
89
- query: query
90
- })
95
+ def search(filter_conditions, query, sort: nil, **options)
96
+ offset = options[:offset]
97
+ next_value = options[:next]
98
+ raise ArgumentError, 'cannot use offset with next or sort parameters' if offset&.positive? && (next_value || (!sort.nil? && !sort.empty?))
91
99
 
92
- get('search', params: { payload: params.to_json })
100
+ to_merge = {
101
+ filter_conditions: filter_conditions,
102
+ sort: get_sort_fields(sort)
103
+ }
104
+ if query.is_a? String
105
+ to_merge[:query] = query
106
+ else
107
+ to_merge[:message_filter_conditions] = query
108
+ end
109
+ get('search', params: { payload: options.merge(to_merge).to_json })
93
110
  end
94
111
 
95
112
  def update_users(users)
@@ -232,6 +249,17 @@ module StreamChat
232
249
  get('devices', params: { user_id: user_id })
233
250
  end
234
251
 
252
+ def get_rate_limits(server_side: false, android: false, ios: false, web: false, endpoints: [])
253
+ params = {}
254
+ params['server_side'] = server_side if server_side
255
+ params['android'] = android if android
256
+ params['ios'] = ios if ios
257
+ params['web'] = web if web
258
+ params['endpoints'] = endpoints.join(',') unless endpoints.empty?
259
+
260
+ get('rate_limits', params: params)
261
+ end
262
+
235
263
  def verify_webhook(request_body, x_signature)
236
264
  signature = OpenSSL::HMAC.hexdigest('SHA256', @api_secret, request_body)
237
265
  signature == x_signature
@@ -265,6 +293,30 @@ module StreamChat
265
293
  get("export_channels/#{task_id}")
266
294
  end
267
295
 
296
+ def revoke_tokens(before)
297
+ before = before.rfc3339 if before.instance_of?(DateTime)
298
+ update_app_settings({ 'revoke_tokens_issued_before' => before })
299
+ end
300
+
301
+ def revoke_user_token(user_id, before)
302
+ revoke_users_token([user_id], before)
303
+ end
304
+
305
+ def revoke_users_token(user_ids, before)
306
+ before = before.rfc3339 if before.instance_of?(DateTime)
307
+
308
+ updates = []
309
+ user_ids.each do |user_id|
310
+ updates.push({
311
+ 'id' => user_id,
312
+ 'set' => {
313
+ 'revoke_tokens_issued_before' => before
314
+ }
315
+ })
316
+ end
317
+ update_users_partial(updates)
318
+ end
319
+
268
320
  def put(relative_url, params: nil, data: nil)
269
321
  make_http_request(:put, relative_url, params: params, data: data)
270
322
  end
@@ -308,6 +360,26 @@ module StreamChat
308
360
  post('check_sqs', data: { sqs_key: sqs_key, sqs_secret: sqs_secret, sqs_url: sqs_url })
309
361
  end
310
362
 
363
+ def create_command(command)
364
+ post('commands', data: command)
365
+ end
366
+
367
+ def get_command(name)
368
+ get("commands/#{name}")
369
+ end
370
+
371
+ def update_command(name, command)
372
+ put("commands/#{name}", data: command)
373
+ end
374
+
375
+ def delete_command(name)
376
+ delete("commands/#{name}")
377
+ end
378
+
379
+ def list_commands
380
+ get('commands')
381
+ end
382
+
311
383
  private
312
384
 
313
385
  def get_default_params
@@ -320,8 +392,8 @@ module StreamChat
320
392
 
321
393
  def get_default_headers
322
394
  {
323
- "Content-Type": 'application/json',
324
- "X-Stream-Client": get_user_agent
395
+ 'Content-Type': 'application/json',
396
+ 'X-Stream-Client': get_user_agent
325
397
  }
326
398
  end
327
399
 
@@ -342,7 +414,7 @@ module StreamChat
342
414
  headers['stream-auth-type'] = 'jwt'
343
415
  url = [@base_url, relative_url].join('/')
344
416
  params = params.nil? ? {} : params
345
- params = Hash[get_default_params.merge(params).sort_by { |k, _v| k.to_s }]
417
+ params = (get_default_params.merge(params).sort_by { |k, _v| k.to_s }).to_h
346
418
  url = "#{url}?#{URI.encode_www_form(params)}"
347
419
 
348
420
  body = data.to_json if %w[patch post put].include? method.to_s
@@ -3,5 +3,5 @@
3
3
  # lib/version.rb
4
4
 
5
5
  module StreamChat
6
- VERSION = '2.5.0'
6
+ VERSION = '2.11.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.5.0
4
+ version: 2.11.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-02-02 00:00:00.000000000 Z
11
+ date: 2021-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday