stream-chat-ruby 1.0.0 → 2.0.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
- SHA1:
3
- metadata.gz: f33905fc20d905b773d08de0596be91bdf399031
4
- data.tar.gz: 3f68209a47f4a0c6f78ec39be3322515e85855b8
2
+ SHA256:
3
+ metadata.gz: c7a819d41561a5fe8bf986b1ddcdc093a985a6de19bd256071a88efb4d790d58
4
+ data.tar.gz: e5cdc6e77fa5e453afbbbdf482c61f791a6896c47fe903f56acdca9794f662a6
5
5
  SHA512:
6
- metadata.gz: dad5cb157613c0c83cf1f9db5acdb8d42882ae5cf7a8831b99afe48434b0bd598e0d73a942a0aeb25d9b0d3ae6f99fe9fb12b7de971b7c5c48496a59b4fc95ed
7
- data.tar.gz: 4ffa4e56a649e549e5b2b88a92949e727648d183b23e53afe06b5e5e5bf3a4fb9da46c2a4bf5fd4a583e6b80057544df2113370179fe621fb55901dff2126965
6
+ metadata.gz: 97fce2a3420903a2b9a88e7197a58683a5e3d0d54139350aec0d7c5029fd657352e2102be57fb398f5e389f5d97a500c5a88fce744f19ae2ffab2c5410ce297e
7
+ data.tar.gz: c9c2c76a61e874e43778b6181e1a2f68191aec1e0444272f043f6086f83f9151ae5a29d7c1255a60bf695520cdbe6e09bc5f87becda1dac93c461468a8b50539
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,3 +1,22 @@
1
+ ## October 2nd, 2020 - 2.0.0
2
+ - Drop EOL Ruby versions: 2.3 && 2.4
3
+ - Setup Rubocop and mark string literals as frozen
4
+
5
+ ## August 3rd, 2020 - 1.1.3
6
+ - Fixed Argument Error on delete_user
7
+
8
+ ## April 23th, 2020 - 1.1.2
9
+ - Fixed ArgumentError when no users was passed
10
+
11
+ ## March 30th, 2020 - 1.1.1
12
+ - Fixed few minor issues
13
+
14
+ ## Oct 27th, 2019 - 1.1.0
15
+
16
+ - Mark gems use for testing as development dependencies
17
+ - Added `send_file`, `send_image`, `delete_file`, `delete_image`
18
+ - Added `invite_members`
19
+
1
20
  ## Oct 19th, 2019 - 1.0.0
2
21
 
3
22
  - Added `channel.hide` and `channel.show`
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,19 +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 })
77
+ end
78
+
79
+ def invite_members(user_ids)
80
+ @client.post(url, data: { "invites": user_ids })
83
81
  end
84
82
 
85
83
  def add_moderators(user_ids)
86
- @client.post(url, data: {"add_moderators": user_ids})
84
+ @client.post(url, data: { "add_moderators": user_ids })
87
85
  end
88
86
 
89
87
  def remove_members(user_ids)
90
- @client.post(url, data: {"remove_members": user_ids})
88
+ @client.post(url, data: { "remove_members": user_ids })
91
89
  end
92
90
 
93
91
  def demote_moderators(user_ids)
94
- @client.post(url, data: {"demote_moderators": user_ids})
92
+ @client.post(url, data: { "demote_moderators": user_ids })
95
93
  end
96
94
 
97
95
  def mark_read(user_id, **options)
@@ -116,18 +114,33 @@ module StreamChat
116
114
  end
117
115
 
118
116
  def hide(user_id)
119
- @client.post("#{url}/hide", data: {user_id: user_id})
117
+ @client.post("#{url}/hide", data: { user_id: user_id })
120
118
  end
121
119
 
122
120
  def show(user_id)
123
- @client.post("#{url}/show", data: {user_id: user_id})
121
+ @client.post("#{url}/show", data: { user_id: user_id })
122
+ end
123
+
124
+ def send_file(url, user, content_type = nil)
125
+ @client.send_file("#{self.url}/file", url, user, content_type)
126
+ end
127
+
128
+ def send_image(url, user, content_type = nil)
129
+ @client.send_file("#{self.url}/image", url, user, content_type)
130
+ end
131
+
132
+ def delete_file(url)
133
+ @client.delete("#{self.url}/file", params: { "url": url })
134
+ end
135
+
136
+ def delete_image(url)
137
+ @client.delete("#{self.url}/image", params: { "url": url })
124
138
  end
