stream-chat-ruby 1.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +25 -0
- data/.gitignore +1 -1
- data/.rubocop.yml +34 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile +9 -7
- data/README.md +30 -3
- data/Rakefile +9 -3
- data/lib/stream-chat.rb +2 -0
- data/lib/stream-chat/channel.rb +27 -34
- data/lib/stream-chat/client.rb +104 -85
- data/lib/stream-chat/errors.rb +6 -3
- data/lib/stream-chat/version.rb +3 -1
- data/stream-chat.gemspec +5 -2
- metadata +5 -4
- data/.travis.yml +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 431753dd911d42b0ca289bc4ca1b35f0043dca65d0bc846bb1af6128c491f386
|
4
|
+
data.tar.gz: 7f48350204e9bad4de4a975c2d88339934e8cf195c7b38fc876a22bdd9139c63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbf182d9dd41639610ac84a3e34b80a2620b707f4f5ebe67f947b7cffd1cd8b69dd43add8025177958a8be80bb521805ee8c36f564a4059a47723eb935f424b5
|
7
|
+
data.tar.gz: d32a9947b564c61a9918ed72dbbf1ec38e160c754f6105213dd1d3595c53bcb8bacdf75581056d2aea9b6a27635127836fd7688c9b2b8cf0753cde99947e66ef
|
@@ -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/.gitignore
CHANGED
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,23 @@
|
|
1
|
+
## January 4th, 2021 - 2.2.0
|
2
|
+
- Add support for export channels
|
3
|
+
- Improve readme for blocklist and export channels
|
4
|
+
- Improve running tests for multiple versions of ruby
|
5
|
+
- Fix issues from the latest version of rubocop
|
6
|
+
- Move to GitHub Actions
|
7
|
+
|
8
|
+
## October 5th, 2020 - 2.1.0
|
9
|
+
- Add support for blocklist
|
10
|
+
|
11
|
+
## October 2nd, 2020 - 2.0.0
|
12
|
+
- Drop EOL Ruby versions: 2.3 && 2.4
|
13
|
+
- Setup Rubocop and mark string literals as frozen
|
14
|
+
|
15
|
+
## August 3rd, 2020 - 1.1.3
|
16
|
+
- Fixed Argument Error on delete_user
|
17
|
+
|
18
|
+
## April 23th, 2020 - 1.1.2
|
19
|
+
- Fixed ArgumentError when no users was passed
|
20
|
+
|
1
21
|
## March 30th, 2020 - 1.1.1
|
2
22
|
- Fixed few minor issues
|
3
23
|
|
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
|
-
[![
|
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.
|
17
|
+
- Ruby (2.7, 2.6, 2.5)
|
18
18
|
|
19
19
|
#### Install
|
20
20
|
|
@@ -37,6 +37,8 @@ gem install stream-chat-ruby
|
|
37
37
|
- User devices
|
38
38
|
- User search
|
39
39
|
- Channel search
|
40
|
+
- Blocklists
|
41
|
+
- Export channels
|
40
42
|
|
41
43
|
### Import
|
42
44
|
|
@@ -152,6 +154,31 @@ client.get_devices('jane-77')
|
|
152
154
|
client.remove_device(jane_phone['id'], jane_phone['user_id'])
|
153
155
|
```
|
154
156
|
|
157
|
+
### Blocklists
|
158
|
+
```ruby
|
159
|
+
# Create a blocklist
|
160
|
+
client.create_blocklist('my_blocker', %w[fudge cream sugar])
|
161
|
+
|
162
|
+
# Enable it on messaging channel type
|
163
|
+
client.update_channel_type('messaging', blocklist: 'my_blocker', blocklist_behavior: 'block')
|
164
|
+
|
165
|
+
# Get the details of the blocklist
|
166
|
+
client.get_blocklist('my_blocker')
|
167
|
+
|
168
|
+
# Delete the blocklist
|
169
|
+
client.delete_blocklist('my_blocker')
|
170
|
+
```
|
171
|
+
|
172
|
+
### Export Channels
|
173
|
+
```ruby
|
174
|
+
# Register an export
|
175
|
+
response = client.export_channels({type: 'messaging', id: 'jane'})
|
176
|
+
|
177
|
+
# Check completion
|
178
|
+
status_response = client.get_export_channel_status(response['task_id'])
|
179
|
+
# status_response['status'] == 'pending', 'completed'
|
180
|
+
```
|
181
|
+
|
155
182
|
### Example Rails application
|
156
183
|
|
157
184
|
See [an example rails application using the Ruby SDK](https://github.com/GetStream/rails-chat-example).
|
@@ -161,7 +188,7 @@ See [an example rails application using the Ruby SDK](https://github.com/GetStre
|
|
161
188
|
First, make sure you can run the test suite. Tests are run via rspec
|
162
189
|
|
163
190
|
```bash
|
164
|
-
|
191
|
+
STREAM_CHAT_API_KEY=my_api_key STREAM_CHAT_API_SECRET=my_api_secret bundle exec rake spec
|
165
192
|
```
|
166
193
|
|
167
194
|
### Releasing a new version
|
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,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'stream-chat/errors'
|
2
4
|
|
3
5
|
module StreamChat
|
4
|
-
|
5
|
-
class Channel
|
6
|
+
class Channel # rubocop:todo Metrics/ClassLength # rubocop:todo Style/Documentation
|
6
7
|
attr_reader :id
|
7
8
|
attr_reader :channel_type
|
8
9
|
attr_reader :custom_data
|
9
10
|
|
10
|
-
def initialize(client, channel_type, channel_id=nil, custom_data=nil)
|
11
|
+
def initialize(client, channel_type, channel_id = nil, custom_data = nil)
|
11
12
|
@channel_type = channel_type
|
12
13
|
@id = channel_id
|
13
14
|
@client = client
|
14
15
|
@custom_data = custom_data
|
15
|
-
if @custom_data
|
16
|
-
@custom_data = {}
|
17
|
-
end
|
16
|
+
@custom_data = {} if @custom_data.nil?
|
18
17
|
end
|
19
18
|
|
20
19
|
def url
|
21
|
-
if @id
|
22
|
-
|
23
|
-
end
|
20
|
+
raise StreamChannelException 'channel does not have an id' if @id.nil?
|
21
|
+
|
24
22
|
"channels/#{@channel_type}/#{@id}"
|
25
23
|
end
|
26
24
|
|
27
25
|
def send_message(message, user_id)
|
28
|
-
payload = {"message": add_user_id(message, user_id)}
|
26
|
+
payload = { "message": add_user_id(message, user_id) }
|
29
27
|
@client.post("#{url}/message", data: payload)
|
30
28
|
end
|
31
29
|
|
32
30
|
def send_event(event, user_id)
|
33
|
-
payload = {'event' => add_user_id(event, user_id)}
|
31
|
+
payload = { 'event' => add_user_id(event, user_id) }
|
34
32
|
@client.post("#{url}/event", data: payload)
|
35
33
|
end
|
36
34
|
|
37
35
|
def send_reaction(message_id, reaction, user_id)
|
38
|
-
payload = {"reaction": add_user_id(reaction, user_id)}
|
36
|
+
payload = { "reaction": add_user_id(reaction, user_id) }
|
39
37
|
@client.post("messages/#{message_id}/reaction", data: payload)
|
40
38
|
end
|
41
39
|
|
42
40
|
def delete_reaction(message_id, reaction_type, user_id)
|
43
41
|
@client.delete(
|
44
42
|
"messages/#{message_id}/reaction/#{reaction_type}",
|
45
|
-
params: {"user_id": user_id}
|
43
|
+
params: { "user_id": user_id }
|
46
44
|
)
|
47
45
|
end
|
48
46
|
|
49
47
|
def create(user_id)
|
50
|
-
@custom_data[
|
48
|
+
@custom_data['created_by'] = { "id": user_id }
|
51
49
|
query(watch: false, state: false, presence: false)
|
52
50
|
end
|
53
51
|
|
54
52
|
def query(**options)
|
55
|
-
payload = {"state": true, "data": @custom_data}.merge(options)
|
53
|
+
payload = { "state": true, "data": @custom_data }.merge(options)
|
56
54
|
url = "channels/#{@channel_type}"
|
57
|
-
|
58
|
-
url = "#{url}/#{@id}"
|
59
|
-
end
|
55
|
+
url = "#{url}/#{@id}" unless @id.nil?
|
60
56
|
|
61
57
|
state = @client.post("#{url}/query", data: payload)
|
62
|
-
if @id
|
63
|
-
@id = state["channel"]["id"]
|
64
|
-
end
|
58
|
+
@id = state['channel']['id'] if @id.nil?
|
65
59
|
state
|
66
60
|
end
|
67
61
|
|
68
|
-
def update(channel_data, update_message=nil)
|
69
|
-
payload = {"data": channel_data, "message": update_message}
|
62
|
+
def update(channel_data, update_message = nil)
|
63
|
+
payload = { "data": channel_data, "message": update_message }
|
70
64
|
@client.post(url, data: payload)
|
71
65
|
end
|
72
66
|
|
@@ -79,23 +73,23 @@ module StreamChat
|
|
79
73
|
end
|
80
74
|
|
81
75
|
def add_members(user_ids)
|
82
|
-
@client.post(url, data: {"add_members": user_ids})
|
76
|
+
@client.post(url, data: { "add_members": user_ids })
|
83
77
|
end
|
84
78
|
|
85
79
|
def invite_members(user_ids)
|
86
|
-
@client.post(url, data: {"invites": user_ids})
|
80
|
+
@client.post(url, data: { "invites": user_ids })
|
87
81
|
end
|
88
82
|
|
89
83
|
def add_moderators(user_ids)
|
90
|
-
@client.post(url, data: {"add_moderators": user_ids})
|
84
|
+
@client.post(url, data: { "add_moderators": user_ids })
|
91
85
|
end
|
92
86
|
|
93
87
|
def remove_members(user_ids)
|
94
|
-
@client.post(url, data: {"remove_members": user_ids})
|
88
|
+
@client.post(url, data: { "remove_members": user_ids })
|
95
89
|
end
|
96
90
|
|
97
91
|
def demote_moderators(user_ids)
|
98
|
-
@client.post(url, data: {"demote_moderators": user_ids})
|
92
|
+
@client.post(url, data: { "demote_moderators": user_ids })
|
99
93
|
end
|
100
94
|
|
101
95
|
def mark_read(user_id, **options)
|
@@ -120,11 +114,11 @@ module StreamChat
|
|
120
114
|
end
|
121
115
|
|
122
116
|
def hide(user_id)
|
123
|
-
@client.post("#{url}/hide", data: {user_id: user_id})
|
117
|
+
@client.post("#{url}/hide", data: { user_id: user_id })
|
124
118
|
end
|
125
119
|
|
126
120
|
def show(user_id)
|
127
|
-
@client.post("#{url}/show", data: {user_id: user_id})
|
121
|
+
@client.post("#{url}/show", data: { user_id: user_id })
|
128
122
|
end
|
129
123
|
|
130
124
|
def send_file(url, user, content_type = nil)
|
@@ -136,18 +130,17 @@ module StreamChat
|
|
136
130
|
end
|
137
131
|
|
138
132
|
def delete_file(url)
|
139
|
-
@client.delete("#{self.url}/file", params: {"url": url})
|
133
|
+
@client.delete("#{self.url}/file", params: { "url": url })
|
140
134
|
end
|
141
135
|
|
142
136
|
def delete_image(url)
|
143
|
-
@client.delete("#{self.url}/image", params: {"url": url})
|
137
|
+
@client.delete("#{self.url}/image", params: { "url": url })
|
144
138
|
end
|
145
139
|
|
146
140
|
private
|
147
141
|
|
148
142
|
def add_user_id(payload, user_id)
|
149
|
-
payload.merge({"user": {"id": user_id}})
|
143
|
+
payload.merge({ "user": { "id": user_id } })
|
150
144
|
end
|
151
|
-
|
152
145
|
end
|
153
146
|
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'
|
@@ -7,6 +9,8 @@ require 'stream-chat/errors'
|
|
7
9
|
require 'stream-chat/version'
|
8
10
|
|
9
11
|
module StreamChat
|
12
|
+
DEFAULT_BLOCKLIST = 'profanity_en_2020_v1'
|
13
|
+
|
10
14
|
class Client
|
11
15
|
BASE_URL = 'https://chat-us-east-1.stream-io-api.com'
|
12
16
|
|
@@ -30,7 +34,7 @@ module StreamChat
|
|
30
34
|
@api_secret = api_secret
|
31
35
|
@timeout = timeout
|
32
36
|
@options = options
|
33
|
-
@auth_token = JWT.encode({server: true}, @api_secret, 'HS256')
|
37
|
+
@auth_token = JWT.encode({ server: true }, @api_secret, 'HS256')
|
34
38
|
@base_url = options[:base_url] || BASE_URL
|
35
39
|
@conn = Faraday.new(url: @base_url) do |faraday|
|
36
40
|
faraday.options[:open_timeout] = @timeout
|
@@ -41,10 +45,8 @@ module StreamChat
|
|
41
45
|
end
|
42
46
|
|
43
47
|
def create_token(user_id, exp = nil)
|
44
|
-
payload = {user_id: user_id}
|
45
|
-
|
46
|
-
payload['exp'] = exp
|
47
|
-
end
|
48
|
+
payload = { user_id: user_id }
|
49
|
+
payload['exp'] = exp unless exp.nil?
|
48
50
|
JWT.encode(payload, @api_secret, 'HS256')
|
49
51
|
end
|
50
52
|
|
@@ -57,23 +59,23 @@ module StreamChat
|
|
57
59
|
end
|
58
60
|
|
59
61
|
def flag_message(id, **options)
|
60
|
-
payload = {'target_message_id': id}.merge(options)
|
61
|
-
post(
|
62
|
+
payload = { 'target_message_id': id }.merge(options)
|
63
|
+
post('moderation/flag', data: payload)
|
62
64
|
end
|
63
65
|
|
64
66
|
def unflag_message(id, **options)
|
65
|
-
payload = {'target_message_id': id}.merge(options)
|
66
|
-
post(
|
67
|
+
payload = { 'target_message_id': id }.merge(options)
|
68
|
+
post('moderation/unflag', data: payload)
|
67
69
|
end
|
68
70
|
|
69
71
|
def flag_user(id, **options)
|
70
|
-
payload = {'target_user_id': id}.merge(options)
|
71
|
-
post(
|
72
|
+
payload = { 'target_user_id': id }.merge(options)
|
73
|
+
post('moderation/flag', data: payload)
|
72
74
|
end
|
73
75
|
|
74
76
|
def unflag_user(id, **options)
|
75
|
-
payload = {'target_user_id': id}.merge(options)
|
76
|
-
post(
|
77
|
+
payload = { 'target_user_id': id }.merge(options)
|
78
|
+
post('moderation/unflag', data: payload)
|
77
79
|
end
|
78
80
|
|
79
81
|
def get_message(id)
|
@@ -82,21 +84,22 @@ module StreamChat
|
|
82
84
|
|
83
85
|
def search(filter_conditions, query, **options)
|
84
86
|
params = options.merge({
|
85
|
-
|
86
|
-
|
87
|
-
|
87
|
+
"filter_conditions": filter_conditions,
|
88
|
+
"query": query
|
89
|
+
})
|
88
90
|
|
89
|
-
get(
|
91
|
+
get('search', params: { "payload": params.to_json })
|
90
92
|
end
|
91
93
|
|
92
94
|
def update_users(users)
|
93
95
|
payload = {}
|
94
96
|
users.each do |user|
|
95
|
-
id = user[:id] || user[
|
96
|
-
raise ArgumentError
|
97
|
+
id = user[:id] || user['id']
|
98
|
+
raise ArgumentError, 'user must have an id' unless id
|
99
|
+
|
97
100
|
payload[id] = user
|
98
101
|
end
|
99
|
-
post('users', data: {'users': payload})
|
102
|
+
post('users', data: { 'users': payload })
|
100
103
|
end
|
101
104
|
|
102
105
|
def update_user(user)
|
@@ -104,7 +107,7 @@ module StreamChat
|
|
104
107
|
end
|
105
108
|
|
106
109
|
def update_users_partial(updates)
|
107
|
-
patch('users', data: {'users': updates})
|
110
|
+
patch('users', data: { 'users': updates })
|
108
111
|
end
|
109
112
|
|
110
113
|
def update_user_partial(update)
|
@@ -112,7 +115,7 @@ module StreamChat
|
|
112
115
|
end
|
113
116
|
|
114
117
|
def delete_user(user_id, **options)
|
115
|
-
delete("users/#{user_id}",
|
118
|
+
delete("users/#{user_id}", params: options)
|
116
119
|
end
|
117
120
|
|
118
121
|
def deactivate_user(user_id, **options)
|
@@ -128,35 +131,34 @@ module StreamChat
|
|
128
131
|
end
|
129
132
|
|
130
133
|
def ban_user(target_id, **options)
|
131
|
-
payload = {'target_user_id': target_id}.merge(options)
|
132
|
-
post(
|
134
|
+
payload = { 'target_user_id': target_id }.merge(options)
|
135
|
+
post('moderation/ban', data: payload)
|
133
136
|
end
|
134
137
|
|
135
138
|
def unban_user(target_id, **options)
|
136
|
-
params = {'target_user_id': target_id}.merge(options)
|
137
|
-
delete(
|
139
|
+
params = { 'target_user_id': target_id }.merge(options)
|
140
|
+
delete('moderation/ban', params: params)
|
138
141
|
end
|
139
142
|
|
140
143
|
def mute_user(target_id, user_id)
|
141
|
-
payload = {'target_id': target_id, 'user_id': user_id}
|
144
|
+
payload = { 'target_id': target_id, 'user_id': user_id }
|
142
145
|
post('moderation/mute', data: payload)
|
143
146
|
end
|
144
147
|
|
145
148
|
def unmute_user(target_id, user_id)
|
146
|
-
payload = {'target_id': target_id, 'user_id': user_id}
|
149
|
+
payload = { 'target_id': target_id, 'user_id': user_id }
|
147
150
|
post('moderation/unmute', data: payload)
|
148
151
|
end
|
149
152
|
|
150
153
|
def mark_all_read(user_id)
|
151
|
-
payload = {'user': {'id': user_id}}
|
154
|
+
payload = { 'user': { 'id': user_id } }
|
152
155
|
post('channels/read', data: payload)
|
153
156
|
end
|
154
157
|
|
155
158
|
def update_message(message)
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
post("messages/#{message['id']}", data: {'message': message})
|
159
|
+
raise ArgumentError 'message must have an id' unless message.key? 'id'
|
160
|
+
|
161
|
+
post("messages/#{message['id']}", data: { 'message': message })
|
160
162
|
end
|
161
163
|
|
162
164
|
def delete_message(message_id)
|
@@ -165,38 +167,32 @@ module StreamChat
|
|
165
167
|
|
166
168
|
def query_users(filter_conditions, sort: nil, **options)
|
167
169
|
sort_fields = []
|
168
|
-
|
169
|
-
|
170
|
-
sort_fields << {"field": k, "direction": v}
|
171
|
-
end
|
170
|
+
sort&.each do |k, v|
|
171
|
+
sort_fields << { "field": k, "direction": v }
|
172
172
|
end
|
173
173
|
params = options.merge({
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
get(
|
174
|
+
"filter_conditions": filter_conditions,
|
175
|
+
"sort": sort_fields
|
176
|
+
})
|
177
|
+
get('users', params: { "payload": params.to_json })
|
178
178
|
end
|
179
179
|
|
180
180
|
def query_channels(filter_conditions, sort: nil, **options)
|
181
|
-
params = {"state": true, "watch": false, "presence": false}
|
181
|
+
params = { "state": true, "watch": false, "presence": false }
|
182
182
|
sort_fields = []
|
183
|
-
|
184
|
-
|
185
|
-
sort_fields << {"field": k, "direction": v}
|
186
|
-
end
|
183
|
+
sort&.each do |k, v|
|
184
|
+
sort_fields << { "field": k, "direction": v }
|
187
185
|
end
|
188
186
|
params = params.merge(options).merge({
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
get(
|
187
|
+
"filter_conditions": filter_conditions,
|
188
|
+
"sort": sort_fields
|
189
|
+
})
|
190
|
+
get('channels', params: { "payload": params.to_json })
|
193
191
|
end
|
194
192
|
|
195
193
|
def create_channel_type(data)
|
196
|
-
|
197
|
-
|
198
|
-
end
|
199
|
-
post("channeltypes", data: data)
|
194
|
+
data['commands'] = ['all'] unless data.key?('commands') || data['commands'].nil? || data['commands'].empty?
|
195
|
+
post('channeltypes', data: data)
|
200
196
|
end
|
201
197
|
|
202
198
|
def get_channel_type(channel_type)
|
@@ -204,11 +200,11 @@ module StreamChat
|
|
204
200
|
end
|
205
201
|
|
206
202
|
def list_channel_types
|
207
|
-
get(
|
203
|
+
get('channeltypes')
|
208
204
|
end
|
209
205
|
|
210
206
|
def update_channel_type(channel_type, **options)
|
211
|
-
put("channeltypes/#{channel_type}",
|
207
|
+
put("channeltypes/#{channel_type}", data: options)
|
212
208
|
end
|
213
209
|
|
214
210
|
def delete_channel_type(channel_type)
|
@@ -228,26 +224,54 @@ module StreamChat
|
|
228
224
|
end
|
229
225
|
|
230
226
|
def add_device(device_id, push_provider, user_id)
|
231
|
-
post(
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
227
|
+
post('devices', data: {
|
228
|
+
"id": device_id,
|
229
|
+
"push_provider": push_provider,
|
230
|
+
"user_id": user_id
|
231
|
+
})
|
236
232
|
end
|
237
233
|
|
238
234
|
def delete_device(device_id, user_id)
|
239
|
-
delete(
|
235
|
+
delete('devices', params: { "id": device_id, "user_id": user_id })
|
240
236
|
end
|
241
237
|
|
242
238
|
def get_devices(user_id)
|
243
|
-
get(
|
239
|
+
get('devices', params: { "user_id": user_id })
|
244
240
|
end
|
245
241
|
|
246
242
|
def verify_webhook(request_body, x_signature)
|
247
|
-
signature = OpenSSL::HMAC.hexdigest(
|
243
|
+
signature = OpenSSL::HMAC.hexdigest('SHA256', @api_secret, request_body)
|
248
244
|
signature == x_signature
|
249
245
|
end
|
250
246
|
|
247
|
+
def list_blocklists
|
248
|
+
get('blocklists')
|
249
|
+
end
|
250
|
+
|
251
|
+
def get_blocklist(name)
|
252
|
+
get("blocklists/#{name}")
|
253
|
+
end
|
254
|
+
|
255
|
+
def create_blocklist(name, words)
|
256
|
+
post('blocklists', data: { "name": name, "words": words })
|
257
|
+
end
|
258
|
+
|
259
|
+
def update_blocklist(name, words)
|
260
|
+
put("blocklists/#{name}", data: { "words": words })
|
261
|
+
end
|
262
|
+
|
263
|
+
def delete_blocklist(name)
|
264
|
+
delete("blocklists/#{name}")
|
265
|
+
end
|
266
|
+
|
267
|
+
def export_channels(*channels)
|
268
|
+
post('export_channels', data: { "channels": channels })
|
269
|
+
end
|
270
|
+
|
271
|
+
def get_export_channel_status(task_id)
|
272
|
+
get("export_channels/#{task_id}")
|
273
|
+
end
|
274
|
+
|
251
275
|
def put(relative_url, params: nil, data: nil)
|
252
276
|
make_http_request(:put, relative_url, params: params, data: data)
|
253
277
|
end
|
@@ -268,29 +292,29 @@ module StreamChat
|
|
268
292
|
make_http_request(:patch, relative_url, params: params, data: data)
|
269
293
|
end
|
270
294
|
|
271
|
-
def send_file(relative_url, file_url, user, content_type = 'application/octet-stream')
|
295
|
+
def send_file(relative_url, file_url, user, content_type = 'application/octet-stream')
|
272
296
|
url = [@base_url, relative_url].join('/')
|
273
297
|
|
274
298
|
file = open(file_url)
|
275
|
-
body = {user: user.to_json}
|
299
|
+
body = { user: user.to_json }
|
276
300
|
|
277
301
|
body[:file] = Faraday::UploadIO.new(file, content_type)
|
278
302
|
|
279
303
|
response = @conn.post url do |req|
|
280
|
-
req.headers[
|
304
|
+
req.headers['X-Stream-Client'] = get_user_agent
|
281
305
|
req.headers['Authorization'] = @auth_token
|
282
|
-
req.headers[
|
306
|
+
req.headers['stream-auth-type'] = 'jwt'
|
283
307
|
req.params = get_default_params
|
284
308
|
req.body = body
|
285
309
|
end
|
286
|
-
|
310
|
+
|
287
311
|
parse_response(response)
|
288
312
|
end
|
289
313
|
|
290
314
|
private
|
291
315
|
|
292
316
|
def get_default_params
|
293
|
-
{api_key: @api_key}
|
317
|
+
{ api_key: @api_key }
|
294
318
|
end
|
295
319
|
|
296
320
|
def get_user_agent
|
@@ -299,7 +323,7 @@ module StreamChat
|
|
299
323
|
|
300
324
|
def get_default_headers
|
301
325
|
{
|
302
|
-
"Content-Type":
|
326
|
+
"Content-Type": 'application/json',
|
303
327
|
"X-Stream-Client": get_user_agent
|
304
328
|
}
|
305
329
|
end
|
@@ -308,26 +332,23 @@ module StreamChat
|
|
308
332
|
begin
|
309
333
|
parsed_result = JSON.parse(response.body)
|
310
334
|
rescue JSON::ParserError
|
311
|
-
raise StreamAPIException
|
312
|
-
end
|
313
|
-
if response.status >= 399
|
314
|
-
raise StreamAPIException.new(response)
|
335
|
+
raise StreamAPIException, response
|
315
336
|
end
|
316
|
-
|
337
|
+
raise StreamAPIException, response if response.status >= 399
|
338
|
+
|
339
|
+
parsed_result
|
317
340
|
end
|
318
341
|
|
319
342
|
def make_http_request(method, relative_url, params: nil, data: nil)
|
320
343
|
headers = get_default_headers
|
321
344
|
headers['Authorization'] = @auth_token
|
322
|
-
headers[
|
345
|
+
headers['stream-auth-type'] = 'jwt'
|
323
346
|
url = [@base_url, relative_url].join('/')
|
324
|
-
params = params
|
325
|
-
params = Hash[get_default_params.merge(params).sort_by { |k,
|
347
|
+
params = params.nil? ? {} : params
|
348
|
+
params = Hash[get_default_params.merge(params).sort_by { |k, _v| k.to_s }]
|
326
349
|
url = "#{url}?#{URI.encode_www_form(params)}"
|
327
|
-
|
328
|
-
if %w[patch post put].include? method.to_s
|
329
|
-
body = data.to_json
|
330
|
-
end
|
350
|
+
|
351
|
+
body = data.to_json if %w[patch post put].include? method.to_s
|
331
352
|
|
332
353
|
response = @conn.run_request(
|
333
354
|
method,
|
@@ -337,7 +358,5 @@ module StreamChat
|
|
337
358
|
)
|
338
359
|
parse_response(response)
|
339
360
|
end
|
340
|
-
|
341
361
|
end
|
342
362
|
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.2.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-05 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
|
@@ -111,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
112
|
requirements:
|
112
113
|
- - ">="
|
113
114
|
- !ruby/object:Gem::Version
|
114
|
-
version:
|
115
|
+
version: 2.5.0
|
115
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
117
|
requirements:
|
117
118
|
- - ">="
|