matrix_sdk 2.4.0 → 2.7.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/CHANGELOG.md +30 -0
- data/README.md +17 -2
- data/lib/matrix_sdk/api.rb +60 -18
- data/lib/matrix_sdk/bot/base.rb +843 -0
- data/lib/matrix_sdk/bot/main.rb +79 -0
- data/lib/matrix_sdk/bot.rb +4 -0
- data/lib/matrix_sdk/client.rb +44 -12
- data/lib/matrix_sdk/mxid.rb +3 -1
- data/lib/matrix_sdk/protocols/cs.rb +132 -106
- data/lib/matrix_sdk/protocols/msc.rb +5 -0
- data/lib/matrix_sdk/response.rb +2 -0
- data/lib/matrix_sdk/room.rb +140 -40
- data/lib/matrix_sdk/rooms/space.rb +3 -3
- data/lib/matrix_sdk/user.rb +25 -3
- data/lib/matrix_sdk/util/account_data_cache.rb +91 -0
- data/lib/matrix_sdk/util/extensions.rb +16 -6
- data/lib/matrix_sdk/util/tinycache.rb +20 -4
- data/lib/matrix_sdk/util/tinycache_adapter.rb +5 -1
- data/lib/matrix_sdk/util/uri.rb +16 -4
- data/lib/matrix_sdk/version.rb +1 -1
- data/lib/matrix_sdk.rb +11 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7db96470aa545490e2dc289243a1c133a708548e334748fee72cfa1bdba68543
|
4
|
+
data.tar.gz: 863bf01f82c86e9a6329bb505c727a872bf2f2b7b5dd8f51fbc633d74675d8b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f529e7679bd36fcad10184795d78f5dd0a72b0a496fe5f3a10d976d3a33e033cf2367ffb01b68bca3e0844ed91f496921a28e2ef7b20a5bd9589c21bb28a321e
|
7
|
+
data.tar.gz: e32d7dcbff2eac544e25f5c7598ac5f743e60dab8eac6394d1054a118882b0efdb3a69dca8ac93d1fae6ed6cf5912d6576156c3dcc9541c0b8b37bc6f9507600
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,33 @@
|
|
1
|
+
## 2.7.0 - 2022-08-12
|
2
|
+
|
3
|
+
- Adds a bot subsystem + DSL
|
4
|
+
- [An example](examples/bot_api.rb) can be found in the examples folder
|
5
|
+
- Adds additional useful helpers for Room and User
|
6
|
+
- Fixes Client.new_for_domain
|
7
|
+
- Improves the handling of MXIDs as strings
|
8
|
+
- Improves handling of caches for rooms
|
9
|
+
- Improves Client shutdown when using Client#start_listener_thread
|
10
|
+
- Improves account data handling, with caches on both Client and Room level
|
11
|
+
|
12
|
+
## 2.6.0 - 2022-07-15
|
13
|
+
|
14
|
+
- Adds some multi-thread usage support to the API (create your API/client with `threadsafe: :multithread/true/false`)
|
15
|
+
The API will currently default to running with multi-threaded requests. In case your application is single-threaded - or never performs requests from multiple threads - then you can set `threadsafe: true/false` to support connection reuse.
|
16
|
+
- Changes room finding to ignore non-canonical aliases by default
|
17
|
+
- Improves room alias handling
|
18
|
+
- Improves Ruby 3.0+ support
|
19
|
+
- Improves debug output by supporting PP (Ruby pretty print) on all MatrixSdk objects
|
20
|
+
|
21
|
+
## 2.5.0 - 2022-01-14
|
22
|
+
|
23
|
+
- Adds preliminary support for the Matrix v1.1 `client/v3` API
|
24
|
+
- Adds some support for knocking rooms
|
25
|
+
- Adds mutex synchronization on API requests to avoid some threading issues
|
26
|
+
- Fixes error on attempting to skip cache for certain requests (#19)
|
27
|
+
- Fixes inconsistency in MXID typing for the Client abstraction (#18 #20)
|
28
|
+
- Fixes missed autoloader entries for errors (#22)
|
29
|
+
- Fixes some potential issues arising from broken user-provided state data
|
30
|
+
|
1
31
|
## 2.4.0 - 2021-07-19
|
2
32
|
|
3
33
|
- Adds support for matrix: URI's according to MSC2312
|
data/README.md
CHANGED
@@ -8,6 +8,8 @@ Live YARD documentation can be found at; https://ruby-sdk.ananace.dev
|
|
8
8
|
|
9
9
|
## Example usage
|
10
10
|
|
11
|
+
For more fully-featured examples, check the [examples](examples/) folder.
|
12
|
+
|
11
13
|
```ruby
|
12
14
|
# Raw API usage
|
13
15
|
require 'matrix_sdk'
|
@@ -24,7 +26,7 @@ api.request :get, :federation_v1, '/version'
|
|
24
26
|
```
|
25
27
|
|
26
28
|
```ruby
|
27
|
-
# Client wrapper
|
29
|
+
# Client wrapper with login
|
28
30
|
require 'matrix_sdk'
|
29
31
|
|
30
32
|
client = MatrixSdk::Client.new 'https://example.com'
|
@@ -41,7 +43,7 @@ hq.send_text "This is an example message - don't actually do this ;)"
|
|
41
43
|
```
|
42
44
|
|
43
45
|
```ruby
|
44
|
-
# Client wrapper
|
46
|
+
# Client wrapper with token
|
45
47
|
require 'matrix_sdk'
|
46
48
|
|
47
49
|
client = MatrixSdk::Client.new 'https://example.com'
|
@@ -56,6 +58,19 @@ client.rooms.count
|
|
56
58
|
# => 5
|
57
59
|
```
|
58
60
|
|
61
|
+
```ruby
|
62
|
+
#!/bin/env ruby
|
63
|
+
# Bot DSL
|
64
|
+
require 'matrix_sdk/bot'
|
65
|
+
|
66
|
+
command :plug do
|
67
|
+
room.send_text <<~PLUG
|
68
|
+
The Ruby SDK is a fine method for writing applications communicating over the Matrix protocol.
|
69
|
+
It can easily be integrated with Rails, and it supports most client/bot use-cases.
|
70
|
+
PLUG
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
59
74
|
## Contributing
|
60
75
|
|
61
76
|
Bug reports and pull requests are welcome on GitHub at https://github.com/ananace/ruby-matrix-sdk
|
data/lib/matrix_sdk/api.rb
CHANGED
@@ -19,7 +19,7 @@ module MatrixSdk
|
|
19
19
|
}.freeze
|
20
20
|
|
21
21
|
attr_accessor :access_token, :connection_address, :connection_port, :device_id, :autoretry, :global_headers
|
22
|
-
attr_reader :homeserver, :validate_certificate, :open_timeout, :read_timeout, :well_known, :proxy_uri
|
22
|
+
attr_reader :homeserver, :validate_certificate, :open_timeout, :read_timeout, :well_known, :proxy_uri, :threadsafe
|
23
23
|
|
24
24
|
ignore_inspect :access_token, :logger
|
25
25
|
|
@@ -39,7 +39,10 @@ module MatrixSdk
|
|
39
39
|
# @option params [Hash] :global_headers Additional headers to set for all requests
|
40
40
|
# @option params [Boolean] :skip_login Should the API skip logging in if the HS URL contains user information
|
41
41
|
# @option params [Boolean] :synapse (true) Is the API connecting to a Synapse instance
|
42
|
-
# @option params [
|
42
|
+
# @option params [Boolean,:multithread] :threadsafe (:multithread) Should the connection be threadsafe/mutexed - or
|
43
|
+
# safe for simultaneous multi-thread usage. Will default to +:multithread+ - a.k.a. per-thread HTTP connections
|
44
|
+
# and requests
|
45
|
+
# @note Using threadsafe +:multithread+ currently doesn't support connection re-use
|
43
46
|
def initialize(homeserver, **params)
|
44
47
|
@homeserver = homeserver
|
45
48
|
raise ArgumentError, 'Homeserver URL must be String or URI' unless @homeserver.is_a?(String) || @homeserver.is_a?(URI)
|
@@ -57,13 +60,16 @@ module MatrixSdk
|
|
57
60
|
@validate_certificate = params.fetch(:validate_certificate, false)
|
58
61
|
@transaction_id = params.fetch(:transaction_id, 0)
|
59
62
|
@backoff_time = params.fetch(:backoff_time, 5000)
|
60
|
-
@open_timeout = params.fetch(:open_timeout,
|
61
|
-
@read_timeout = params.fetch(:read_timeout,
|
63
|
+
@open_timeout = params.fetch(:open_timeout, nil)
|
64
|
+
@read_timeout = params.fetch(:read_timeout, nil)
|
62
65
|
@well_known = params.fetch(:well_known, {})
|
63
66
|
@global_headers = DEFAULT_HEADERS.dup
|
64
67
|
@global_headers.merge!(params.fetch(:global_headers)) if params.key? :global_headers
|
65
68
|
@synapse = params.fetch(:synapse, true)
|
66
69
|
@http = nil
|
70
|
+
@inflight = []
|
71
|
+
|
72
|
+
self.threadsafe = params.fetch(:threadsafe, :multithread)
|
67
73
|
|
68
74
|
([params.fetch(:protocols, [:CS])].flatten - protocols).each do |proto|
|
69
75
|
self.class.include MatrixSdk::Protocols.const_get(proto)
|
@@ -243,6 +249,17 @@ module MatrixSdk
|
|
243
249
|
@proxy_uri = proxy_uri
|
244
250
|
end
|
245
251
|
|
252
|
+
# @param [Boolean,:multithread] threadsafe What level of thread-safety the API should use
|
253
|
+
# @return [Boolean,:multithread]
|
254
|
+
def threadsafe=(threadsafe)
|
255
|
+
raise ArgumentError, 'Threadsafe must be either a boolean or :multithread' unless [true, false, :multithread].include? threadsafe
|
256
|
+
raise ArugmentError, 'JRuby only support :multithread/false for threadsafe' if RUBY_ENGINE == 'jruby' && threadsafe == true
|
257
|
+
|
258
|
+
@threadsafe = threadsafe
|
259
|
+
@http_lock = nil unless threadsafe == true
|
260
|
+
@threadsafe
|
261
|
+
end
|
262
|
+
|
246
263
|
# Perform a raw Matrix API request
|
247
264
|
#
|
248
265
|
# @example Simple API query
|
@@ -281,14 +298,27 @@ module MatrixSdk
|
|
281
298
|
|
282
299
|
req_obj = construct_request(url: url, method: method, **options)
|
283
300
|
print_http(req_obj, id: req_id)
|
284
|
-
|
301
|
+
response = duration = nil
|
302
|
+
|
303
|
+
loc_http = http
|
304
|
+
perform_request = proc do
|
305
|
+
@inflight << loc_http
|
285
306
|
dur_start = Time.now
|
286
|
-
response =
|
307
|
+
response = loc_http.request req_obj
|
287
308
|
dur_end = Time.now
|
288
309
|
duration = dur_end - dur_start
|
289
310
|
rescue EOFError
|
290
311
|
logger.error 'Socket closed unexpectedly'
|
291
312
|
raise
|
313
|
+
ensure
|
314
|
+
@inflight.delete loc_http
|
315
|
+
end
|
316
|
+
|
317
|
+
if @threadsafe == true
|
318
|
+
http_lock.synchronize { perform_request.call }
|
319
|
+
else
|
320
|
+
perform_request.call
|
321
|
+
loc_http.finish if @threadsafe == :multithread
|
292
322
|
end
|
293
323
|
print_http(response, duration: duration, id: req_id)
|
294
324
|
|
@@ -330,6 +360,10 @@ module MatrixSdk
|
|
330
360
|
ret
|
331
361
|
end
|
332
362
|
|
363
|
+
def stop_inflight
|
364
|
+
@inflight.each(&:finish)
|
365
|
+
end
|
366
|
+
|
333
367
|
private
|
334
368
|
|
335
369
|
def construct_request(method:, url:, **options)
|
@@ -392,18 +426,26 @@ module MatrixSdk
|
|
392
426
|
|
393
427
|
host = (@connection_address || homeserver.host)
|
394
428
|
port = (@connection_port || homeserver.port)
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
429
|
+
|
430
|
+
connection = @http unless @threadsafe == :multithread
|
431
|
+
connection ||= if proxy_uri
|
432
|
+
Net::HTTP.new(host, port, proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
|
433
|
+
else
|
434
|
+
Net::HTTP.new(host, port)
|
435
|
+
end
|
436
|
+
|
437
|
+
connection.open_timeout = open_timeout if open_timeout
|
438
|
+
connection.read_timeout = read_timeout if read_timeout
|
439
|
+
connection.use_ssl = homeserver.scheme == 'https'
|
440
|
+
connection.verify_mode = validate_certificate ? ::OpenSSL::SSL::VERIFY_PEER : ::OpenSSL::SSL::VERIFY_NONE
|
441
|
+
connection.start
|
442
|
+
@http = connection unless @threadsafe == :multithread
|
443
|
+
|
444
|
+
connection
|
445
|
+
end
|
446
|
+
|
447
|
+
def http_lock
|
448
|
+
@http_lock ||= Mutex.new if @threadsafe == true
|
407
449
|
end
|
408
450
|
end
|
409
451
|
end
|