125
139
 
126
140
  private
127
141
 
128
142
  def add_user_id(payload, user_id)
129
- payload.merge({"user": {"id": user_id}})
143
+ payload.merge({ "user": { "id": user_id } })
130
144
  end
131
-
132
145
  end
133
146
  end
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # lib/client.rb
4
+ require 'open-uri'
2
5
  require 'faraday'
3
6
  require 'jwt'
4
7
  require 'stream-chat/channel'
@@ -29,20 +32,19 @@ module StreamChat
29
32
  @api_secret = api_secret
30
33
  @timeout = timeout
31
34
  @options = options
32
- @auth_token = JWT.encode({server: true}, @api_secret, 'HS256')
35
+ @auth_token = JWT.encode({ server: true }, @api_secret, 'HS256')
33
36
  @base_url = options[:base_url] || BASE_URL
34
37
  @conn = Faraday.new(url: @base_url) do |faraday|
35
38
  faraday.options[:open_timeout] = @timeout
36
39
  faraday.options[:timeout] = @timeout
37
- faraday.adapter Faraday.default_adapter
40
+ faraday.request :multipart
41
+ faraday.adapter :net_http
38
42
  end
39
43
  end
40
44
 
41
45
  def create_token(user_id, exp = nil)
42
- payload = {user_id: user_id}
43
- if exp != nil
44
- payload['exp'] = exp
45
- end
46
+ payload = { user_id: user_id }
47
+ payload['exp'] = exp unless exp.nil?
46
48
  JWT.encode(payload, @api_secret, 'HS256')
47
49
  end
48
50
 
@@ -55,23 +57,23 @@ module StreamChat
55
57
  end
56
58
 
57
59
  def flag_message(id, **options)
58
- payload = {'target_message_id': id}.merge(options)
59
- post("moderation/flag", data: payload)
60
+ payload = { 'target_message_id': id }.merge(options)
61
+ post('moderation/flag', data: payload)
60
62
  end
61
63
 
62
64
  def unflag_message(id, **options)
63
- payload = {'target_message_id': id}.merge(options)
64
- post("moderation/unflag", data: payload)
65
+ payload = { 'target_message_id': id }.merge(options)
66
+ post('moderation/unflag', data: payload)
65
67
  end
66
68
 
67
69
  def flag_user(id, **options)
68
- payload = {'target_user_id': id}.merge(options)
69
- post("moderation/flag", data: payload)
70
+ payload = { 'target_user_id': id }.merge(options)
71
+ post('moderation/flag', data: payload)
70
72
  end
71
73
 
72
74
  def unflag_user(id, **options)
73
- payload = {'target_user_id': id}.merge(options)
74
- post("moderation/unflag", data: payload)
75
+ payload = { 'target_user_id': id }.merge(options)
76
+ post('moderation/unflag', data: payload)
75
77
  end
76
78
 
77
79
  def get_message(id)
@@ -80,19 +82,22 @@ module StreamChat
80
82
 
81
83
  def search(filter_conditions, query, **options)
82
84
  params = options.merge({
83
- "filter_conditions": filter_conditions,
84
- "query": query,
85
- })
85
+ "filter_conditions": filter_conditions,
86
+ "query": query
87
+ })
86
88
 
87
- get("search", params: {"payload": params.to_json})
89
+ get('search', params: { "payload": params.to_json })
88
90
  end
89
91
 
90
92
  def update_users(users)
91
93
  payload = {}
92
94
  users.each do |user|
93
- 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
94
99
  end
95
- post('users', data: {'users': payload})
100
+ post('users', data: { 'users': payload })
96
101
  end
97
102
 
98
103
  def update_user(user)
@@ -100,7 +105,7 @@ module StreamChat
100
105
  end
101
106
 
102
107
  def update_users_partial(updates)
103
- patch('users', data: {'users': updates})
108
+ patch('users', data: { 'users': updates })
104
109
  end
105
110
 
106
111
  def update_user_partial(update)
@@ -108,7 +113,7 @@ module StreamChat
108
113
  end
109
114
 
110
115
  def delete_user(user_id, **options)
111
- delete("users/#{user_id}", **options)
116
+ delete("users/#{user_id}", params: options)
112
117
  end
113
118
 
114
119
  def deactivate_user(user_id, **options)
@@ -124,35 +129,34 @@ module StreamChat
124
129
  end
125
130
 
126
131
  def ban_user(target_id, **options)
