matrix_sdk 0.0.4 → 0.1.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 +7 -0
- data/CHANGELOG.md +11 -0
- data/README.md +2 -0
- data/examples/simple_client.rb +6 -3
- data/lib/matrix_sdk.rb +13 -2
- data/lib/matrix_sdk/api.rb +70 -720
- data/lib/matrix_sdk/application_service.rb +210 -0
- data/lib/matrix_sdk/client.rb +69 -44
- data/lib/matrix_sdk/extensions.rb +22 -10
- data/lib/matrix_sdk/protocols/as.rb +5 -0
- data/lib/matrix_sdk/protocols/cs.rb +799 -0
- data/lib/matrix_sdk/protocols/is.rb +33 -0
- data/lib/matrix_sdk/protocols/ss.rb +12 -0
- data/lib/matrix_sdk/room.rb +15 -38
- data/lib/matrix_sdk/user.rb +6 -4
- data/lib/matrix_sdk/version.rb +1 -1
- data/matrix-sdk.gemspec +4 -3
- metadata +25 -7
@@ -0,0 +1,33 @@
|
|
1
|
+
module MatrixSdk::Protocols::IS
|
2
|
+
def identity_status
|
3
|
+
request(:get, :identity_api_v1, '/')
|
4
|
+
end
|
5
|
+
|
6
|
+
def identity_get_pubkey(id)
|
7
|
+
id = ERB::Util.url_encode id.to_s
|
8
|
+
|
9
|
+
request(:get, :identity_api_v1, "/pubkey/#{id}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def identity_pubkey_isvalid(key, ephemeral: false)
|
13
|
+
if ephemeral
|
14
|
+
request(:get, :identity_api_v1, '/pubkey/ephemeral/isvalid', query: { public_key: key })
|
15
|
+
else
|
16
|
+
request(:get, :identity_api_v1, '/pubkey/isvalid', query: { public_key: key })
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def identity_pubkey_ephemeral_isvalid(key)
|
21
|
+
identity_pubkey_isvalid(key, ephemeral: true)
|
22
|
+
end
|
23
|
+
|
24
|
+
def identity_lookup(medium:, address:)
|
25
|
+
request(:get, :identity_api_v1, '/lookup', query: { medium: medium, address: address })
|
26
|
+
end
|
27
|
+
|
28
|
+
def identity_bulk_lookup(threepids)
|
29
|
+
request(:post, :identity_api_v1, '/bulk_lookup', body: { threepids: threepids })
|
30
|
+
end
|
31
|
+
|
32
|
+
# XXX
|
33
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module MatrixSdk::Protocols::SS
|
2
|
+
# Gets the server version
|
3
|
+
def server_version
|
4
|
+
Response.new(self, request(:get, :federation_v1, '/version').server).tap do |resp|
|
5
|
+
resp.instance_eval <<-'CODE', __FILE__, __LINE__ + 1
|
6
|
+
def to_s
|
7
|
+
"#{name} #{version}"
|
8
|
+
end
|
9
|
+
CODE
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/matrix_sdk/room.rb
CHANGED
@@ -3,6 +3,8 @@ require 'matrix_sdk'
|
|
3
3
|
module MatrixSdk
|
4
4
|
# A class for tracking the information about a room on Matrix
|
5
5
|
class Room
|
6
|
+
include MatrixSdk::Logging
|
7
|
+
|
6
8
|
# @!attribute [rw] canonical_alias
|
7
9
|
# @return [String, nil] the canonical alias of the room
|
8
10
|
# @!attribute [rw] event_history_limit
|
@@ -48,7 +50,7 @@ module MatrixSdk
|
|
48
50
|
# An inspect method that skips a handful of instance variables to avoid
|
49
51
|
# flooding the terminal with debug data.
|
50
52
|
# @return [String] a regular inspect string without the data for some variables
|
51
|
-
ignore_inspect :client, :members, :events, :prev_batch,
|
53
|
+
ignore_inspect :client, :members, :events, :prev_batch, :logger,
|
52
54
|
:on_event, :on_state_event, :on_ephemeral_event
|
53
55
|
|
54
56
|
alias room_id id
|
@@ -66,6 +68,7 @@ module MatrixSdk
|
|
66
68
|
@guest_access = nil
|
67
69
|
@members = []
|
68
70
|
@events = []
|
71
|
+
@members_loaded = false
|
69
72
|
@event_history_limit = 10
|
70
73
|
|
71
74
|
@prev_batch = nil
|
@@ -77,10 +80,6 @@ module MatrixSdk
|
|
77
80
|
logger.debug "Created room #{room_id}"
|
78
81
|
end
|
79
82
|
|
80
|
-
def logger
|
81
|
-
@logger ||= Logging.logger[self]
|
82
|
-
end
|
83
|
-
|
84
83
|
#
|
85
84
|
# State readers
|
86
85
|
#
|
@@ -100,7 +99,7 @@ module MatrixSdk
|
|
100
99
|
|
101
100
|
members = joined_members
|
102
101
|
.reject { |m| m.user_id == client.mxid }
|
103
|
-
.map(&:
|
102
|
+
.map(&:display_name)
|
104
103
|
|
105
104
|
return members.first if members.one?
|
106
105
|
return "#{members.first} and #{members.last}" if members.count == 2
|
@@ -111,13 +110,14 @@ module MatrixSdk
|
|
111
110
|
|
112
111
|
# Populates and returns the #members array
|
113
112
|
def joined_members
|
114
|
-
return members
|
113
|
+
return members if @members_loaded && !members.empty?
|
115
114
|
|
116
115
|
client.api.get_room_members(id)[:chunk].each do |chunk|
|
117
116
|
next unless chunk [:content][:membership] == 'join'
|
118
117
|
|
119
|
-
ensure_member(User.new(client, chunk[:state_key], display_name: chunk[:content].fetch(:displayname)))
|
118
|
+
ensure_member(User.new(client, chunk[:state_key], display_name: chunk[:content].fetch(:displayname, nil)))
|
120
119
|
end
|
120
|
+
@members_loaded = true
|
121
121
|
members
|
122
122
|
end
|
123
123
|
|
@@ -242,6 +242,7 @@ module MatrixSdk
|
|
242
242
|
# @param reason [String,nil] the reason for the redaction
|
243
243
|
def redact_message(event_id, reason = nil)
|
244
244
|
client.api.redact_event(id, event_id, reason: reason)
|
245
|
+
true
|
245
246
|
end
|
246
247
|
|
247
248
|
# Backfills messages into the room history
|
@@ -256,6 +257,7 @@ module MatrixSdk
|
|
256
257
|
events.each do |ev|
|
257
258
|
put_event(ev)
|
258
259
|
end
|
260
|
+
true
|
259
261
|
end
|
260
262
|
|
261
263
|
#
|
@@ -269,8 +271,6 @@ module MatrixSdk
|
|
269
271
|
user_id = user_id.id if user_id.is_a? MatrixSdk::User
|
270
272
|
client.api.invite_user(id, user_id)
|
271
273
|
true
|
272
|
-
rescue MatrixError
|
273
|
-
false
|
274
274
|
end
|
275
275
|
|
276
276
|
# Kicks a user from the room
|
@@ -281,8 +281,6 @@ module MatrixSdk
|
|
281
281
|
user_id = user_id.id if user_id.is_a? MatrixSdk::User
|
282
282
|
client.api.kick_user(id, user_id, reason: reason)
|
283
283
|
true
|
284
|
-
rescue MatrixError
|
285
|
-
false
|
286
284
|
end
|
287
285
|
|
288
286
|
# Bans a user from the room
|
@@ -293,8 +291,6 @@ module MatrixSdk
|
|
293
291
|
user_id = user_id.id if user_id.is_a? MatrixSdk::User
|
294
292
|
client.api.ban_user(id, user_id, reason: reason)
|
295
293
|
true
|
296
|
-
rescue MatrixError
|
297
|
-
false
|
298
294
|
end
|
299
295
|
|
300
296
|
# Unbans a user from the room
|
@@ -304,8 +300,6 @@ module MatrixSdk
|
|
304
300
|
user_id = user_id.id if user_id.is_a? MatrixSdk::User
|
305
301
|
client.api.unban_user(id, user_id)
|
306
302
|
true
|
307
|
-
rescue MatrixError
|
308
|
-
false
|
309
303
|
end
|
310
304
|
|
311
305
|
# Requests to be removed from the room
|
@@ -314,8 +308,6 @@ module MatrixSdk
|
|
314
308
|
client.api.leave_room(id)
|
315
309
|
client.rooms.delete id
|
316
310
|
true
|
317
|
-
rescue MatrixError
|
318
|
-
false
|
319
311
|
end
|
320
312
|
|
321
313
|
# Retrieves a custom entry from the room-specific account data
|
@@ -330,6 +322,7 @@ module MatrixSdk
|
|
330
322
|
# @param account_data [Hash] the data to store
|
331
323
|
def set_account_data(type, account_data)
|
332
324
|
client.api.set_room_account_data(client.mxid, id, type, account_data)
|
325
|
+
true
|
333
326
|
end
|
334
327
|
|
335
328
|
# Changes the room-specific user profile
|
@@ -347,6 +340,7 @@ module MatrixSdk
|
|
347
340
|
data[:avatar_url] = params[:avatar_url] unless params[:avatar_url].nil?
|
348
341
|
|
349
342
|
client.api.set_membership(id, client.mxid, 'join', params.fetch(:reason, 'Updating room profile information'), data)
|
343
|
+
true
|
350
344
|
end
|
351
345
|
|
352
346
|
def tags
|
@@ -369,10 +363,12 @@ module MatrixSdk
|
|
369
363
|
|
370
364
|
def remove_tag(tag)
|
371
365
|
client.api.remove_user_tag(client.mxid, id, tag)
|
366
|
+
true
|
372
367
|
end
|
373
368
|
|
374
369
|
def add_tag(tag, params = {})
|
375
370
|
client.api.add_user_tag(client.mxid, id, tag, params)
|
371
|
+
true
|
376
372
|
end
|
377
373
|
|
378
374
|
#
|
@@ -382,8 +378,6 @@ module MatrixSdk
|
|
382
378
|
def name=(name)
|
383
379
|
client.api.set_room_name(id, name)
|
384
380
|
@name = name
|
385
|
-
rescue MatrixError
|
386
|
-
nil
|
387
381
|
end
|
388
382
|
|
389
383
|
# Reloads the name of the room
|
@@ -393,15 +387,11 @@ module MatrixSdk
|
|
393
387
|
changed = data[:name] != name
|
394
388
|
@name = data[:name] if changed
|
395
389
|
changed
|
396
|
-
rescue MatrixError
|
397
|
-
false
|
398
390
|
end
|
399
391
|
|
400
392
|
def topic=(topic)
|
401
393
|
client.api.set_room_topic(id, topic)
|
402
394
|
@topic = topic
|
403
|
-
rescue MatrixError
|
404
|
-
nil
|
405
395
|
end
|
406
396
|
|
407
397
|
# Reloads the topic of the room
|
@@ -411,8 +401,6 @@ module MatrixSdk
|
|
411
401
|
changed = data[:topic] != topic
|
412
402
|
@topic = data[:topic] if changed
|
413
403
|
changed
|
414
|
-
rescue MatrixError
|
415
|
-
false
|
416
404
|
end
|
417
405
|
|
418
406
|
# Add an alias to the room
|
@@ -421,8 +409,6 @@ module MatrixSdk
|
|
421
409
|
client.api.set_room_alias(id, room_alias)
|
422
410
|
@aliases << room_alias
|
423
411
|
true
|
424
|
-
rescue MatrixError
|
425
|
-
false
|
426
412
|
end
|
427
413
|
|
428
414
|
# Reloads the list of aliases by an API query
|
@@ -440,8 +426,6 @@ module MatrixSdk
|
|
440
426
|
changed = new_aliases != aliases
|
441
427
|
@aliases = new_aliases if changed
|
442
428
|
changed
|
443
|
-
rescue MatrixError
|
444
|
-
false
|
445
429
|
end
|
446
430
|
|
447
431
|
def invite_only=(invite_only)
|
@@ -452,8 +436,6 @@ module MatrixSdk
|
|
452
436
|
def join_rule=(join_rule)
|
453
437
|
client.api.set_join_rule(id, join_rule)
|
454
438
|
@join_rule = join_rule
|
455
|
-
rescue MatrixError
|
456
|
-
nil
|
457
439
|
end
|
458
440
|
|
459
441
|
def allow_guests=(allow_guests)
|
@@ -464,8 +446,6 @@ module MatrixSdk
|
|
464
446
|
def guest_access=(guest_access)
|
465
447
|
client.api.set_guest_access(id, guest_access)
|
466
448
|
@guest_access = guest_access
|
467
|
-
rescue MatrixError
|
468
|
-
nil
|
469
449
|
end
|
470
450
|
|
471
451
|
# Modifies the power levels of the room
|
@@ -486,8 +466,6 @@ module MatrixSdk
|
|
486
466
|
|
487
467
|
client.api.set_power_levels(id, data)
|
488
468
|
true
|
489
|
-
rescue MatrixError
|
490
|
-
false
|
491
469
|
end
|
492
470
|
|
493
471
|
# Modifies the required power levels for actions in the room
|
@@ -508,8 +486,7 @@ module MatrixSdk
|
|
508
486
|
end
|
509
487
|
|
510
488
|
client.api.set_power.levels(id, data)
|
511
|
-
|
512
|
-
false
|
489
|
+
true
|
513
490
|
end
|
514
491
|
|
515
492
|
private
|
data/lib/matrix_sdk/user.rb
CHANGED
@@ -39,8 +39,6 @@ module MatrixSdk
|
|
39
39
|
def display_name=(name)
|
40
40
|
client.api.set_display_name(id, name)
|
41
41
|
@display_name = name
|
42
|
-
rescue MatrixError
|
43
|
-
nil
|
44
42
|
end
|
45
43
|
|
46
44
|
# Gets a friendly name of the user
|
@@ -58,8 +56,12 @@ module MatrixSdk
|
|
58
56
|
def avatar_url=(url)
|
59
57
|
client.api.set_avatar_url(id, url)
|
60
58
|
@avatar_url = url
|
61
|
-
|
62
|
-
|
59
|
+
end
|
60
|
+
|
61
|
+
def device_keys
|
62
|
+
@device_keys ||= client.api.keys_query(device_keys: { id => [] }).yield_self do |resp|
|
63
|
+
resp[:device_keys][id.to_sym]
|
64
|
+
end
|
63
65
|
end
|
64
66
|
end
|
65
67
|
end
|
data/lib/matrix_sdk/version.rb
CHANGED
data/matrix-sdk.gemspec
CHANGED
@@ -6,9 +6,9 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.authors = ['Alexander Olofsson']
|
7
7
|
spec.email = ['ace@haxalot.com']
|
8
8
|
|
9
|
-
spec.summary = ''
|
10
|
-
spec.description =
|
11
|
-
spec.homepage = 'https://github.com/ananace/
|
9
|
+
spec.summary = 'SDK for applications using the Matrix protocol'
|
10
|
+
spec.description = spec.summary
|
11
|
+
spec.homepage = 'https://github.com/ananace/ruby-matrix-sdk'
|
12
12
|
spec.license = 'MIT'
|
13
13
|
|
14
14
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency 'mocha'
|
22
22
|
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'simplecov'
|
23
24
|
spec.add_development_dependency 'test-unit'
|
24
25
|
|
25
26
|
# TODO: Put this in a better location
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matrix_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Olofsson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logging
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: test-unit
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,7 +94,7 @@ dependencies:
|
|
80
94
|
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
|
-
description:
|
97
|
+
description: SDK for applications using the Matrix protocol
|
84
98
|
email:
|
85
99
|
- ace@haxalot.com
|
86
100
|
executables: []
|
@@ -99,16 +113,21 @@ files:
|
|
99
113
|
- examples/simple_client.rb
|
100
114
|
- lib/matrix_sdk.rb
|
101
115
|
- lib/matrix_sdk/api.rb
|
116
|
+
- lib/matrix_sdk/application_service.rb
|
102
117
|
- lib/matrix_sdk/client.rb
|
103
118
|
- lib/matrix_sdk/errors.rb
|
104
119
|
- lib/matrix_sdk/extensions.rb
|
105
120
|
- lib/matrix_sdk/mxid.rb
|
121
|
+
- lib/matrix_sdk/protocols/as.rb
|
122
|
+
- lib/matrix_sdk/protocols/cs.rb
|
123
|
+
- lib/matrix_sdk/protocols/is.rb
|
124
|
+
- lib/matrix_sdk/protocols/ss.rb
|
106
125
|
- lib/matrix_sdk/response.rb
|
107
126
|
- lib/matrix_sdk/room.rb
|
108
127
|
- lib/matrix_sdk/user.rb
|
109
128
|
- lib/matrix_sdk/version.rb
|
110
129
|
- matrix-sdk.gemspec
|
111
|
-
homepage: https://github.com/ananace/
|
130
|
+
homepage: https://github.com/ananace/ruby-matrix-sdk
|
112
131
|
licenses:
|
113
132
|
- MIT
|
114
133
|
metadata: {}
|
@@ -127,9 +146,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
146
|
- !ruby/object:Gem::Version
|
128
147
|
version: '0'
|
129
148
|
requirements: []
|
130
|
-
|
131
|
-
rubygems_version: 2.7.7
|
149
|
+
rubygems_version: 3.0.3
|
132
150
|
signing_key:
|
133
151
|
specification_version: 4
|
134
|
-
summary:
|
152
|
+
summary: SDK for applications using the Matrix protocol
|
135
153
|
test_files: []
|