stream-chat-ruby 1.1.0 → 2.1.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: 0a7fe7381fe903fe6c875649624173564234d61a561c42852b2e00d39af597fb
4
- data.tar.gz: cdfb06d0a7f43b3e49423148abf29a654d31de8f1f7246218fe1c69740813d15
3
+ metadata.gz: 9b1c2b73dbb2e8e0e65aaa47da051ad41694ae5faf6c1d6d1de9e368d9f6bea6
4
+ data.tar.gz: 45a43c071349a05ce38a9df5840182ce299f3c41942c351dfb033aad314bba32
5
5
  SHA512:
6
- metadata.gz: ef7720d01eca5f1b3a66198cfdf23834d4e81100a780992dc0737343d32d23b39d50b8019811da02796f568fe08e542ec602c3b51eeaa55d6d2efd3502d024d8
7
- data.tar.gz: 9e64bef129d028ab0d9757794662b3106bec83b1a6730e2a1941e767a97ab455d3fd2e0939c6ed635445e8400f2d54a67ba620dd521025e1e2916efd33800a76
6
+ metadata.gz: 37f5d1762e3185a5a92698b0e3ea9f8358d21a5d90c9683387b29a8b64e31e6548d1ac3090bf111b83175e1a228ecf6ed711123e9b080ea01332de5d8d33a9d4
7
+ data.tar.gz: 68eb7fee75f01cae1d684fd4c9f51354914656193e4681d2d8a398659613f45bbf37f2322874d01e12f41a395f9a6f68431586a36b1c7094ccf770d85012c3eb
data/.gitignore CHANGED
@@ -42,7 +42,7 @@ build-iPhoneSimulator/
42
42
 
43
43
  # for a library or gem, you might want to ignore these files since the code is
44
44
  # intended to run in multiple environments; otherwise, check them in:
45
- # Gemfile.lock
45
+ Gemfile.lock
46
46
  # .ruby-version
47
47
  # .ruby-gemset
48
48
 
@@ -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
@@ -2,7 +2,9 @@ language: ruby
2
2
  before_install:
3
3
  - gem update bundler
4
4
  rvm:
5
- - 2.3.8
6
- - 2.4.6
7
- - 2.5.5
8
- - 2.6.3
5
+ - 2.5
6
+ - 2.6
7
+ - 2.7
8
+ script:
9
+ - bundle exec rake rubocop
10
+ - bundle exec rake test
@@ -1,4 +1,18 @@
1
- ## next release
1
+ ## October 5th, 2020 - 2.1.0
2
+ - Add support for blocklist
3
+
4
+ ## October 2nd, 2020 - 2.0.0
5
+ - Drop EOL Ruby versions: 2.3 && 2.4
6
+ - Setup Rubocop and mark string literals as frozen
7
+
8
+ ## August 3rd, 2020 - 1.1.3
9
+ - Fixed Argument Error on delete_user
10
+
11
+ ## April 23th, 2020 - 1.1.2
12
+ - Fixed ArgumentError when no users was passed
13
+
14
+ ## March 30th, 2020 - 1.1.1
15
+ - Fixed few minor issues
2
16
 
3
17
  ## Oct 27th, 2019 - 1.1.0
4
18
 
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 "pry"
7
- gem "pry-doc"
8
- gem "method_source"
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 "faraday"
13
- gem "rack"
14
- gem "simplecov"
15
+ gem 'faraday'
16
+ gem 'rack'
17
+ gem 'simplecov'
15
18
  end
16
-
data/README.md CHANGED
@@ -60,9 +60,9 @@ client.create_token('bob-1')
60
60
 
61
61
  ```ruby
62
62
  client.update_user({
63
- 'id' => 'bob-1',
64
- 'role' => 'admin',
65
- 'name' => 'Robert Tables'
63
+ :id => 'bob-1',
64
+ :role => 'admin',
65
+ :name => 'Robert Tables'
66
66
  })
67
67
 
68
68
  # batch update is also supported
@@ -161,7 +161,7 @@ See [an example rails application using the Ruby SDK](https://github.com/GetStre
161
161
  First, make sure you can run the test suite. Tests are run via rspec
162
162
 
163
163
  ```bash