127
- payload = {'target_user_id': target_id}.merge(options)
128
- post("moderation/ban", data: payload)
132
+ payload = { 'target_user_id': target_id }.merge(options)
133
+ post('moderation/ban', data: payload)
129
134
  end
130
135
 
131
136
  def unban_user(target_id, **options)
132
- params = {'target_user_id': target_id}.merge(options)
133
- delete("moderation/ban", params: params)
137
+ params = { 'target_user_id': target_id }.merge(options)
138
+ delete('moderation/ban', params: params)
134
139
  end
135
140
 
136
141
  def mute_user(target_id, user_id)
137
- payload = {'target_id': target_id, 'user_id': user_id}
142
+ payload = { 'target_id': target_id, 'user_id': user_id }
138
143
  post('moderation/mute', data: payload)
139
144
  end
140
145
 
141
146
  def unmute_user(target_id, user_id)
142
- payload = {'target_id': target_id, 'user_id': user_id}
147
+ payload = { 'target_id': target_id, 'user_id': user_id }
143
148
  post('moderation/unmute', data: payload)
144
149
  end
145
150
 
146
151
  def mark_all_read(user_id)
147
- payload = {'user': {'id': user_id}}
152
+ payload = { 'user': { 'id': user_id } }
148
153
  post('channels/read', data: payload)
149
154
  end
150
155
 
151
156
  def update_message(message)
152
- if !message.key? 'id'
153
- raise ArgumentError "message must have an id"
154
- end
155
- 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 })
156
160
  end
157
161
 
158
162
  def delete_message(message_id)
@@ -161,38 +165,32 @@ module StreamChat
161
165
 
162
166
  def query_users(filter_conditions, sort: nil, **options)
163
167
  sort_fields = []
164
- if sort != nil
165
- sort.each do |k ,v|
166
- sort_fields << {"field": k, "direction": v}
167
- end
168
+ sort&.each do |k, v|
169
+ sort_fields << { "field": k, "direction": v }
168
170
  end
169
171
  params = options.merge({
170
- "filter_conditions": filter_conditions,
171
- "sort": sort_fields
172
- })
173
- 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 })
174
176
  end
175
177
 
176
178
  def query_channels(filter_conditions, sort: nil, **options)
177
- params = {"state": true, "watch": false, "presence": false}
179
+ params = { "state": true, "watch": false, "presence": false }
178
180
  sort_fields = []
179
- if sort != nil
180
- sort.each do |k, v|
181
- sort_fields << {"field": k, "direction": v}
182
- end
181
+ sort&.each do |k, v|
182
+ sort_fields << { "field": k, "direction": v }
183
183
  end
184
184
  params = params.merge(options).merge({
185
- "filter_conditions": filter_conditions,
186
- "sort": sort_fields
187
- })
188
- 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 })
189
189
  end
190
190
 
191
191
  def create_channel_type(data)
192
- if !data.key? "commands" || data["commands"].nil? || data["commands"].empty?
193
- data["commands"] = ["all"]
194
- end
195
- post("channeltypes", data: data)
192
+ data['commands'] = ['all'] unless data.key?('commands') || data['commands'].nil? || data['commands'].empty?
193
+ post('channeltypes', data: data)
196
194
  end
197
195
 
198
196
  def get_channel_type(channel_type)
@@ -200,7 +198,7 @@ module StreamChat
200
198
  end
201
199
 
202
200
  def list_channel_types
203
- get("channeltypes")
201
+ get('channeltypes')
204
202
  end
205
203
 
206
204
  def update_channel_type(channel_type, **options)
@@ -224,23 +222,23 @@ module StreamChat
224
222
  end
225
223
 
226
224
  def add_device(device_id, push_provider, user_id)
227
- post("devices", data: {
228
- "id": device_id,
229
- "push_provider": push_provider,
230
- "user_id": user_id
231
- })
225
+ post('devices', data: {
226
+ "id": device_id,
227
+ "push_provider": push_provider,
228
+ "user_id": user_id
229
+ })
232
230
  end
233
231
 
234
232
  def delete_device(device_id, user_id)
235
- delete("devices", params: {"id": device_id, "user_id": user_id})
233
+ delete('devices', params: { "id": device_id, "user_id": user_id })
236
234
  end
237
235
 
238
236
  def get_devices(user_id)
239
- get("devices", params: {"user_id": user_id})
237
+ get('devices', params: { "user_id": user_id })
240
238
  end
