stream-chat-ruby 1.1.3 → 2.4.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 +4 -4
- data/.github/workflows/ci.yml +25 -0
- data/.rubocop.yml +34 -0
- data/CHANGELOG.md +22 -2
- data/Gemfile +9 -7
- data/README.md +33 -4
- data/Rakefile +9 -3
- data/lib/stream-chat.rb +2 -0
- data/lib/stream-chat/channel.rb +47 -34
- data/lib/stream-chat/client.rb +102 -86
- data/lib/stream-chat/errors.rb +6 -3
- data/lib/stream-chat/util.rb +11 -0
- data/lib/stream-chat/version.rb +3 -1
- data/stream-chat.gemspec +5 -2
- metadata +6 -4
- data/.travis.yml +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea550365bc302aeb9097c2f2819a0dd6c5ead1fd1064a7c12842de4670e871d4
|
4
|
+
data.tar.gz: b01a528a334338edfd9f05e8f3aa40e682cabd3de40e6356b162f9f0cc791e64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f12aa7bec1853b9a91e3b9a63a6f296aca373bb8f24a719a0728959e68cbe10e4b440bc7056d730bfa36f3e2a0c5c1b4db1b566cc51159a09bad3eac4694747
|
7
|
+
data.tar.gz: 9982645b54641b15fd7d8deae0049d90aca66defcaba509e19be7f0c27dfd42fec8bba5221b0ca961251fc8c084c61a1793fcc689df853ae09a570b0358ac605
|
@@ -0,0 +1,25 @@
|
|
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
|
+
run: |
|
22
|
+
gem install bundler
|
23
|
+
bundle install --jobs 4 --retry 3
|
24
|
+
bundle exec rake rubocop
|
25
|
+
bundle exec rake test
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
AllCops:
|
2
|
+
DisabledByDefault: false
|
3
|
+
NewCops: enable
|
4
|
+
TargetRubyVersion: 2.5
|
5
|
+
|
6
|
+
Layout/LineLength:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Lint/RedundantCopDisableDirective:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Metrics/AbcSize:
|
13
|
+
Enabled: false
|
14
|
+
Metrics/BlockLength:
|
15
|
+
Enabled: false
|
16
|
+
Metrics/ClassLength:
|
17
|
+
Enabled: false
|
18
|
+
Metrics/MethodLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Naming/AccessorMethodName:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Security/Open:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Style/AccessorGrouping:
|
28
|
+
Enabled: false
|
29
|
+
Style/Documentation:
|
30
|
+
Enabled: false
|
31
|
+
Style/DoubleCopDisableDirective:
|
32
|
+
Enabled: false
|
33
|
+
Style/FrozenStringLiteralComment:
|
34
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
## January 20th, 2021 - 2.4.0
|
2
|
+
- Add query_members to channel
|
3
|
+
- Use post endpoint for query channels instead of get
|
4
|
+
- Extract common code for sorting into a helper for query calls
|
5
|
+
|
6
|
+
## January 5th, 2021 - 2.3.0
|
7
|
+
- Add check SQS helper
|
8
|
+
|
9
|
+
## January 4th, 2021 - 2.2.0
|
10
|
+
- Add support for export channels
|
11
|
+
- Improve readme for blocklist and export channels
|
12
|
+
- Improve running tests for multiple versions of ruby
|
13
|
+
- Fix issues from the latest version of rubocop
|
14
|
+
- Move to GitHub Actions
|
15
|
+
|
16
|
+
## October 5th, 2020 - 2.1.0
|
17
|
+
- Add support for blocklist
|
18
|
+
|
19
|
+
## October 2nd, 2020 - 2.0.0
|
20
|
+
- Drop EOL Ruby versions: 2.3 && 2.4
|
21
|
+
- Setup Rubocop and mark string literals as frozen
|
22
|
+
|
1
23
|
## August 3rd, 2020 - 1.1.3
|
2
24
|
- Fixed Argument Error on delete_user
|
3
25
|
|
@@ -8,13 +30,11 @@
|
|
8
30
|
- Fixed few minor issues
|
9
31
|
|
10
32
|
## Oct 27th, 2019 - 1.1.0
|
11
|
-
|
12
33
|
- Mark gems use for testing as development dependencies
|
13
34
|
- Added `send_file`, `send_image`, `delete_file`, `delete_image`
|
14
35
|
- Added `invite_members`
|
15
36
|
|
16
37
|
## Oct 19th, 2019 - 1.0.0
|
17
|
-
|
18
38
|
- Added `channel.hide` and `channel.show`
|
19
39
|
- Added `client.flag_message` and `client.unflag_message`
|
20
40
|
- Added `client.flag_user` and `client.unflag_user`
|
data/Gemfile
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
gemspec
|
4
6
|
|
5
7
|
group :dev do
|
6
|
-
gem
|
7
|
-
gem
|
8
|
-
gem
|
8
|
+
gem 'method_source'
|
9
|
+
gem 'pry'
|
10
|
+
gem 'pry-doc'
|
11
|
+
gem 'rubocop', require: false
|
9
12
|
end
|
10
13
|
|
11
14
|
group :test do
|
12
|
-
gem
|
13
|
-
gem
|
14
|
-
gem
|
15
|
+
gem 'faraday'
|
16
|
+
gem 'rack'
|
17
|
+
gem 'simplecov'
|
15
18
|
end
|
16
|
-
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# stream-chat-ruby
|
2
2
|
|
3
|
-
[](https://github.com/GetStream/stream-chat-ruby/actions) [](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.
|
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,9 @@ 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
|
+
# Query channel members
|
135
|
+
chan.query_members({name: {'$autocomplete': 'test'}}, {last_created_at: -1}, offset: 5, limit: 5)
|
132
136
|
```
|
133
137
|
|
134
138
|
### Messages
|
@@ -152,6 +156,31 @@ client.get_devices('jane-77')
|
|
152
156
|
client.remove_device(jane_phone['id'], jane_phone['user_id'])
|
153
157
|
```
|
154
158
|
|
159
|
+
### Blocklists
|
160
|
+
```ruby
|
161
|
+
# Create a blocklist
|
162
|
+
client.create_blocklist('my_blocker', %w[fudge cream sugar])
|
163
|
+
|
164
|
+
# Enable it on messaging channel type
|
165
|
+
client.update_channel_type('messaging', blocklist: 'my_blocker', blocklist_behavior: 'block')
|
166
|
+
|
167
|
+
# Get the details of the blocklist
|
168
|
+
client.get_blocklist('my_blocker')
|
169
|
+
|
170
|
+
# Delete the blocklist
|
171
|
+
client.delete_blocklist('my_blocker')
|
172
|
+
```
|
173
|
+
|
174
|
+
### Export Channels
|
175
|
+
```ruby
|
176
|
+
# Register an export
|
177
|
+
response = client.export_channels({type: 'messaging', id: 'jane'})
|
178
|
+
|
179
|
+
# Check completion
|
180
|
+
status_response = client.get_export_channel_status(response['task_id'])
|
181
|
+
# status_response['status'] == 'pending', 'completed'
|
182
|
+
```
|
183
|
+
|
155
184
|
### Example Rails application
|
156
185
|
|
157
186
|
See [an example rails application using the Ruby SDK](https://github.com/GetStream/rails-chat-example).
|
data/Rakefile
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/gem_tasks'
|
2
4
|
# rake spec
|
3
5
|
require 'rspec/core/rake_task'
|
4
|
-
RSpec::Core::RakeTask.new(:spec) { |t| t.verbose = false
|
6
|
+
RSpec::Core::RakeTask.new(:spec) { |t| t.verbose = false }
|
5
7
|
|
6
8
|
# rake console
|
7
9
|
task :console do
|
@@ -11,6 +13,10 @@ task :console do
|
|
11
13
|
Pry.start
|
12
14
|
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
+
require 'rubocop/rake_task'
|
17
|
+
RuboCop::RakeTask.new(:rubocop) do |t|
|
18
|
+
t.options = ['--display-cop-names']
|
19
|
+
end
|
16
20
|
|
21
|
+
task default: [:spec]
|
22
|
+
task test: [:spec]
|
data/lib/stream-chat.rb
CHANGED
data/lib/stream-chat/channel.rb
CHANGED
@@ -1,72 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'stream-chat/errors'
|
4
|
+
require 'stream-chat/util'
|
2
5
|
|
3
6
|
module StreamChat
|
4
|
-
|
5
|
-
class Channel
|
7
|
+
class Channel # rubocop:todo Metrics/ClassLength # rubocop:todo Style/Documentation
|
6
8
|
attr_reader :id
|
7
9
|
attr_reader :channel_type
|
8
10
|
attr_reader :custom_data
|
11
|
+
attr_reader :members
|
9
12
|
|
10
|
-
def initialize(client, channel_type, channel_id=nil, custom_data=nil)
|
13
|
+
def initialize(client, channel_type, channel_id = nil, custom_data = nil)
|
11
14
|
@channel_type = channel_type
|
12
15
|
@id = channel_id
|
13
16
|
@client = client
|
14
17
|
@custom_data = custom_data
|
15
|
-
if @custom_data
|
16
|
-
@custom_data = {}
|
17
|
-
end
|
18
|
+
@custom_data = {} if @custom_data.nil?
|
18
19
|
end
|
19
20
|
|
20
21
|
def url
|
21
|
-
if @id
|
22
|
-
|
23
|
-
end
|
22
|
+
raise StreamChannelException 'channel does not have an id' if @id.nil?
|
23
|
+
|
24
24
|
"channels/#{@channel_type}/#{@id}"
|
25
25
|
end
|
26
26
|
|
27
27
|
def send_message(message, user_id)
|
28
|
-
payload = {"message": add_user_id(message, user_id)}
|
28
|
+
payload = { "message": add_user_id(message, user_id) }
|
29
29
|
@client.post("#{url}/message", data: payload)
|
30
30
|
end
|
31
31
|
|
32
32
|
def send_event(event, user_id)
|
33
|
-
payload = {'event' => add_user_id(event, user_id)}
|
33
|
+
payload = { 'event' => add_user_id(event, user_id) }
|
34
34
|
@client.post("#{url}/event", data: payload)
|
35
35
|
end
|
36
36
|
|
37
37
|
def send_reaction(message_id, reaction, user_id)
|
38
|
-
payload = {"reaction": add_user_id(reaction, user_id)}
|
38
|
+
payload = { "reaction": add_user_id(reaction, user_id) }
|
39
39
|
@client.post("messages/#{message_id}/reaction", data: payload)
|
40
40
|
end
|
41
41
|
|
42
42
|
def delete_reaction(message_id, reaction_type, user_id)
|
43
43
|
@client.delete(
|
44
44
|
"messages/#{message_id}/reaction/#{reaction_type}",
|
45
|
-
params: {"user_id": user_id}
|
45
|
+
params: { "user_id": user_id }
|
46
46
|
)
|
47
47
|
end
|
48
48
|
|
49
49
|
def create(user_id)
|
50
|
-
@custom_data[
|
50
|
+
@custom_data['created_by'] = { "id": user_id }
|
51
51
|
query(watch: false, state: false, presence: false)
|
52
52
|
end
|
53
53
|
|
54
54
|
def query(**options)
|
55
|
-
payload = {"state": true, "data": @custom_data}.merge(options)
|
55
|
+
payload = { "state": true, "data": @custom_data }.merge(options)
|
56
56
|
url = "channels/#{@channel_type}"
|
57
|
-
|
58
|
-
url = "#{url}/#{@id}"
|
59
|
-
end
|
57
|
+
url = "#{url}/#{@id}" unless @id.nil?
|
60
58
|
|
61
59
|
state = @client.post("#{url}/query", data: payload)
|
62
|
-
if @id
|
63
|
-
@id = state["channel"]["id"]
|
64
|
-
end
|
60
|
+
@id = state['channel']['id'] if @id.nil?
|
65
61
|
state
|
66
62
|
end
|
67
63
|
|
68
|
-
def
|
69
|
-
|
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
|
+
|
82
|
+
def update(channel_data, update_message = nil)
|
83
|
+
payload = { "data": channel_data, "message": update_message }
|
70
84
|
@client.post(url, data: payload)
|
71
85
|
end
|
72
86
|
|
@@ -79,23 +93,23 @@ module StreamChat
|
|
79
93
|
end
|
80
94
|
|
81
95
|
def add_members(user_ids)
|
82
|
-
@client.post(url, data: {"add_members": user_ids})
|
96
|
+
@client.post(url, data: { "add_members": user_ids })
|
83
97
|
end
|
84
98
|
|
85
99
|
def invite_members(user_ids)
|
86
|
-
@client.post(url, data: {"invites": user_ids})
|
100
|
+
@client.post(url, data: { "invites": user_ids })
|
87
101
|
end
|
88
102
|
|
89
103
|
def add_moderators(user_ids)
|
90
|
-
@client.post(url, data: {"add_moderators": user_ids})
|
104
|
+
@client.post(url, data: { "add_moderators": user_ids })
|
91
105
|
end
|
92
106
|
|
93
107
|
def remove_members(user_ids)
|
94
|
-
@client.post(url, data: {"remove_members": user_ids})
|
108
|
+
@client.post(url, data: { "remove_members": user_ids })
|
95
109
|
end
|
96
110
|
|
97
111
|
def demote_moderators(user_ids)
|
98
|
-
@client.post(url, data: {"demote_moderators": user_ids})
|
112
|
+
@client.post(url, data: { "demote_moderators": user_ids })
|
99
113
|
end
|
100
114
|
|
101
115
|
def mark_read(user_id, **options)
|
@@ -120,11 +134,11 @@ module StreamChat
|
|
120
134
|
end
|
121
135
|
|
122
136
|
def hide(user_id)
|
123
|
-
@client.post("#{url}/hide", data: {user_id: user_id})
|
137
|
+
@client.post("#{url}/hide", data: { user_id: user_id })
|
124
138
|
end
|
125
139
|
|
126
140
|
def show(user_id)
|
127
|
-
@client.post("#{url}/show", data: {user_id: user_id})
|
141
|
+
@client.post("#{url}/show", data: { user_id: user_id })
|
128
142
|
end
|
129
143
|
|
130
144
|
def send_file(url, user, content_type = nil)
|
@@ -136,18 +150,17 @@ module StreamChat
|
|
136
150
|
end
|
137
151
|
|
138
152
|
def delete_file(url)
|
139
|
-
@client.delete("#{self.url}/file", params: {"url": url})
|
153
|
+
@client.delete("#{self.url}/file", params: { "url": url })
|
140
154
|
end
|
141
155
|
|
142
156
|
def delete_image(url)
|
143
|
-
@client.delete("#{self.url}/image", params: {"url": url})
|
157
|
+
@client.delete("#{self.url}/image", params: { "url": url })
|
144
158
|
end
|
145
159
|
|
146
160
|
private
|
147
161
|
|
148
162
|
def add_user_id(payload, user_id)
|
149
|
-
payload.merge({"user": {"id": user_id}})
|
163
|
+
payload.merge({ "user": { "id": user_id } })
|
150
164
|
end
|
151
|
-
|
152
165
|
end
|
153
166
|
end
|
data/lib/stream-chat/client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# lib/client.rb
|
2
4
|
require 'open-uri'
|
3
5
|
require 'faraday'
|
@@ -5,8 +7,11 @@ require 'jwt'
|
|
5
7
|
require 'stream-chat/channel'
|
6
8
|
require 'stream-chat/errors'
|
7
9
|
require 'stream-chat/version'
|
10
|
+
require 'stream-chat/util'
|
8
11
|
|
9
12
|
module StreamChat
|
13
|
+
DEFAULT_BLOCKLIST = 'profanity_en_2020_v1'
|
14
|
+
|
10
15
|
class Client
|
11
16
|
BASE_URL = 'https://chat-us-east-1.stream-io-api.com'
|
12
17
|
|
@@ -30,7 +35,7 @@ module StreamChat
|
|
30
35
|
@api_secret = api_secret
|
31
36
|
@timeout = timeout
|
32
37
|
@options = options
|
33
|
-
@auth_token = JWT.encode({server: true}, @api_secret, 'HS256')
|
38
|
+
@auth_token = JWT.encode({ server: true }, @api_secret, 'HS256')
|
34
39
|
@base_url = options[:base_url] || BASE_URL
|
35
40
|
@conn = Faraday.new(url: @base_url) do |faraday|
|
36
41
|
faraday.options[:open_timeout] = @timeout
|
@@ -41,10 +46,8 @@ module StreamChat
|
|
41
46
|
end
|
42
47
|
|
43
48
|
def create_token(user_id, exp = nil)
|
44
|
-
payload = {user_id: user_id}
|
45
|
-
|
46
|
-
payload['exp'] = exp
|
47
|
-
end
|
49
|
+
payload = { user_id: user_id }
|
50
|
+
payload['exp'] = exp unless exp.nil?
|
48
51
|
JWT.encode(payload, @api_secret, 'HS256')
|
49
52
|
end
|
50
53
|
|
@@ -57,23 +60,23 @@ module StreamChat
|
|
57
60
|
end
|
58
61
|
|
59
62
|
def flag_message(id, **options)
|
60
|
-
payload = {'target_message_id': id}.merge(options)
|
61
|
-
post(
|
63
|
+
payload = { 'target_message_id': id }.merge(options)
|
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)
|
66
|
-
post(
|
68
|
+
payload = { 'target_message_id': id }.merge(options)
|
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)
|
71
|
-
post(
|
73
|
+
payload = { 'target_user_id': id }.merge(options)
|
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)
|
76
|
-
post(
|
78
|
+
payload = { 'target_user_id': id }.merge(options)
|
79
|
+
post('moderation/unflag', data: payload)
|
77
80
|
end
|
78
81
|
|
79
82
|
def get_message(id)
|
@@ -82,21 +85,22 @@ module StreamChat
|
|
82
85
|
|
83
86
|
def search(filter_conditions, query, **options)
|
84
87
|
params = options.merge({
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
+
"filter_conditions": filter_conditions,
|
89
|
+
"query": query
|
90
|
+
})
|
88
91
|
|
89
|
-
get(
|
92
|
+
get('search', params: { "payload": params.to_json })
|
90
93
|
end
|
91
94
|
|
92
95
|
def update_users(users)
|
93
96
|
payload = {}
|
94
97
|
users.each do |user|
|
95
|
-
id = user[:id] || user[
|
96
|
-
raise ArgumentError,
|
98
|
+
id = user[:id] || user['id']
|
99
|
+
raise ArgumentError, 'user must have an id' unless id
|
100
|
+
|
97
101
|
payload[id] = user
|
98
102
|
end
|
99
|
-
post('users', data: {'users': payload})
|
103
|
+
post('users', data: { 'users': payload })
|
100
104
|
end
|
101
105
|
|
102
106
|
def update_user(user)
|
@@ -104,7 +108,7 @@ module StreamChat
|
|
104
108
|
end
|
105
109
|
|
106
110
|
def update_users_partial(updates)
|
107
|
-
patch('users', data: {'users': updates})
|
111
|
+
patch('users', data: { 'users': updates })
|
108
112
|
end
|
109
113
|
|
110
114
|
def update_user_partial(update)
|
@@ -128,35 +132,34 @@ module StreamChat
|
|
128
132
|
end
|
129
133
|
|
130
134
|
def ban_user(target_id, **options)
|
131
|
-
payload = {'target_user_id': target_id}.merge(options)
|
132
|
-
post(
|
135
|
+
payload = { 'target_user_id': target_id }.merge(options)
|
136
|
+
post('moderation/ban', data: payload)
|
133
137
|
end
|
134
138
|
|
135
139
|
def unban_user(target_id, **options)
|
136
|
-
params = {'target_user_id': target_id}.merge(options)
|
137
|
-
delete(
|
140
|
+
params = { 'target_user_id': target_id }.merge(options)
|
141
|
+
delete('moderation/ban', params: params)
|
138
142
|
end
|
139
143
|
|
140
144
|
def mute_user(target_id, user_id)
|
141
|
-
payload = {'target_id': target_id, 'user_id': user_id}
|
145
|
+
payload = { 'target_id': target_id, 'user_id': user_id }
|
142
146
|
post('moderation/mute', data: payload)
|
143
147
|
end
|
144
148
|
|
145
149
|
def unmute_user(target_id, user_id)
|
146
|
-
payload = {'target_id': target_id, 'user_id': user_id}
|
150
|
+
payload = { 'target_id': target_id, 'user_id': user_id }
|
147
151
|
post('moderation/unmute', data: payload)
|
148
152
|
end
|
149
153
|
|
150
154
|
def mark_all_read(user_id)
|
151
|
-
payload = {'user': {'id': user_id}}
|
155
|
+
payload = { 'user': { 'id': user_id } }
|
152
156
|
post('channels/read', data: payload)
|
153
157
|
end
|
154
158
|
|
155
159
|
def update_message(message)
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
post("messages/#{message['id']}", data: {'message': message})
|
160
|
+
raise ArgumentError 'message must have an id' unless message.key? 'id'
|
161
|
+
|
162
|
+
post("messages/#{message['id']}", data: { 'message': message })
|
160
163
|
end
|
161
164
|
|
162
165
|
def delete_message(message_id)
|
@@ -164,39 +167,25 @@ module StreamChat
|
|
164
167
|
end
|
165
168
|
|
166
169
|
def query_users(filter_conditions, sort: nil, **options)
|
167
|
-
sort_fields = []
|
168
|
-
if sort != nil
|
169
|
-
sort.each do |k ,v|
|
170
|
-
sort_fields << {"field": k, "direction": v}
|
171
|
-
end
|
172
|
-
end
|
173
170
|
params = options.merge({
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
get(
|
171
|
+
"filter_conditions": filter_conditions,
|
172
|
+
"sort": get_sort_fields(sort)
|
173
|
+
})
|
174
|
+
get('users', params: { "payload": params.to_json })
|
178
175
|
end
|
179
176
|
|
180
177
|
def query_channels(filter_conditions, sort: nil, **options)
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
end
|
188
|
-
params = params.merge(options).merge({
|
189
|
-
"filter_conditions": filter_conditions,
|
190
|
-
"sort": sort_fields
|
191
|
-
})
|
192
|
-
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)
|
193
184
|
end
|
194
185
|
|
195
186
|
def create_channel_type(data)
|
196
|
-
|
197
|
-
|
198
|
-
end
|
199
|
-
post("channeltypes", data: data)
|
187
|
+
data['commands'] = ['all'] unless data.key?('commands') || data['commands'].nil? || data['commands'].empty?
|
188
|
+
post('channeltypes', data: data)
|
200
189
|
end
|
201
190
|
|
202
191
|
def get_channel_type(channel_type)
|
@@ -204,11 +193,11 @@ module StreamChat
|
|
204
193
|
end
|
205
194
|
|
206
195
|
def list_channel_types
|
207
|
-
get(
|
196
|
+
get('channeltypes')
|
208
197
|
end
|
209
198
|
|
210
199
|
def update_channel_type(channel_type, **options)
|
211
|
-
put("channeltypes/#{channel_type}",
|
200
|
+
put("channeltypes/#{channel_type}", data: options)
|
212
201
|
end
|
213
202
|
|
214
203
|
def delete_channel_type(channel_type)
|
@@ -228,26 +217,54 @@ module StreamChat
|
|
228
217
|
end
|
229
218
|
|
230
219
|
def add_device(device_id, push_provider, user_id)
|
231
|
-
post(
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
220
|
+
post('devices', data: {
|
221
|
+
"id": device_id,
|
222
|
+
"push_provider": push_provider,
|
223
|
+
"user_id": user_id
|
224
|
+
})
|
236
225
|
end
|
237
226
|
|
238
227
|
def delete_device(device_id, user_id)
|
239
|
-
delete(
|
228
|
+
delete('devices', params: { "id": device_id, "user_id": user_id })
|
240
229
|
end
|
241
230
|
|
242
231
|
def get_devices(user_id)
|
243
|
-
get(
|
232
|
+
get('devices', params: { "user_id": user_id })
|
244
233
|
end
|
245
234
|
|
246
235
|
def verify_webhook(request_body, x_signature)
|
247
|
-
signature = OpenSSL::HMAC.hexdigest(
|
236
|
+
signature = OpenSSL::HMAC.hexdigest('SHA256', @api_secret, request_body)
|
248
237
|
signature == x_signature
|
249
238
|
end
|
250
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
|
+
|
251
268
|
def put(relative_url, params: nil, data: nil)
|
252
269
|
make_http_request(:put, relative_url, params: params, data: data)
|
253
270
|
end
|
@@ -272,14 +289,14 @@ module StreamChat
|
|
272
289
|
url = [@base_url, relative_url].join('/')
|
273
290
|
|
274
291
|
file = open(file_url)
|
275
|
-
body = {user: user.to_json}
|
292
|
+
body = { user: user.to_json }
|
276
293
|
|
277
294
|
body[:file] = Faraday::UploadIO.new(file, content_type)
|
278
295
|
|
279
296
|
response = @conn.post url do |req|
|
280
|
-
req.headers[
|
297
|
+
req.headers['X-Stream-Client'] = get_user_agent
|
281
298
|
req.headers['Authorization'] = @auth_token
|
282
|
-
req.headers[
|
299
|
+
req.headers['stream-auth-type'] = 'jwt'
|
283
300
|
req.params = get_default_params
|
284
301
|
req.body = body
|
285
302
|
end
|
@@ -287,10 +304,14 @@ module StreamChat
|
|
287
304
|
parse_response(response)
|
288
305
|
end
|
289
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
|
+
|
290
311
|
private
|
291
312
|
|
292
313
|
def get_default_params
|
293
|
-
{api_key: @api_key}
|
314
|
+
{ api_key: @api_key }
|
294
315
|
end
|
295
316
|
|
296
317
|
def get_user_agent
|
@@ -299,7 +320,7 @@ module StreamChat
|
|
299
320
|
|
300
321
|
def get_default_headers
|
301
322
|
{
|
302
|
-
"Content-Type":
|
323
|
+
"Content-Type": 'application/json',
|
303
324
|
"X-Stream-Client": get_user_agent
|
304
325
|
}
|
305
326
|
end
|
@@ -308,26 +329,23 @@ module StreamChat
|
|
308
329
|
begin
|
309
330
|
parsed_result = JSON.parse(response.body)
|
310
331
|
rescue JSON::ParserError
|
311
|
-
raise StreamAPIException
|
332
|
+
raise StreamAPIException, response
|
312
333
|
end
|
313
|
-
if response.status >= 399
|
314
|
-
|
315
|
-
|
316
|
-
return parsed_result
|
334
|
+
raise StreamAPIException, response if response.status >= 399
|
335
|
+
|
336
|
+
parsed_result
|
317
337
|
end
|
318
338
|
|
319
339
|
def make_http_request(method, relative_url, params: nil, data: nil)
|
320
340
|
headers = get_default_headers
|
321
341
|
headers['Authorization'] = @auth_token
|
322
|
-
headers[
|
342
|
+
headers['stream-auth-type'] = 'jwt'
|
323
343
|
url = [@base_url, relative_url].join('/')
|
324
|
-
params = params
|
325
|
-
params = Hash[get_default_params.merge(params).sort_by { |k,
|
344
|
+
params = params.nil? ? {} : params
|
345
|
+
params = Hash[get_default_params.merge(params).sort_by { |k, _v| k.to_s }]
|
326
346
|
url = "#{url}?#{URI.encode_www_form(params)}"
|
327
347
|
|
328
|
-
if %w[patch post put].include? method.to_s
|
329
|
-
body = data.to_json
|
330
|
-
end
|
348
|
+
body = data.to_json if %w[patch post put].include? method.to_s
|
331
349
|
|
332
350
|
response = @conn.run_request(
|
333
351
|
method,
|
@@ -337,7 +355,5 @@ module StreamChat
|
|
337
355
|
)
|
338
356
|
parse_response(response)
|
339
357
|
end
|
340
|
-
|
341
358
|
end
|
342
359
|
end
|
343
|
-
|
data/lib/stream-chat/errors.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# lib/errors.rb
|
2
4
|
|
3
5
|
module StreamChat
|
4
6
|
class StreamAPIException < StandardError
|
5
|
-
|
6
7
|
def initialize(response)
|
8
|
+
super()
|
7
9
|
@response = response
|
8
10
|
p response
|
9
11
|
begin
|
10
12
|
parsed_response = JSON.parse(response.body)
|
11
13
|
@json_response = true
|
12
|
-
@error_code = parsed_response.fetch(
|
13
|
-
@error_message = parsed_response.fetch(
|
14
|
+
@error_code = parsed_response.fetch('code', 'unknown')
|
15
|
+
@error_message = parsed_response.fetch('message', 'unknown')
|
14
16
|
rescue JSON::ParserError
|
15
17
|
@json_response = false
|
16
18
|
end
|
@@ -24,5 +26,6 @@ module StreamChat
|
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
29
|
+
|
27
30
|
class StreamChannelException < StandardError; end
|
28
31
|
end
|
data/lib/stream-chat/version.rb
CHANGED
data/stream-chat.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require 'stream-chat/version'
|
4
6
|
|
@@ -11,9 +13,10 @@ Gem::Specification.new do |gem|
|
|
11
13
|
gem.email = 'support@getstream.io'
|
12
14
|
gem.homepage = 'http://github.com/GetStream/stream-chat-ruby'
|
13
15
|
gem.authors = ['Mircea Cosbuc']
|
14
|
-
gem.files = Dir.chdir(File.expand_path(
|
16
|
+
gem.files = Dir.chdir(File.expand_path(__dir__)) do
|
15
17
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
18
|
end
|
19
|
+
gem.required_ruby_version = '>=2.5.0'
|
17
20
|
|
18
21
|
gem.add_dependency 'faraday'
|
19
22
|
gem.add_dependency 'jwt'
|
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:
|
4
|
+
version: 2.4.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:
|
11
|
+
date: 2021-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -86,8 +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
92
|
- CHANGELOG.md
|
92
93
|
- Gemfile
|
93
94
|
- LICENSE
|
@@ -98,6 +99,7 @@ files:
|
|
98
99
|
- lib/stream-chat/channel.rb
|
99
100
|
- lib/stream-chat/client.rb
|
100
101
|
- lib/stream-chat/errors.rb
|
102
|
+
- lib/stream-chat/util.rb
|
101
103
|
- lib/stream-chat/version.rb
|
102
104
|
- stream-chat.gemspec
|
103
105
|
homepage: http://github.com/GetStream/stream-chat-ruby
|
@@ -111,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
113
|
requirements:
|
112
114
|
- - ">="
|
113
115
|
- !ruby/object:Gem::Version
|
114
|
-
version:
|
116
|
+
version: 2.5.0
|
115
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
118
|
requirements:
|
117
119
|
- - ">="
|