stream-chat-ruby 2.18.0 → 2.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/stream-chat/client.rb +35 -11
- data/lib/stream-chat/version.rb +1 -1
- data/stream-chat.gemspec +2 -0
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5789a9c18bf5d3508b754a0a3931b647d441dd48057fe0ff4209092d31a985c1
|
4
|
+
data.tar.gz: 86f540d7f3dc23e481314757efa3f6bac1746218f8e7686448da197c373a6b7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4984f7402280cd7484a7687a6a940ef6c7662bcda3684da6e05d3e9cef8271f677221e11df4c0e865a4a3910dcdb5423a9adac479648f30d0eb1341effbb515
|
7
|
+
data.tar.gz: 0d89825ed4fae41d47a4daeb80d0192aad1c8e2d381d89384eed4076820fd7ce6538e278fd905a04e657e9f719910166f6b10dc6e1ae33fcc59d5988b3907ffe
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
4
4
|
|
5
|
+
## [2.19.0](https://github.com/GetStream/stream-chat-ruby/compare/v2.18.0...v2.19.0) (2022-02-02)
|
6
|
+
|
7
|
+
|
8
|
+
### Features
|
9
|
+
|
10
|
+
* ability to provide custom http client ([#75](https://github.com/GetStream/stream-chat-ruby/issues/75)) ([bfff20d](https://github.com/GetStream/stream-chat-ruby/commit/bfff20d06232c49a1a8d0eee255a718bfffbb351))
|
11
|
+
* add connection pooling and idle timeout ([#74](https://github.com/GetStream/stream-chat-ruby/issues/74)) ([7891005](https://github.com/GetStream/stream-chat-ruby/commit/78910053b3a15b1efa3183a71299068e63b128e3))
|
12
|
+
* env var handling enhancement ([#76](https://github.com/GetStream/stream-chat-ruby/issues/76)) ([0cdc38a](https://github.com/GetStream/stream-chat-ruby/commit/0cdc38abd671bfaa8cefa7f403b9e2ac8b642272))
|
13
|
+
> 🚨 Note: if you used `STREAM_CHAT_URL` env var, you'll need to provide it manually in the `**options` as `base_url`. See the initializer of `Client` class for more information.
|
14
|
+
|
5
15
|
## [2.18.0](https://github.com/GetStream/stream-chat-ruby/compare/v2.17.2...v2.18.0) (2022-01-26)
|
6
16
|
|
7
17
|
|
data/lib/stream-chat/client.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
require 'open-uri'
|
5
5
|
require 'faraday'
|
6
6
|
require 'faraday/multipart'
|
7
|
+
require 'faraday/net_http_persistent'
|
7
8
|
require 'jwt'
|
8
9
|
require 'time'
|
9
10
|
require 'stream-chat/channel'
|
@@ -18,7 +19,8 @@ module StreamChat
|
|
18
19
|
HARD_DELETE = 'hard'
|
19
20
|
|
20
21
|
class Client
|
21
|
-
|
22
|
+
DEFAULT_BASE_URL = 'https://chat.stream-io-api.com'
|
23
|
+
DEFAULT_TIMEOUT = 6.0
|
22
24
|
|
23
25
|
attr_reader :api_key
|
24
26
|
attr_reader :api_secret
|
@@ -29,27 +31,50 @@ module StreamChat
|
|
29
31
|
#
|
30
32
|
# @param [string] api_key your application api_key
|
31
33
|
# @param [string] api_secret your application secret
|
32
|
-
# @param [
|
33
|
-
# @param [hash] options extra options
|
34
|
+
# @param [float] timeout the timeout for the http requests
|
35
|
+
# @param [hash] options extra options such as base_url
|
34
36
|
#
|
35
37
|
# @example initialized the client with a timeout setting
|
36
38
|
# StreamChat::Client.new('my_key', 'my_secret', 3.0)
|
37
39
|
#
|
38
|
-
def initialize(api_key
|
39
|
-
|
40
|
-
|
41
|
-
@
|
40
|
+
def initialize(api_key, api_secret, timeout = nil, **options)
|
41
|
+
raise ArgumentError, 'api_key and api_secret are required' if api_key.to_s.empty? || api_secret.to_s.empty?
|
42
|
+
|
43
|
+
@api_key = api_key
|
44
|
+
@api_secret = api_secret
|
45
|
+
@timeout = timeout || DEFAULT_TIMEOUT
|
42
46
|
@options = options
|
43
47
|
@auth_token = JWT.encode({ server: true }, @api_secret, 'HS256')
|
44
|
-
@base_url = options[:base_url] ||
|
48
|
+
@base_url = options[:base_url] || DEFAULT_BASE_URL
|
45
49
|
@conn = Faraday.new(url: @base_url) do |faraday|
|
46
50
|
faraday.options[:open_timeout] = @timeout
|
47
51
|
faraday.options[:timeout] = @timeout
|
48
52
|
faraday.request :multipart
|
49
|
-
faraday.adapter :
|
53
|
+
faraday.adapter :net_http_persistent, pool_size: 5 do |http|
|
54
|
+
# AWS load balancer idle timeout is 60 secs, so let's make it 59
|
55
|
+
http.idle_timeout = 59
|
56
|
+
end
|
50
57
|
end
|
51
58
|
end
|
52
59
|
|
60
|
+
# initializes a Stream Chat API Client from STREAM_KEY and STREAM_SECRET
|
61
|
+
# environmental variables. STREAM_CHAT_TIMEOUT and STREAM_CHAT_URL
|
62
|
+
# variables are optional.
|
63
|
+
# @param [hash] options extra options
|
64
|
+
def self.from_env(**options)
|
65
|
+
Client.new(ENV['STREAM_KEY'],
|
66
|
+
ENV['STREAM_SECRET'],
|
67
|
+
ENV['STREAM_CHAT_TIMEOUT'],
|
68
|
+
**{ base_url: ENV['STREAM_CHAT_URL'] }.merge(options))
|
69
|
+
end
|
70
|
+
|
71
|
+
# Sets the underlying Faraday http client.
|
72
|
+
#
|
73
|
+
# @param [client] an instance of Faraday::Connection
|
74
|
+
def set_http_client(client)
|
75
|
+
@conn = client
|
76
|
+
end
|
77
|
+
|
53
78
|
def create_token(user_id, exp = nil, iat = nil)
|
54
79
|
payload = { user_id: user_id }
|
55
80
|
payload['exp'] = exp unless exp.nil?
|
@@ -522,10 +547,9 @@ module StreamChat
|
|
522
547
|
headers = get_default_headers
|
523
548
|
headers['Authorization'] = @auth_token
|
524
549
|
headers['stream-auth-type'] = 'jwt'
|
525
|
-
url = [@base_url, relative_url].join('/')
|
526
550
|
params = {} if params.nil?
|
527
551
|
params = (get_default_params.merge(params).sort_by { |k, _v| k.to_s }).to_h
|
528
|
-
url = "#{
|
552
|
+
url = "#{relative_url}?#{URI.encode_www_form(params)}"
|
529
553
|
|
530
554
|
body = data.to_json if %w[patch post put].include? method.to_s
|
531
555
|
|
data/lib/stream-chat/version.rb
CHANGED
data/stream-chat.gemspec
CHANGED
@@ -28,7 +28,9 @@ Gem::Specification.new do |gem|
|
|
28
28
|
|
29
29
|
gem.add_dependency 'faraday'
|
30
30
|
gem.add_dependency 'faraday-multipart'
|
31
|
+
gem.add_dependency 'faraday-net_http_persistent'
|
31
32
|
gem.add_dependency 'jwt'
|
33
|
+
gem.add_dependency 'net-http-persistent'
|
32
34
|
gem.add_development_dependency 'rake'
|
33
35
|
gem.add_development_dependency 'rspec'
|
34
36
|
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.19.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-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday-net_http_persistent
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: jwt
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +66,20 @@ dependencies:
|
|
52
66
|
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: net-http-persistent
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: rake
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|