stream-chat-ruby 1.1.3 → 2.0.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/.rubocop.yml +34 -0
- data/.travis.yml +3 -2
- data/CHANGELOG.md +4 -0
- data/Gemfile +9 -7
- 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 +69 -80
- data/lib/stream-chat/errors.rb +5 -3
- data/lib/stream-chat/version.rb +3 -1
- data/stream-chat.gemspec +5 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7a819d41561a5fe8bf986b1ddcdc093a985a6de19bd256071a88efb4d790d58
|
4
|
+
data.tar.gz: e5cdc6e77fa5e453afbbbdf482c61f791a6896c47fe903f56acdca9794f662a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97fce2a3420903a2b9a88e7197a58683a5e3d0d54139350aec0d7c5029fd657352e2102be57fb398f5e389f5d97a500c5a88fce744f19ae2ffab2c5410ce297e
|
7
|
+
data.tar.gz: c9c2c76a61e874e43778b6181e1a2f68191aec1e0444272f043f6086f83f9151ae5a29d7c1255a60bf695520cdbe6e09bc5f87becda1dac93c461468a8b50539
|
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/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
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/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'
|
@@ -30,7 +32,7 @@ module StreamChat
|
|
30
32
|
@api_secret = api_secret
|
31
33
|
@timeout = timeout
|
32
34
|
@options = options
|
33
|
-
@auth_token = JWT.encode({server: true}, @api_secret, 'HS256')
|
35
|
+
@auth_token = JWT.encode({ server: true }, @api_secret, 'HS256')
|
34
36
|
@base_url = options[:base_url] || BASE_URL
|
35
37
|
@conn = Faraday.new(url: @base_url) do |faraday|
|
36
38
|
faraday.options[:open_timeout] = @timeout
|
@@ -41,10 +43,8 @@ module StreamChat
|
|
41
43
|
end
|
42
44
|
|
43
45
|
def create_token(user_id, exp = nil)
|
44
|
-
payload = {user_id: user_id}
|
45
|
-
|
46
|
-
payload['exp'] = exp
|
47
|
-
end
|
46
|
+
payload = { user_id: user_id }
|
47
|
+
payload['exp'] = exp unless exp.nil?
|
48
48
|
JWT.encode(payload, @api_secret, 'HS256')
|
49
49
|
end
|
50
50
|
|
@@ -57,23 +57,23 @@ module StreamChat
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def flag_message(id, **options)
|
60
|
-
payload = {'target_message_id': id}.merge(options)
|
61
|
-
post(
|
60
|
+
payload = { 'target_message_id': id }.merge(options)
|
61
|
+
post('moderation/flag', data: payload)
|
62
62
|
end
|
63
63
|
|
64
64
|
def unflag_message(id, **options)
|
65
|
-
payload = {'target_message_id': id}.merge(options)
|
66
|
-
post(
|
65
|
+
payload = { 'target_message_id': id }.merge(options)
|
66
|
+
post('moderation/unflag', data: payload)
|
67
67
|
end
|
68
68
|
|
69
69
|
def flag_user(id, **options)
|
70
|
-
payload = {'target_user_id': id}.merge(options)
|
71
|
-
post(
|
70
|
+
payload = { 'target_user_id': id }.merge(options)
|
71
|
+
post('moderation/flag', data: payload)
|
72
72
|
end
|
73
73
|
|
74
74
|
def unflag_user(id, **options)
|
75
|
-
payload = {'target_user_id': id}.merge(options)
|
76
|
-
post(
|
75
|
+
payload = { 'target_user_id': id }.merge(options)
|
76
|
+
post('moderation/unflag', data: payload)
|
77
77
|
end
|
78
78
|
|
79
79
|
def get_message(id)
|
@@ -82,21 +82,22 @@ module StreamChat
|
|
82
82
|
|
83
83
|
def search(filter_conditions, query, **options)
|
84
84
|
params = options.merge({
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
"filter_conditions": filter_conditions,
|
86
|
+
"query": query
|
87
|
+
})
|
88
88
|
|
89
|
-
get(
|
89
|
+
get('search', params: { "payload": params.to_json })
|
90
90
|
end
|
91
91
|
|
92
92
|
def update_users(users)
|
93
93
|
payload = {}
|
94
94
|
users.each do |user|
|
95
|
-
id = user[:id] || user[
|
96
|
-
raise ArgumentError,
|
95
|
+
id = user[:id] || user['id']
|
96
|
+
raise ArgumentError, 'user must have an id' unless id
|
97
|
+
|
97
98
|
payload[id] = user
|
98
99
|
end
|
99
|
-
post('users', data: {'users': payload})
|
100
|
+
post('users', data: { 'users': payload })
|
100
101
|
end
|
101
102
|
|
102
103
|
def update_user(user)
|
@@ -104,7 +105,7 @@ module StreamChat
|
|
104
105
|
end
|
105
106
|
|
106
107
|
def update_users_partial(updates)
|
107
|
-
patch('users', data: {'users': updates})
|
108
|
+
patch('users', data: { 'users': updates })
|
108
109
|
end
|
109
110
|
|
110
111
|
def update_user_partial(update)
|
@@ -128,35 +129,34 @@ module StreamChat
|
|
128
129
|
end
|
129
130
|
|
130
131
|
def ban_user(target_id, **options)
|
131
|
-
payload = {'target_user_id': target_id}.merge(options)
|
132
|
-
post(
|
132
|
+
payload = { 'target_user_id': target_id }.merge(options)
|
133
|
+
post('moderation/ban', data: payload)
|
133
134
|
end
|
134
135
|
|
135
136
|
def unban_user(target_id, **options)
|
136
|
-
params = {'target_user_id': target_id}.merge(options)
|
137
|
-
delete(
|
137
|
+
params = { 'target_user_id': target_id }.merge(options)
|
138
|
+
delete('moderation/ban', params: params)
|
138
139
|
end
|
139
140
|
|
140
141
|
def mute_user(target_id, user_id)
|
141
|
-
payload = {'target_id': target_id, 'user_id': user_id}
|
142
|
+
payload = { 'target_id': target_id, 'user_id': user_id }
|
142
143
|
post('moderation/mute', data: payload)
|
143
144
|
end
|
144
145
|
|
145
146
|
def unmute_user(target_id, user_id)
|
146
|
-
payload = {'target_id': target_id, 'user_id': user_id}
|
147
|
+
payload = { 'target_id': target_id, 'user_id': user_id }
|
147
148
|
post('moderation/unmute', data: payload)
|
148
149
|
end
|
149
150
|
|
150
151
|
def mark_all_read(user_id)
|
151
|
-
payload = {'user': {'id': user_id}}
|
152
|
+
payload = { 'user': { 'id': user_id } }
|
152
153
|
post('channels/read', data: payload)
|
153
154
|
end
|
154
155
|
|
155
156
|
def update_message(message)
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
post("messages/#{message['id']}", data: {'message': message})
|
157
|
+
raise ArgumentError 'message must have an id' unless message.key? 'id'
|
158
|
+
|
159
|
+
post("messages/#{message['id']}", data: { 'message': message })
|
160
160
|
end
|
161
161
|
|
162
162
|
def delete_message(message_id)
|
@@ -165,38 +165,32 @@ module StreamChat
|
|
165
165
|
|
166
166
|
def query_users(filter_conditions, sort: nil, **options)
|
167
167
|
sort_fields = []
|
168
|
-
|
169
|
-
|
170
|
-
sort_fields << {"field": k, "direction": v}
|
171
|
-
end
|
168
|
+
sort&.each do |k, v|
|
169
|
+
sort_fields << { "field": k, "direction": v }
|
172
170
|
end
|
173
171
|
params = options.merge({
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
get(
|
172
|
+
"filter_conditions": filter_conditions,
|
173
|
+
"sort": sort_fields
|
174
|
+
})
|
175
|
+
get('users', params: { "payload": params.to_json })
|
178
176
|
end
|
179
177
|
|
180
178
|
def query_channels(filter_conditions, sort: nil, **options)
|
181
|
-
params = {"state": true, "watch": false, "presence": false}
|
179
|
+
params = { "state": true, "watch": false, "presence": false }
|
182
180
|
sort_fields = []
|
183
|
-
|
184
|
-
|
185
|
-
sort_fields << {"field": k, "direction": v}
|
186
|
-
end
|
181
|
+
sort&.each do |k, v|
|
182
|
+
sort_fields << { "field": k, "direction": v }
|
187
183
|
end
|
188
184
|
params = params.merge(options).merge({
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
get(
|
185
|
+
"filter_conditions": filter_conditions,
|
186
|
+
"sort": sort_fields
|
187
|
+
})
|
188
|
+
get('channels', params: { "payload": params.to_json })
|
193
189
|
end
|
194
190
|
|
195
191
|
def create_channel_type(data)
|
196
|
-
|
197
|
-
|
198
|
-
end
|
199
|
-
post("channeltypes", data: data)
|
192
|
+
data['commands'] = ['all'] unless data.key?('commands') || data['commands'].nil? || data['commands'].empty?
|
193
|
+
post('channeltypes', data: data)
|
200
194
|
end
|
201
195
|
|
202
196
|
def get_channel_type(channel_type)
|
@@ -204,7 +198,7 @@ module StreamChat
|
|
204
198
|
end
|
205
199
|
|
206
200
|
def list_channel_types
|
207
|
-
get(
|
201
|
+
get('channeltypes')
|
208
202
|
end
|
209
203
|
|
210
204
|
def update_channel_type(channel_type, **options)
|
@@ -228,23 +222,23 @@ module StreamChat
|
|
228
222
|
end
|
229
223
|
|
230
224
|
def add_device(device_id, push_provider, user_id)
|
231
|
-
post(
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
225
|
+
post('devices', data: {
|
226
|
+
"id": device_id,
|
227
|
+
"push_provider": push_provider,
|
228
|
+
"user_id": user_id
|
229
|
+
})
|
236
230
|
end
|
237
231
|
|
238
232
|
def delete_device(device_id, user_id)
|
239
|
-
delete(
|
233
|
+
delete('devices', params: { "id": device_id, "user_id": user_id })
|
240
234
|
end
|
241
235
|
|
242
236
|
def get_devices(user_id)
|
243
|
-
get(
|
237
|
+
get('devices', params: { "user_id": user_id })
|
244
238
|
end
|
245
239
|
|
246
240
|
def verify_webhook(request_body, x_signature)
|
247
|
-
signature = OpenSSL::HMAC.hexdigest(
|
241
|
+
signature = OpenSSL::HMAC.hexdigest('SHA256', @api_secret, request_body)
|
248
242
|
signature == x_signature
|
249
243
|
end
|
250
244
|
|
@@ -272,14 +266,14 @@ module StreamChat
|
|
272
266
|
url = [@base_url, relative_url].join('/')
|
273
267
|
|
274
268
|
file = open(file_url)
|
275
|
-
body = {user: user.to_json}
|
269
|
+
body = { user: user.to_json }
|
276
270
|
|
277
271
|
body[:file] = Faraday::UploadIO.new(file, content_type)
|
278
272
|
|
279
273
|
response = @conn.post url do |req|
|
280
|
-
req.headers[
|
274
|
+
req.headers['X-Stream-Client'] = get_user_agent
|
281
275
|
req.headers['Authorization'] = @auth_token
|
282
|
-
req.headers[
|
276
|
+
req.headers['stream-auth-type'] = 'jwt'
|
283
277
|
req.params = get_default_params
|
284
278
|
req.body = body
|
285
279
|
end
|
@@ -290,7 +284,7 @@ module StreamChat
|
|
290
284
|
private
|
291
285
|
|
292
286
|
def get_default_params
|
293
|
-
{api_key: @api_key}
|
287
|
+
{ api_key: @api_key }
|
294
288
|
end
|
295
289
|
|
296
290
|
def get_user_agent
|
@@ -299,7 +293,7 @@ module StreamChat
|
|
299
293
|
|
300
294
|
def get_default_headers
|
301
295
|
{
|
302
|
-
"Content-Type":
|
296
|
+
"Content-Type": 'application/json',
|
303
297
|
"X-Stream-Client": get_user_agent
|
304
298
|
}
|
305
299
|
end
|
@@ -308,26 +302,23 @@ module StreamChat
|
|
308
302
|
begin
|
309
303
|
parsed_result = JSON.parse(response.body)
|
310
304
|
rescue JSON::ParserError
|
311
|
-
raise StreamAPIException
|
305
|
+
raise StreamAPIException, response
|
312
306
|
end
|
313
|
-
if response.status >= 399
|
314
|
-
|
315
|
-
|
316
|
-
return parsed_result
|
307
|
+
raise StreamAPIException, response if response.status >= 399
|
308
|
+
|
309
|
+
parsed_result
|
317
310
|
end
|
318
311
|
|
319
312
|
def make_http_request(method, relative_url, params: nil, data: nil)
|
320
313
|
headers = get_default_headers
|
321
314
|
headers['Authorization'] = @auth_token
|
322
|
-
headers[
|
315
|
+
headers['stream-auth-type'] = 'jwt'
|
323
316
|
url = [@base_url, relative_url].join('/')
|
324
|
-
params = params
|
325
|
-
params = Hash[get_default_params.merge(params).sort_by { |k,
|
317
|
+
params = !params.nil? ? params : {}
|
318
|
+
params = Hash[get_default_params.merge(params).sort_by { |k, _v| k.to_s }]
|
326
319
|
url = "#{url}?#{URI.encode_www_form(params)}"
|
327
320
|
|
328
|
-
if %w[patch post put].include? method.to_s
|
329
|
-
body = data.to_json
|
330
|
-
end
|
321
|
+
body = data.to_json if %w[patch post put].include? method.to_s
|
331
322
|
|
332
323
|
response = @conn.run_request(
|
333
324
|
method,
|
@@ -337,7 +328,5 @@ module StreamChat
|
|
337
328
|
)
|
338
329
|
parse_response(response)
|
339
330
|
end
|
340
|
-
|
341
331
|
end
|
342
332
|
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
|
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.0.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-
|
11
|
+
date: 2020-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -87,6 +87,7 @@ extensions: []
|
|
87
87
|
extra_rdoc_files: []
|
88
88
|
files:
|
89
89
|
- ".gitignore"
|
90
|
+
- ".rubocop.yml"
|
90
91
|
- ".travis.yml"
|
91
92
|
- CHANGELOG.md
|
92
93
|
- Gemfile
|
@@ -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
|
- - ">="
|