stream-chat-ruby 2.20.0 → 2.21.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 +3 -0
- data/CHANGELOG.md +13 -0
- data/CONTRIBUTING.md +64 -0
- data/Gemfile +1 -0
- data/README.md +67 -115
- data/lib/stream-chat/channel.rb +58 -6
- data/lib/stream-chat/client.rb +129 -27
- data/lib/stream-chat/errors.rb +22 -9
- data/lib/stream-chat/stream_rate_limits.rb +16 -5
- data/lib/stream-chat/stream_response.rb +21 -8
- data/lib/stream-chat/types.rb +13 -0
- data/lib/stream-chat/util.rb +16 -6
- data/lib/stream-chat/version.rb +2 -3
- data/lib/stream-chat.rb +2 -1
- data/stream-chat.gemspec +2 -1
- metadata +18 -2
data/lib/stream-chat/errors.rb
CHANGED
@@ -1,25 +1,41 @@
|
|
1
|
+
# typed: strict
|
1
2
|
# frozen_string_literal: true
|
2
3
|
|
3
|
-
# lib/errors.rb
|
4
|
-
|
5
4
|
module StreamChat
|
6
5
|
class StreamAPIException < StandardError
|
6
|
+
extend T::Sig
|
7
|
+
T::Configuration.default_checked_level = :never
|
8
|
+
# For now we disable runtime type checks.
|
9
|
+
# We will enable it with a major bump in the future,
|
10
|
+
# but for now, let's just run a static type check.
|
11
|
+
|
12
|
+
sig { returns(Integer) }
|
7
13
|
attr_reader :error_code
|
14
|
+
|
15
|
+
sig { returns(String) }
|
8
16
|
attr_reader :error_message
|
9
17
|
|
18
|
+
sig { returns(T::Boolean) }
|
19
|
+
attr_reader :json_response
|
20
|
+
|
21
|
+
sig { returns(Faraday::Response) }
|
22
|
+
attr_reader :response
|
23
|
+
|
24
|
+
sig { params(response: Faraday::Response).void }
|
10
25
|
def initialize(response)
|
11
26
|
super()
|
12
27
|
@response = response
|
13
28
|
begin
|
14
29
|
parsed_response = JSON.parse(response.body)
|
15
|
-
@json_response = true
|
16
|
-
@error_code = parsed_response.fetch('code', 'unknown')
|
17
|
-
@error_message = parsed_response.fetch('message', 'unknown')
|
30
|
+
@json_response = T.let(true, T::Boolean)
|
31
|
+
@error_code = T.let(parsed_response.fetch('code', 'unknown'), Integer)
|
32
|
+
@error_message = T.let(parsed_response.fetch('message', 'unknown'), String)
|
18
33
|
rescue JSON::ParserError
|
19
34
|
@json_response = false
|
20
35
|
end
|
21
36
|
end
|
22
37
|
|
38
|
+
sig { returns(String) }
|
23
39
|
def message
|
24
40
|
if @json_response
|
25
41
|
"StreamChat error code #{@error_code}: #{@error_message}"
|
@@ -28,10 +44,7 @@ module StreamChat
|
|
28
44
|
end
|
29
45
|
end
|
30
46
|
|
31
|
-
|
32
|
-
@json_response
|
33
|
-
end
|
34
|
-
|
47
|
+
sig { returns(String) }
|
35
48
|
def to_s
|
36
49
|
message
|
37
50
|
end
|
@@ -1,17 +1,28 @@
|
|
1
|
+
# typed: strict
|
1
2
|
# frozen_string_literal: true
|
2
3
|
|
3
|
-
# lib/stream_rate_limits.rb
|
4
|
-
|
5
4
|
module StreamChat
|
6
5
|
class StreamRateLimits
|
6
|
+
extend T::Sig
|
7
|
+
T::Configuration.default_checked_level = :never
|
8
|
+
# For now we disable runtime type checks.
|
9
|
+
# We will enable it with a major bump in the future,
|
10
|
+
# but for now, let's just run a static type check.
|
11
|
+
|
12
|
+
sig { returns(Integer) }
|
7
13
|
attr_reader :limit
|
14
|
+
|
15
|
+
sig { returns(Integer) }
|
8
16
|
attr_reader :remaining
|
17
|
+
|
18
|
+
sig { returns(Time) }
|
9
19
|
attr_reader :reset
|
10
20
|
|
21
|
+
sig { params(limit: String, remaining: String, reset: String).void }
|
11
22
|
def initialize(limit, remaining, reset)
|
12
|
-
@limit = limit.to_i
|
13
|
-
@remaining = remaining.to_i
|
14
|
-
@reset = Time.at(reset.to_i)
|
23
|
+
@limit = T.let(limit.to_i, Integer)
|
24
|
+
@remaining = T.let(remaining.to_i, Integer)
|
25
|
+
@reset = T.let(Time.at(reset.to_i), Time)
|
15
26
|
end
|
16
27
|
end
|
17
28
|
end
|
@@ -1,28 +1,41 @@
|
|
1
|
+
# typed: true
|
1
2
|
# frozen_string_literal: true
|
2
3
|
|
3
|
-
# lib/stream_response.rb
|
4
4
|
require 'stream-chat/stream_rate_limits'
|
5
|
+
require 'stream-chat/types'
|
5
6
|
|
6
7
|
module StreamChat
|
7
8
|
class StreamResponse < Hash
|
9
|
+
extend T::Sig
|
10
|
+
T::Configuration.default_checked_level = :never
|
11
|
+
# For now we disable runtime type checks.
|
12
|
+
# We will enable it with a major bump in the future,
|
13
|
+
# but for now, let's just run a static type check.
|
14
|
+
|
15
|
+
sig { returns(StreamRateLimits) }
|
8
16
|
attr_reader :rate_limit
|
17
|
+
|
18
|
+
sig { returns(Integer) }
|
9
19
|
attr_reader :status_code
|
20
|
+
|
21
|
+
sig { returns(StringKeyHash) }
|
10
22
|
attr_reader :headers
|
11
23
|
|
24
|
+
sig { params(hash: T::Hash[T.untyped, T.untyped], response: Faraday::Response).void }
|
12
25
|
def initialize(hash, response)
|
13
26
|
super(nil)
|
14
27
|
merge!(hash)
|
15
28
|
|
16
29
|
if response.headers.key?('X-Ratelimit-Limit')
|
17
|
-
@rate_limit = StreamRateLimits.new(
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
30
|
+
@rate_limit = T.let(StreamRateLimits.new(
|
31
|
+
T.must(response.headers['X-Ratelimit-Limit']),
|
32
|
+
T.must(response.headers['X-Ratelimit-Remaining']),
|
33
|
+
T.must(response.headers['X-Ratelimit-Reset'])
|
34
|
+
), StreamRateLimits)
|
22
35
|
end
|
23
36
|
|
24
|
-
@status_code = response.status
|
25
|
-
@headers = response.headers
|
37
|
+
@status_code = T.let(response.status, Integer)
|
38
|
+
@headers = T.let(response.headers, StringKeyHash)
|
26
39
|
end
|
27
40
|
end
|
28
41
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module StreamChat
|
5
|
+
extend T::Sig
|
6
|
+
T::Configuration.default_checked_level = :never
|
7
|
+
# For now we disable runtime type checks.
|
8
|
+
# We will enable it with a major bump in the future,
|
9
|
+
# but for now, let's just run a static type check.
|
10
|
+
|
11
|
+
StringKeyHash = T.type_alias { T::Hash[T.any(String, Symbol), T.untyped] }
|
12
|
+
SortArray = T.type_alias { T::Array[{ field: String, direction: Integer }] }
|
13
|
+
end
|
data/lib/stream-chat/util.rb
CHANGED
@@ -1,11 +1,21 @@
|
|
1
|
+
# typed: strict
|
1
2
|
# frozen_string_literal: true
|
2
3
|
|
3
|
-
|
4
|
+
require 'stream-chat/types'
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
module StreamChat
|
7
|
+
extend T::Sig
|
8
|
+
T::Configuration.default_checked_level = :never
|
9
|
+
# For now we disable runtime type checks.
|
10
|
+
# We will enable it with a major bump in the future,
|
11
|
+
# but for now, let's just run a static type check.
|
12
|
+
|
13
|
+
sig { params(sort: T.nilable(T::Hash[String, Integer])).returns(SortArray) }
|
14
|
+
def self.get_sort_fields(sort)
|
15
|
+
sort_fields = T.let([], SortArray)
|
16
|
+
sort&.each do |k, v|
|
17
|
+
sort_fields << { field: k, direction: v }
|
18
|
+
end
|
19
|
+
sort_fields
|
9
20
|
end
|
10
|
-
sort_fields
|
11
21
|
end
|
data/lib/stream-chat/version.rb
CHANGED
data/lib/stream-chat.rb
CHANGED
data/stream-chat.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.homepage = 'http://github.com/GetStream/stream-chat-ruby'
|
15
15
|
gem.authors = ['getstream.io']
|
16
16
|
gem.files = Dir.chdir(File.expand_path(__dir__)) do
|
17
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|\.github|scripts)/}) }
|
17
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|sorbet|spec|\.github|scripts|assets)/}) }
|
18
18
|
end
|
19
19
|
gem.required_ruby_version = '>=2.5.0'
|
20
20
|
gem.metadata = {
|
@@ -31,6 +31,7 @@ Gem::Specification.new do |gem|
|
|
31
31
|
gem.add_dependency 'faraday-net_http_persistent'
|
32
32
|
gem.add_dependency 'jwt'
|
33
33
|
gem.add_dependency 'net-http-persistent'
|
34
|
+
gem.add_dependency 'sorbet-runtime'
|
34
35
|
gem.add_development_dependency 'rake'
|
35
36
|
gem.add_development_dependency 'rspec'
|
36
37
|
gem.add_development_dependency 'simplecov'
|
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: 2.
|
4
|
+
version: 2.21.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- getstream.io
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sorbet-runtime
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: rake
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,6 +146,7 @@ files:
|
|
132
146
|
- ".rubocop.yml"
|
133
147
|
- ".versionrc.js"
|
134
148
|
- CHANGELOG.md
|
149
|
+
- CONTRIBUTING.md
|
135
150
|
- Gemfile
|
136
151
|
- LICENSE
|
137
152
|
- PULL_REQUEST_TEMPLATE.md
|
@@ -143,6 +158,7 @@ files:
|
|
143
158
|
- lib/stream-chat/errors.rb
|
144
159
|
- lib/stream-chat/stream_rate_limits.rb
|
145
160
|
- lib/stream-chat/stream_response.rb
|
161
|
+
- lib/stream-chat/types.rb
|
146
162
|
- lib/stream-chat/util.rb
|
147
163
|
- lib/stream-chat/version.rb
|
148
164
|
- stream-chat.gemspec
|