matrix_sdk 2.5.0 → 2.8.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 +27 -0
- data/README.md +17 -2
- data/lib/matrix_sdk/api.rb +56 -17
- data/lib/matrix_sdk/bot/base.rb +847 -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 +2 -0
- data/lib/matrix_sdk/protocols/cs.rb +12 -18
- data/lib/matrix_sdk/protocols/msc.rb +5 -4
- data/lib/matrix_sdk/response.rb +2 -0
- data/lib/matrix_sdk/room.rb +172 -89
- data/lib/matrix_sdk/rooms/space.rb +2 -2
- data/lib/matrix_sdk/user.rb +23 -1
- 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/state_event_cache.rb +92 -0
- data/lib/matrix_sdk/util/tinycache.rb +8 -2
- data/lib/matrix_sdk/util/tinycache_adapter.rb +11 -1
- data/lib/matrix_sdk/util/uri.rb +16 -4
- data/lib/matrix_sdk/version.rb +1 -1
- data/lib/matrix_sdk.rb +7 -1
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd493a721423c1f1a7da7b2ff678ad8e1a949f258fe613616ebedab39d5ae204
|
4
|
+
data.tar.gz: 52e6563d1dbb42cd5acddf3809df720fb6ecc5b6f49cbdc14606450e908c32c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fa0a6cbae2b6fa8ab91961df79082017be6a50028cc7b318ad70a5be9c76b8488b4b24cbef5e5a768ac34076236430683d518c18fccb296290599427bd71095
|
7
|
+
data.tar.gz: f62ad6791ee5f3921869d2431e55e3a1f44501af1b8c966a957fbcacbcaf809edb2e47b8d8b65d1393c268ff58b19e21fc966b1660c671d4d257121bf832dadf
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,30 @@
|
|
1
|
+
## 2.8.0 - 2022-08-19
|
2
|
+
|
3
|
+
- Drops support for EoL Ruby 2.6
|
4
|
+
- Adds helpers for accessing room state
|
5
|
+
- Fixes Client#sync_token usage
|
6
|
+
- Improves caching of state events in rooms
|
7
|
+
|
8
|
+
## 2.7.0 - 2022-08-12
|
9
|
+
|
10
|
+
- Adds a bot subsystem + DSL
|
11
|
+
- [An example](examples/bot_api.rb) can be found in the examples folder
|
12
|
+
- Adds additional useful helpers for Room and User
|
13
|
+
- Fixes Client.new_for_domain
|
14
|
+
- Improves the handling of MXIDs as strings
|
15
|
+
- Improves handling of caches for rooms
|
16
|
+
- Improves Client shutdown when using Client#start_listener_thread
|
17
|
+
- Improves account data handling, with caches on both Client and Room level
|
18
|
+
|
19
|
+
## 2.6.0 - 2022-07-15
|
20
|
+
|
21
|
+
- Adds some multi-thread usage support to the API (create your API/client with `threadsafe: :multithread/true/false`)
|
22
|
+
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.
|
23
|
+
- Changes room finding to ignore non-canonical aliases by default
|
24
|
+
- Improves room alias handling
|
25
|
+
- Improves Ruby 3.0+ support
|
26
|
+
- Improves debug output by supporting PP (Ruby pretty print) on all MatrixSdk objects
|
27
|
+
|
1
28
|
## 2.5.0 - 2022-01-14
|
2
29
|
|
3
30
|
- Adds preliminary support for the Matrix v1.1 `client/v3` API
|
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)
|
@@ -64,7 +67,9 @@ module MatrixSdk
|
|
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
|
67
|
-
@
|
70
|
+
@inflight = []
|
71
|
+
|
72
|
+
self.threadsafe = params.fetch(:threadsafe, :multithread)
|
68
73
|
|
69
74
|
([params.fetch(:protocols, [:CS])].flatten - protocols).each do |proto|
|
70
75
|
self.class.include MatrixSdk::Protocols.const_get(proto)
|
@@ -244,6 +249,17 @@ module MatrixSdk
|
|
244
249
|
@proxy_uri = proxy_uri
|
245
250
|
end
|
246
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
|
+
|
247
263
|
# Perform a raw Matrix API request
|
248
264
|
#
|
249
265
|
# @example Simple API query
|
@@ -284,14 +300,25 @@ module MatrixSdk
|
|
284
300
|
print_http(req_obj, id: req_id)
|
285
301
|
response = duration = nil
|
286
302
|
|
287
|
-
|
303
|
+
loc_http = http
|
304
|
+
perform_request = proc do
|
305
|
+
@inflight << loc_http
|
288
306
|
dur_start = Time.now
|
289
|
-
response =
|
307
|
+
response = loc_http.request req_obj
|
290
308
|
dur_end = Time.now
|
291
309
|
duration = dur_end - dur_start
|
292
310
|
rescue EOFError
|
293
311
|
logger.error 'Socket closed unexpectedly'
|
294
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
|
295
322
|
end
|
296
323
|
print_http(response, duration: duration, id: req_id)
|
297
324
|
|
@@ -333,6 +360,10 @@ module MatrixSdk
|
|
333
360
|
ret
|
334
361
|
end
|
335
362
|
|
363
|
+
def stop_inflight
|
364
|
+
@inflight.each(&:finish)
|
365
|
+
end
|
366
|
+
|
336
367
|
private
|
337
368
|
|
338
369
|
def construct_request(method:, url:, **options)
|
@@ -395,18 +426,26 @@ module MatrixSdk
|
|
395
426
|
|
396
427
|
host = (@connection_address || homeserver.host)
|
397
428
|
port = (@connection_port || homeserver.port)
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
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
|
410
449
|
end
|
411
450
|
end
|
412
451
|
end
|