241
239
 
242
240
  def verify_webhook(request_body, x_signature)
243
- signature = OpenSSL::HMAC.hexdigest("SHA256", @api_secret, request_body)
241
+ signature = OpenSSL::HMAC.hexdigest('SHA256', @api_secret, request_body)
244
242
  signature == x_signature
245
243
  end
246
244
 
@@ -264,10 +262,29 @@ module StreamChat
264
262
  make_http_request(:patch, relative_url, params: params, data: data)
265
263
  end
266
264
 
265
+ def send_file(relative_url, file_url, user, content_type = 'application/octet-stream')
266
+ url = [@base_url, relative_url].join('/')
267
+
268
+ file = open(file_url)
269
+ body = { user: user.to_json }
270
+
271
+ body[:file] = Faraday::UploadIO.new(file, content_type)
272
+
273
+ response = @conn.post url do |req|
274
+ req.headers['X-Stream-Client'] = get_user_agent
275
+ req.headers['Authorization'] = @auth_token
276
+ req.headers['stream-auth-type'] = 'jwt'
277
+ req.params = get_default_params
278
+ req.body = body
279
+ end
280
+
281
+ parse_response(response)
282
+ end
283
+
267
284
  private
268
285
 
269
286
  def get_default_params
270
- {api_key: @api_key}
287
+ { api_key: @api_key }
271
288
  end
272
289
 
273
290
  def get_user_agent
@@ -276,7 +293,7 @@ module StreamChat
276
293
 
277
294
  def get_default_headers
278
295
  {
279
- "Content-Type": "application/json",
296
+ "Content-Type": 'application/json',
280
297
  "X-Stream-Client": get_user_agent
281
298
  }
282
299
  end
@@ -285,22 +302,22 @@ module StreamChat
285
302
  begin
286
303
  parsed_result = JSON.parse(response.body)
287
304
  rescue JSON::ParserError
288
- raise StreamAPIException.new(response)
305
+ raise StreamAPIException, response
289
306
  end
290
- if response.status >= 399
291
- raise StreamAPIException.new(response)
292
- end
293
- return parsed_result
307
+ raise StreamAPIException, response if response.status >= 399
308
+
309
+ parsed_result
294
310
  end
295
311
 
296
312
  def make_http_request(method, relative_url, params: nil, data: nil)
297
313
  headers = get_default_headers
298
314
  headers['Authorization'] = @auth_token
299
- headers["stream-auth-type"] = "jwt"
315
+ headers['stream-auth-type'] = 'jwt'
300
316
  url = [@base_url, relative_url].join('/')
301
- params = params != nil ? params : {}
302
- params = Hash[get_default_params.merge(params).sort_by { |k, v| k.to_s }]
317
+ params = !params.nil? ? params : {}
318
+ params = Hash[get_default_params.merge(params).sort_by { |k, _v| k.to_s }]
303
319
  url = "#{url}?#{URI.encode_www_form(params)}"
320
+
304
321
  body = data.to_json if %w[patch post put].include? method.to_s
305
322
 
306
323
  response = @conn.run_request(
@@ -311,7 +328,5 @@ module StreamChat
311
328
  )
312
329
  parse_response(response)
313
330
  end
314
-
315
331
  end
316
332
  end
317
-
@@ -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.0.0".freeze
6
+ VERSION = '2.0.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,13 +13,14 @@ 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
17
-
19
+ gem.required_ruby_version = '>=2.5.0'
20
+
18
21
  gem.add_dependency 'faraday'
19
22
  gem.add_dependency 'jwt'
20
- gem.add_dependency 'rake'
21
- gem.add_dependency 'rspec'
22
- gem.add_dependency 'simplecov'
23
+ gem.add_development_dependency 'rake'
24
+ gem.add_development_dependency 'rspec'
25
+ gem.add_development_dependency 'simplecov'
23
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stream-chat-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
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: 2019-10-19 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
@@ -45,7 +45,7 @@ dependencies:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
- type: :runtime
48
+ type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
@@ -59,7 +59,7 @@ dependencies:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- type: :runtime
62
+ type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
@@ -73,7 +73,7 @@ dependencies:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
- type: :runtime
76
+ type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
@@ -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,15 +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
- rubyforge_project:
122
- rubygems_version: 2.4.7
122
+ rubygems_version: 3.1.2
123
123
  signing_key:
124
124
  specification_version: 4
125
125
  summary: The low level client for serverside calls for Stream Chat.