164
- STREAM_KEY=my_api_key STREAM_SECRET=my_api_secret bundle exec rake spec
164
+ STREAM_CHAT_API_KEY=my_api_key STREAM_CHAT_API_SECRET=my_api_secret bundle exec rake spec
165
165
  ```
166
166
 
167
167
  ### 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
- task :default => [:spec]
15
- task :test => [:spec]
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]
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true # rubocop:todo Naming/FileName
2
+
1
3
  require 'stream-chat/client'
@@ -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 == nil
16
- @custom_data = {}
17
- end
16
+ @custom_data = {} if @custom_data.nil?
18
17
  end
19
18
 
20
19
  def url
21
- if @id == nil
22
- raise StreamChannelException "channel does not have an id"
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["created_by"] = {"id": user_id}
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
- if @id != nil
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 == nil
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
@@ -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
- if exp != nil
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("moderation/flag", data: payload)
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("moderation/unflag", data: payload)
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("moderation/flag", data: payload)
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("moderation/unflag", data: payload)
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,19 +82,22 @@ module StreamChat
82
82
 
83
83
  def search(filter_conditions, query, **options)
84
84
  params = options.merge({
85
- "filter_conditions": filter_conditions,
86
- "query": query,
87
- })
85
+ "filter_conditions": filter_conditions,
86
+ "query": query
87
+ })
88
88
 
89
- get("search", params: {"payload": params.to_json})
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
- payload[user[:id]] = user
95
+ id = user[:id] || user['id']
96
+ raise ArgumentError, 'user must have an id' unless id
97
+
98
+ payload[id] = user
96
99
  end
97
- post('users', data: {'users': payload})
100
+ post('users', data: { 'users': payload })
98
101
  end
99
102
 
100
103
  def update_user(user)
@@ -102,7 +105,7 @@ module StreamChat
102
105
  end
103
106
 
104
107
  def update_users_partial(updates)
105
- patch('users', data: {'users': updates})
108
+ patch('users', data: { 'users': updates })
106
109
  end
107
110
 
108
111
  def update_user_partial(update)
@@ -110,7 +113,7 @@ module StreamChat
110
113
  end
111
114
 
112
115
  def delete_user(user_id, **options)
113
- delete("users/#{user_id}", **options)
116
+ delete("users/#{user_id}", params: options)
114
117
  end
115
118
 
116
119
  def deactivate_user(user_id, **options)
@@ -126,35 +129,34 @@ module StreamChat
126
129
  end
127
130
 
128
131
  def ban_user(target_id, **options)
129
- payload = {'target_user_id': target_id}.merge(options)
130
- post("moderation/ban", data: payload)
132
+ payload = { 'target_user_id': target_id }.merge(options)
133
+ post('moderation/ban', data: payload)
131
134
  end
132
135
 
133
136
  def unban_user(target_id, **options)
134
- params = {'target_user_id': target_id}.merge(options)
135
- delete("moderation/ban", params: params)
137
+ params = { 'target_user_id': target_id }.merge(options)
138
+ delete('moderation/ban', params: params)
136
139
  end
137
140
 
138
141
  def mute_user(target_id, user_id)
139
- payload = {'target_id': target_id, 'user_id': user_id}
142
+ payload = { 'target_id': target_id, 'user_id': user_id }
140
143
  post('moderation/mute', data: payload)
141
144
  end
142
145
 
143
146
  def unmute_user(target_id, user_id)
144
- payload = {'target_id': target_id, 'user_id': user_id}
147
+ payload = { 'target_id': target_id, 'user_id': user_id }
145
148
  post('moderation/unmute', data: payload)
146
149
  end
147
150
 
148
151
  def mark_all_read(user_id)
149
- payload = {'user': {'id': user_id}}
152
+ payload = { 'user': { 'id': user_id } }
150
153
  post('channels/read', data: payload)
151
154
  end
152
155
 
153
156
  def update_message(message)
154
- if !message.key? 'id'
155
- raise ArgumentError "message must have an id"
156
- end
157
- 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 })
158
160
  end
159
161
 
160
162
  def delete_message(message_id)
@@ -163,38 +165,32 @@ module StreamChat
163
165
 
164
166
  def query_users(filter_conditions, sort: nil, **options)
165
167
  sort_fields = []
166
- if sort != nil
167
- sort.each do |k ,v|
168
- sort_fields << {"field": k, "direction": v}
169
- end
168
+ sort&.each do |k, v|
169
+ sort_fields << { "field": k, "direction": v }
170
170
  end
171
171
  params = options.merge({
172
- "filter_conditions": filter_conditions,
173
- "sort": sort_fields
174
- })
175
- get("users", params: {"payload": params.to_json})
172
+ "filter_conditions": filter_conditions,
173
+ "sort": sort_fields
174
+ })
175
+ get('users', params: { "payload": params.to_json })
176
176
  end
177
177
 
178
178
  def query_channels(filter_conditions, sort: nil, **options)
179
- params = {"state": true, "watch": false, "presence": false}
179
+ params = { "state": true, "watch": false, "presence": false }
180
180
  sort_fields = []
181
- if sort != nil
182
- sort.each do |k, v|
183
- sort_fields << {"field": k, "direction": v}
184
- end
181
+ sort&.each do |k, v|
182
+ sort_fields << { "field": k, "direction": v }
185
183
  end
186
184
  params = params.merge(options).merge({
187
- "filter_conditions": filter_conditions,
188
- "sort": sort_fields
189
- })
190
- get("channels", params: {"payload": params.to_json})
185
+ "filter_conditions": filter_conditions,
186
+ "sort": sort_fields
187
+ })
188
+ get('channels', params: { "payload": params.to_json })
191
189
  end
192
190
 
193
191
  def create_channel_type(data)
194
- if !data.key? "commands" || data["commands"].nil? || data["commands"].empty?
195
- data["commands"] = ["all"]
196
- end
197
- post("channeltypes", data: data)
192
+ data['commands'] = ['all'] unless data.key?('commands') || data['commands'].nil? || data['commands'].empty?
193
+ post('channeltypes', data: data)
198
194
  end
199
195
 
200
196
  def get_channel_type(channel_type)
@@ -202,11 +198,11 @@ module StreamChat
202
198
  end
203
199
 
204
200
  def list_channel_types
205
- get("channeltypes")
201
+ get('channeltypes')
206
202
  end
207
203
 
208
204
  def update_channel_type(channel_type, **options)
209
- put("channeltypes/#{channel_type}", **options)
205
+ put("channeltypes/#{channel_type}", data: options)
210
206
  end
211
207
 
212
208
  def delete_channel_type(channel_type)
@@ -226,26 +222,46 @@ module StreamChat
226
222
  end
227
223
 
228
224
  def add_device(device_id, push_provider, user_id)
229
- post("devices", data: {
230
- "id": device_id,
231
- "push_provider": push_provider,
232
- "user_id": user_id
233
- })
225
+ post('devices', data: {
226
+ "id": device_id,
227
+ "push_provider": push_provider,
228
+ "user_id": user_id
229
+ })
234
230
  end
235
231
 
236
232
  def delete_device(device_id, user_id)
237
- delete("devices", params: {"id": device_id, "user_id": user_id})
233
+ delete('devices', params: { "id": device_id, "user_id": user_id })
238
234
  end
239
235
 
240
236
  def get_devices(user_id)
241
- get("devices", params: {"user_id": user_id})
237
+ get('devices', params: { "user_id": user_id })
242
238
  end
243
239
 
244
240
  def verify_webhook(request_body, x_signature)
245
- signature = OpenSSL::HMAC.hexdigest("SHA256", @api_secret, request_body)
241
+ signature = OpenSSL::HMAC.hexdigest('SHA256', @api_secret, request_body)
246
242
  signature == x_signature
247
243
  end
248
244
 
245
+ def list_blocklists
246
+ get('blocklists')
247
+ end
248
+
249
+ def get_blocklist(name)
250
+ get("blocklists/#{name}")
251
+ end
252
+
253
+ def create_blocklist(name, words)
254
+ post('blocklists', data: { "name": name, "words": words })
255
+ end
256
+
257
+ def update_blocklist(name, words)
258
+ put("blocklists/#{name}", data: { "words": words })
259
+ end
260
+
261
+ def delete_blocklist(name)
262
+ delete("blocklists/#{name}")
263
+ end
264
+
249
265
  def put(relative_url, params: nil, data: nil)
250
266
  make_http_request(:put, relative_url, params: params, data: data)
251
267
  end
@@ -266,29 +282,29 @@ module StreamChat
266
282
  make_http_request(:patch, relative_url, params: params, data: data)
267
283
  end
268
284
 
269
- def send_file(relative_url, file_url, user, content_type = 'application/octet-stream')
285
+ def send_file(relative_url, file_url, user, content_type = 'application/octet-stream')
270
286
  url = [@base_url, relative_url].join('/')
271
287
 
272
288
  file = open(file_url)
273
- body = {user: user.to_json}
289
+ body = { user: user.to_json }
274
290
 
275
291
  body[:file] = Faraday::UploadIO.new(file, content_type)
276
292
 
277
293
  response = @conn.post url do |req|
278
- req.headers["X-Stream-Client"] = get_user_agent
294
+ req.headers['X-Stream-Client'] = get_user_agent
279
295
  req.headers['Authorization'] = @auth_token
280
- req.headers["stream-auth-type"] = "jwt"
296
+ req.headers['stream-auth-type'] = 'jwt'
281
297
  req.params = get_default_params
282
298
  req.body = body
283
299
  end
284
-
300
+
285
301
  parse_response(response)
286
302
  end
287
303
 
288
304
  private
289
305
 
290
306
  def get_default_params
291
- {api_key: @api_key}
307
+ { api_key: @api_key }
292
308
  end
293
309
 
294
310
  def get_user_agent
@@ -297,7 +313,7 @@ module StreamChat
297
313
 
298
314
  def get_default_headers
299
315
  {
300
- "Content-Type": "application/json",
316
+ "Content-Type": 'application/json',
301
317
  "X-Stream-Client": get_user_agent
302
318
  }
303
319
  end
@@ -306,26 +322,23 @@ module StreamChat
306
322
  begin
307
323
  parsed_result = JSON.parse(response.body)
308
324
  rescue JSON::ParserError
309
- raise StreamAPIException.new(response)
325
+ raise StreamAPIException, response
310
326
  end
311
- if response.status >= 399
312
- raise StreamAPIException.new(response)
313
- end
314
- return parsed_result
327
+ raise StreamAPIException, response if response.status >= 399
328
+
329
+ parsed_result
315
330
  end
316
331
 
317
332
  def make_http_request(method, relative_url, params: nil, data: nil)
318
333
  headers = get_default_headers
319
334
  headers['Authorization'] = @auth_token
320
- headers["stream-auth-type"] = "jwt"
335
+ headers['stream-auth-type'] = 'jwt'
321
336
  url = [@base_url, relative_url].join('/')
322
- params = params != nil ? params : {}
323
- params = Hash[get_default_params.merge(params).sort_by { |k, v| k.to_s }]
337
+ params = !params.nil? ? params : {}
338
+ params = Hash[get_default_params.merge(params).sort_by { |k, _v| k.to_s }]
324
339
  url = "#{url}?#{URI.encode_www_form(params)}"
325
-
326
- if %w[patch post put].include? method.to_s
327
- body = data.to_json
328
- end
340
+
341
+ body = data.to_json if %w[patch post put].include? method.to_s
329
342
 
330
343
  response = @conn.run_request(
331
344
  method,
@@ -335,7 +348,5 @@ module StreamChat
335
348
  )
336
349
  parse_response(response)
337
350
  end
338
-
339
351
  end
340
352
  end
341
-
@@ -1,18 +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("data", {})
13
- .fetch("code", "unknown")
14
- @error_message = parsed_response.fetch("data", {})
15
- .fetch("message", "unknown")
14
+ @error_code = parsed_response.fetch('code', 'unknown')
15
+ @error_message = parsed_response.fetch('message', 'unknown')
16
16
  rescue JSON::ParserError
17
17
  @json_response = false
18
18
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # lib/version.rb
2
4
 
3
5
  module StreamChat
4
- VERSION = "1.1.0".freeze
6
+ VERSION = '2.1.0'
5
7
  end
@@ -1,4 +1,6 @@
1
- lib = File.expand_path("../lib", __FILE__)
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('..', __FILE__)) do
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: 1.1.0
4
+ version: 2.1.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: 2019-11-27 00:00:00.000000000 Z
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,14 +112,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
112
  requirements:
112
113
  - - ">="
113
114
  - !ruby/object:Gem::Version
114
- version: '0'
115
+ version: 2.5.0
115
116
  required_rubygems_version: !ruby/object:Gem::Requirement
116
117
  requirements:
117
118
  - - ">="
118
119
  - !ruby/object:Gem::Version
119
120
  version: '0'
120
121
  requirements: []
121
- rubygems_version: 3.0.6
122
+ rubygems_version: 3.1.2
122
123
  signing_key:
123
124
  specification_version: 4
124
125
  summary: The low level client for serverside calls for Stream Chat.