matrix_sdk 2.3.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,8 +13,10 @@ module MatrixSdk::Protocols::CS
13
13
  def client_api_versions
14
14
  (@client_api_versions ||= request(:get, :client, '/versions')).versions.tap do |vers|
15
15
  vers.instance_eval <<-'CODE', __FILE__, __LINE__ + 1
16
- def latest
17
- last
16
+ if !respond_to? :latest
17
+ def latest
18
+ last
19
+ end
18
20
  end
19
21
  CODE
20
22
  end
@@ -39,10 +41,20 @@ module MatrixSdk::Protocols::CS
39
41
  end
40
42
  end
41
43
 
44
+ # Gets the latest version of the client API
45
+ # @return [Symbol] :client_r0 / :client_v3 / etc
46
+ def client_api_latest
47
+ @client_api_latest ||= :client_v3 if client_api_versions.any? { |v| v.start_with? 'v1.1' }
48
+ @client_api_latest ||= :client_r0
49
+ rescue StandardError => e
50
+ logger.warn "Failed to look up supported client API, defaulting to r0. The error was #{e.class}: #{e}"
51
+ @client_api_latest ||= :client_r0
52
+ end
53
+
42
54
  # Gets the list of available methods for logging in
43
55
  # @return [Response]
44
56
  def allowed_login_methods
45
- request(:get, :client_r0, '/login')
57
+ request(:get, client_api_latest, '/login')
46
58
  end
47
59
 
48
60
  # Runs the client API /sync method
@@ -64,7 +76,7 @@ module MatrixSdk::Protocols::CS
64
76
  query[:timeout] = params.delete(:timeout_ms).to_i if params.key? :timeout_ms
65
77
  query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
66
78
 
67
- request(:get, :client_r0, '/sync', query: query)
79
+ request(:get, client_api_latest, '/sync', query: query)
68
80
  end
69
81
 
70
82
  # Registers a user using the client API /register endpoint
@@ -90,7 +102,7 @@ module MatrixSdk::Protocols::CS
90
102
  store_token = params.delete(:store_token) { !protocol?(:AS) }
91
103
  store_device_id = params.delete(:store_device_id) { store_token }
92
104
 
93
- request(:post, :client_r0, '/register', body: params, query: query).tap do |resp|
105
+ request(:post, client_api_latest, '/register', body: params, query: query).tap do |resp|
94
106
  @access_token = resp.token if resp.key?(:token) && store_token
95
107
  @device_id = resp.device_id if resp.key?(:device_id) && store_device_id
96
108
  end
@@ -113,7 +125,7 @@ module MatrixSdk::Protocols::CS
113
125
  next_link: next_link
114
126
  }.compact
115
127
 
116
- request(:post, :client_r0, '/register/email/requestToken', body: body)
128
+ request(:post, client_api_latest, '/register/email/requestToken', body: body)
117
129
  end
118
130
 
119
131
  # Requests to register a phone number to the current account
@@ -135,7 +147,7 @@ module MatrixSdk::Protocols::CS
135
147
  next_link: next_link
136
148
  }.compact
137
149
 
138
- request(:post, :client_r0, '/register/msisdn/requestToken', body: body)
150
+ request(:post, client_api_latest, '/register/msisdn/requestToken', body: body)
139
151
  end
140
152
 
141
153
  # Checks if a given username is available and valid for registering
@@ -148,7 +160,7 @@ module MatrixSdk::Protocols::CS
148
160
  # @return [Response]
149
161
  # @see https://matrix.org/docs/spec/client_server/latest.html#get-matrix-client-r0-register-available
150
162
  def username_available?(username)
151
- request(:get, :client_r0, '/register/available', query: { username: username })
163
+ request(:get, client_api_latest, '/register/available', query: { username: username })
152
164
  end
153
165
 
154
166
  # Logs in using the client API /login endpoint, and optionally stores the resulting access for API usage
@@ -190,8 +202,8 @@ module MatrixSdk::Protocols::CS
190
202
  }.merge params
191
203
  data[:device_id] = device_id if device_id
192
204
 
193
- request(:post, :client_r0, '/login', body: data, query: query).tap do |resp|
194
- @access_token = resp.token if resp.key?(:token) && options[:store_token]
205
+ request(:post, client_api_latest, '/login', body: data, query: query).tap do |resp|
206
+ @access_token = resp.access_token if resp.key?(:access_token) && options[:store_token]
195
207
  @device_id = resp.device_id if resp.key?(:device_id) && options[:store_device_id]
196
208
  end
197
209
  end
@@ -204,7 +216,7 @@ module MatrixSdk::Protocols::CS
204
216
  query = {}
205
217
  query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
206
218
 
207
- request(:post, :client_r0, '/logout', query: query)
219
+ request(:post, client_api_latest, '/logout', query: query)
208
220
  end
209
221
 
210
222
  # Logs out the currently logged in user
@@ -215,7 +227,7 @@ module MatrixSdk::Protocols::CS
215
227
  query = {}
216
228
  query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
217
229
 
218
- request(:post, :client_r0, '/logout/all', query: query)
230
+ request(:post, client_api_latest, '/logout/all', query: query)
219
231
  end
220
232
 
221
233
  # Changes the users password
@@ -235,7 +247,7 @@ module MatrixSdk::Protocols::CS
235
247
  auth: auth
236
248
  }
237
249
 
238
- request(:post, :client_r0, '/account/password', body: body, query: query)
250
+ request(:post, client_api_latest, '/account/password', body: body, query: query)
239
251
  end
240
252
 
241
253
  # Requests an authentication token based on an email address
@@ -255,7 +267,7 @@ module MatrixSdk::Protocols::CS
255
267
  next_link: next_link
256
268
  }.compact
257
269
 
258
- request(:post, :client_r0, '/account/password/email/requestToken', body: body)
270
+ request(:post, client_api_latest, '/account/password/email/requestToken', body: body)
259
271
  end
260
272
 
261
273
  # Requests an authentication token based on a phone number
@@ -277,7 +289,7 @@ module MatrixSdk::Protocols::CS
277
289
  next_link: next_link
278
290
  }.compact
279
291
 
280
- request(:post, :client_r0, '/account/password/msisdn/requestToken', body: body)
292
+ request(:post, client_api_latest, '/account/password/msisdn/requestToken', body: body)
281
293
  end
282
294
 
283
295
  # Deactivates the current account, logging out all connected devices and preventing future logins
@@ -293,14 +305,14 @@ module MatrixSdk::Protocols::CS
293
305
  id_server: id_server
294
306
  }.compact
295
307
 
296
- request(:post, :client_r0, '/account/deactivate', body: body)
308
+ request(:post, client_api_latest, '/account/deactivate', body: body)
297
309
  end
298
310
 
299
311
  def get_3pids(**params)
300
312
  query = {}
301
313
  query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
302
314
 
303
- request(:get, :client_r0, '/account/3pid', query: query)
315
+ request(:get, client_api_latest, '/account/3pid', query: query)
304
316
  end
305
317
 
306
318
  # Finishes a 3PID addition to the current user
@@ -318,7 +330,7 @@ module MatrixSdk::Protocols::CS
318
330
  auth: auth_data
319
331
  }.compact
320
332
 
321
- request(:post, :client_r0, '/account/3pid/add', body: body)
333
+ request(:post, client_api_latest, '/account/3pid/add', body: body)
322
334
  end
323
335
 
324
336
  # Finishes binding a 3PID to the current user
@@ -338,7 +350,7 @@ module MatrixSdk::Protocols::CS
338
350
  sid: session
339
351
  }
340
352
 
341
- request(:post, :client_r0, '/account/3pid/bind', body: body)
353
+ request(:post, client_api_latest, '/account/3pid/bind', body: body)
342
354
  end
343
355
 
344
356
  # Deletes a 3PID from the current user, this method might not unbind it from the identity server
@@ -356,7 +368,7 @@ module MatrixSdk::Protocols::CS
356
368
  medium: medium
357
369
  }
358
370
 
359
- request(:post, :client_r0, '/account/3pid/delete', body: body)
371
+ request(:post, client_api_latest, '/account/3pid/delete', body: body)
360
372
  end
361
373
 
362
374
  # Unbinds a 3PID from the current user
@@ -374,7 +386,7 @@ module MatrixSdk::Protocols::CS
374
386
  medium: medium
375
387
  }
376
388
 
377
- request(:post, :client_r0, '/account/3pid/unbind', body: body)
389
+ request(:post, client_api_latest, '/account/3pid/unbind', body: body)
378
390
  end
379
391
 
380
392
  # Gets the list of rooms joined by the current user
@@ -385,7 +397,7 @@ module MatrixSdk::Protocols::CS
385
397
  query = {}
386
398
  query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
387
399
 
388
- request(:get, :client_r0, '/joined_rooms', query: query)
400
+ request(:get, client_api_latest, '/joined_rooms', query: query)
389
401
  end
390
402
 
391
403
  # Gets the list of public rooms on a Matrix server
@@ -418,7 +430,7 @@ module MatrixSdk::Protocols::CS
418
430
  query = query.merge(params).compact
419
431
  end
420
432
 
421
- request(method, :client_r0, '/publicRooms', query: query, body: body)
433
+ request(method, client_api_latest, '/publicRooms', query: query, body: body)
422
434
  end
423
435
 
424
436
  # Creates a new room
@@ -440,7 +452,29 @@ module MatrixSdk::Protocols::CS
440
452
  content[:invite] = [params.delete(:invite)].flatten if params[:invite]
441
453
  content.merge! params
442
454
 
443
- request(:post, :client_r0, '/createRoom', body: content, query: query)
455
+ request(:post, client_api_latest, '/createRoom', body: content, query: query)
456
+ end
457
+
458
+ # Knock on a room
459
+ #
460
+ # @param id_or_alias [MXID,String] The room ID or Alias to knock
461
+ # @param reason [String] A reason for the knock, will be attached to the membership data
462
+ # @param server_name [String[]] A list of servers to perform the join through
463
+ # @param params [Hash] Extra room knock options
464
+ # @return [Response] A response hash with at least the parameter :room_id
465
+ # @see https://spec.matrix.org/v1.1/client-server-api/#knocking-on-rooms
466
+ # The Matrix Spec, for more information about the call and response
467
+ def knock_room(id_or_alias, reason: nil, server_name: nil, **params)
468
+ query = {}
469
+ query[:server_name] = server_name if server_name
470
+ query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
471
+
472
+ content = {}
473
+ content[:reason] = reason if reason
474
+
475
+ id_or_alias = ERB::Util.url_encode id_or_alias.to_s
476
+
477
+ request(:post, client_api_latest, "/knock/#{id_or_alias}", body: content, query: query)
444
478
  end
445
479
 
446
480
  # Joins a room
@@ -451,17 +485,17 @@ module MatrixSdk::Protocols::CS
451
485
  # @see https://matrix.org/docs/spec/client_server/latest.html#post-matrix-client-r0-join-roomidoralias
452
486
  # The Matrix Spec, for more information about the call and response
453
487
  # @todo Add support for 3rd-party signed objects
454
- def join_room(id_or_alias, **params)
488
+ def join_room(id_or_alias, reason: nil, **params)
455
489
  query = {}
456
490
  query[:server_name] = params[:server_name] if params[:server_name]
457
491
  query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
458
492
 
459
- # id_or_alias = MXID.new id_or_alias.to_s unless id_or_alias.is_a? MXID
460
- # raise ArgumentError, 'Not a room ID or alias' unless id_or_alias.room?
493
+ content = {}
494
+ content[:reason] = reason if reason
461
495
 
462
496
  id_or_alias = ERB::Util.url_encode id_or_alias.to_s
463
497
 
464
- request(:post, :client_r0, "/join/#{id_or_alias}", query: query)
498
+ request(:post, client_api_latest, "/join/#{id_or_alias}", body: content, query: query)
465
499
  end
466
500
 
467
501
  # Sends a state event to a room
@@ -482,7 +516,7 @@ module MatrixSdk::Protocols::CS
482
516
  event_type = ERB::Util.url_encode event_type.to_s
483
517
  state_key = ERB::Util.url_encode params[:state_key].to_s if params.key? :state_key
484
518
 
485
- request(:put, :client_r0, "/rooms/#{room_id}/state/#{event_type}#{"/#{state_key}" unless state_key.nil?}", body: content, query: query)
519
+ request(:put, client_api_latest, "/rooms/#{room_id}/state/#{event_type}#{"/#{state_key}" unless state_key.nil?}", body: content, query: query)
486
520
  end
487
521
 
488
522
  # Sends a message event to a room
@@ -505,7 +539,7 @@ module MatrixSdk::Protocols::CS
505
539
  event_type = ERB::Util.url_encode event_type.to_s
506
540
  txn_id = ERB::Util.url_encode txn_id.to_s
507
541
 
508
- request(:put, :client_r0, "/rooms/#{room_id}/send/#{event_type}/#{txn_id}", body: content, query: query)
542
+ request(:put, client_api_latest, "/rooms/#{room_id}/send/#{event_type}/#{txn_id}", body: content, query: query)
509
543
  end
510
544
 
511
545
  # Redact an event in a room
@@ -531,7 +565,7 @@ module MatrixSdk::Protocols::CS
531
565
  event_id = ERB::Util.url_encode event_id.to_s
532
566
  txn_id = ERB::Util.url_encode txn_id.to_s
533
567
 
534
- request(:put, :client_r0, "/rooms/#{room_id}/redact/#{event_id}/#{txn_id}", body: content, query: query)
568
+ request(:put, client_api_latest, "/rooms/#{room_id}/redact/#{event_id}/#{txn_id}", body: content, query: query)
535
569
  end
536
570
 
537
571
  # Send a content message to a room
@@ -687,7 +721,7 @@ module MatrixSdk::Protocols::CS
687
721
  room_id = ERB::Util.url_encode room_id.to_s
688
722
  event_id = ERB::Util.url_encode event_id.to_s
689
723
 
690
- request(:post, :client_r0, "/rooms/#{room_id}/report/#{event_id}", body: body, query: query)
724
+ request(:post, client_api_latest, "/rooms/#{room_id}/report/#{event_id}", body: body, query: query)
691
725
  end
692
726
 
693
727
  # Retrieve additional messages in a room
@@ -714,7 +748,7 @@ module MatrixSdk::Protocols::CS
714
748
 
715
749
  room_id = ERB::Util.url_encode room_id.to_s
716
750
 
717
- request(:get, :client_r0, "/rooms/#{room_id}/messages", query: query)
751
+ request(:get, client_api_latest, "/rooms/#{room_id}/messages", query: query)
718
752
  end
719
753
 
720
754
  # Gets a specific event from a room
@@ -731,7 +765,7 @@ module MatrixSdk::Protocols::CS
731
765
  room_id = ERB::Util.url_encode room_id.to_s
732
766
  event_id = ERB::Util.url_encode event_id.to_s
733
767
 
734
- request(:get, :client_r0, "/rooms/#{room_id}/event/#{event_id}", query: query)
768
+ request(:get, client_api_latest, "/rooms/#{room_id}/event/#{event_id}", query: query)
735
769
  end
736
770
 
737
771
  # Reads the latest instance of a room state event
@@ -749,7 +783,7 @@ module MatrixSdk::Protocols::CS
749
783
  state_type = ERB::Util.url_encode state_type.to_s
750
784
  key = ERB::Util.url_encode key.to_s
751
785
 
752
- request(:get, :client_r0, "/rooms/#{room_id}/state/#{state_type}#{key.empty? ? nil : "/#{key}"}", query: query)
786
+ request(:get, client_api_latest, "/rooms/#{room_id}/state/#{state_type}#{key.empty? ? nil : "/#{key}"}", query: query)
753
787
  end
754
788
 
755
789
  # Retrieves all current state objects from a room
@@ -764,7 +798,7 @@ module MatrixSdk::Protocols::CS
764
798
 
765
799
  room_id = ERB::Util.url_encode room_id.to_s
766
800
 
767
- request(:get, :client_r0, "/rooms/#{room_id}/state", query: query)
801
+ request(:get, client_api_latest, "/rooms/#{room_id}/state", query: query)
768
802
  end
769
803
 
770
804
  # Retrieves number of events that happened just before and after the specified event
@@ -788,7 +822,7 @@ module MatrixSdk::Protocols::CS
788
822
  room_id = ERB::Util.url_encode room_id.to_s
789
823
  event_id = ERB::Util.url_encode event_id.to_s
790
824
 
791
- request(:get, :client_r0, "/rooms/#{room_id}/context/#{event_id}", query: query)
825
+ request(:get, client_api_latest, "/rooms/#{room_id}/context/#{event_id}", query: query)
792
826
  end
793
827
 
794
828
  ## Specialized getters for specced state
@@ -878,31 +912,23 @@ module MatrixSdk::Protocols::CS
878
912
  send_state_event(room_id, 'm.room.avatar', content, **params)
879
913
  end
880
914
 
881
- # Gets a list of current aliases of a room
915
+ # Gets a list of currently known aliases of a room
882
916
  #
883
917
  # @param [MXID,String] room_id The room ID to look up
884
- # @param [Hash] params Extra options to provide to the request, see #get_room_state
885
918
  # @return [Response] A response hash with the array :aliases
886
- # @raise [MatrixNotFoundError] Raised if no aliases has been set on the room by the specified HS
887
- # @see get_room_state
888
- # @see https://matrix.org/docs/spec/client_server/latest.html#m-room-avatar
919
+ # @raise [MatrixForbiddenError] Raised if the user doesn't have the right to read aliases
920
+ # @see https://spec.matrix.org/v1.1/client-server-api/#get_matrixclientv3roomsroomidaliases
889
921
  # The Matrix Spec, for more information about the event and data
890
922
  # @example Looking up aliases for a room
891
923
  # api.get_room_aliases('!QtykxKocfZaZOUrTwp:matrix.org')
892
- # # MatrixSdk::MatrixNotFoundError: HTTP 404 (M_NOT_FOUND): Event not found.
893
- # api.get_room_aliases('!QtykxKocfZaZOUrTwp:matrix.org', key: 'matrix.org')
894
924
  # # => {:aliases=>["#matrix:matrix.org"]}
895
- # api.get_room_aliases('!QtykxKocfZaZOUrTwp:matrix.org', key: 'kittenface.studio')
896
- # # => {:aliases=>["#worlddominationhq:kittenface.studio"]}
897
- # @example A way to find all aliases for a room
898
- # api.get_room_state('!mjbDjyNsRXndKLkHIe:matrix.org')
899
- # .select { |ch| ch[:type] == 'm.room.aliases' }
900
- # .map { |ch| ch[:content][:aliases] }
901
- # .flatten
902
- # .compact
903
- # # => ["#synapse:im.kabi.tk", "#synapse:matrix.org", "#synapse-community:matrix.org", "#synapse-ops:matrix.org", "#synops:matrix.org", ...
904
925
  def get_room_aliases(room_id, **params)
905
- get_room_state(room_id, 'm.room.aliases', **params)
926
+ query = {}
927
+ query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
928
+
929
+ room_id = ERB::Util.url_encode room_id.to_s
930
+
931
+ request(:get, client_api_latest, "/rooms/#{room_id}/aliases", query: query)
906
932
  end
907
933
 
908
934
  # Gets a list of pinned events in a room
@@ -1125,7 +1151,7 @@ module MatrixSdk::Protocols::CS
1125
1151
 
1126
1152
  room_id = ERB::Util.url_encode room_id.to_s
1127
1153
 
1128
- request(:post, :client_r0, "/rooms/#{room_id}/leave", query: query)
1154
+ request(:post, client_api_latest, "/rooms/#{room_id}/leave", query: query)
1129
1155
  end
1130
1156
 
1131
1157
  def forget_room(room_id, **params)
@@ -1134,7 +1160,7 @@ module MatrixSdk::Protocols::CS
1134
1160
 
1135
1161
  room_id = ERB::Util.url_encode room_id.to_s
1136
1162
 
1137
- request(:post, :client_r0, "/rooms/#{room_id}/forget", query: query)
1163
+ request(:post, client_api_latest, "/rooms/#{room_id}/forget", query: query)
1138
1164
  end
1139
1165
 
1140
1166
  # Directly joins a room by ID
@@ -1154,7 +1180,7 @@ module MatrixSdk::Protocols::CS
1154
1180
 
1155
1181
  room_id = ERB::Util.url_encode room_id.to_s
1156
1182
 
1157
- request(:post, :client_r0, "/rooms/#{room_id}/join", body: body, query: query)
1183
+ request(:post, client_api_latest, "/rooms/#{room_id}/join", body: body, query: query)
1158
1184
  end
1159
1185
 
1160
1186
  def invite_user(room_id, user_id, **params)
@@ -1167,7 +1193,7 @@ module MatrixSdk::Protocols::CS
1167
1193
 
1168
1194
  room_id = ERB::Util.url_encode room_id.to_s
1169
1195
 
1170
- request(:post, :client_r0, "/rooms/#{room_id}/invite", body: content, query: query)
1196
+ request(:post, client_api_latest, "/rooms/#{room_id}/invite", body: content, query: query)
1171
1197
  end
1172
1198
 
1173
1199
  def kick_user(room_id, user_id, reason: '', **params)
@@ -1180,7 +1206,7 @@ module MatrixSdk::Protocols::CS
1180
1206
  }
1181
1207
  room_id = ERB::Util.url_encode room_id.to_s
1182
1208
 
1183
- request(:post, :client_r0, "/rooms/#{room_id}/kick", body: content, query: query)
1209
+ request(:post, client_api_latest, "/rooms/#{room_id}/kick", body: content, query: query)
1184
1210
  end
1185
1211
 
1186
1212
  def get_membership(room_id, user_id, **params)
@@ -1190,7 +1216,7 @@ module MatrixSdk::Protocols::CS
1190
1216
  room_id = ERB::Util.url_encode room_id.to_s
1191
1217
  user_id = ERB::Util.url_encode user_id.to_s
1192
1218
 
1193
- request(:get, :client_r0, "/rooms/#{room_id}/state/m.room.member/#{user_id}", query: query)
1219
+ request(:get, client_api_latest, "/rooms/#{room_id}/state/m.room.member/#{user_id}", query: query)
1194
1220
  end
1195
1221
 
1196
1222
  def set_membership(room_id, user_id, membership, reason: '', **params)
@@ -1214,7 +1240,7 @@ module MatrixSdk::Protocols::CS
1214
1240
  }
1215
1241
  room_id = ERB::Util.url_encode room_id.to_s
1216
1242
 
1217
- request(:post, :client_r0, "/rooms/#{room_id}/ban", body: content, query: query)
1243
+ request(:post, client_api_latest, "/rooms/#{room_id}/ban", body: content, query: query)
1218
1244
  end
1219
1245
 
1220
1246
  def unban_user(room_id, user_id, **params)
@@ -1226,7 +1252,7 @@ module MatrixSdk::Protocols::CS
1226
1252
  }
1227
1253
  room_id = ERB::Util.url_encode room_id.to_s
1228
1254
 
1229
- request(:post, :client_r0, "/rooms/#{room_id}/unban", body: content, query: query)
1255
+ request(:post, client_api_latest, "/rooms/#{room_id}/unban", body: content, query: query)
1230
1256
  end
1231
1257
 
1232
1258
  # Gets the room directory visibility status for a room
@@ -1241,7 +1267,7 @@ module MatrixSdk::Protocols::CS
1241
1267
 
1242
1268
  room_id = ERB::Util.url_encode room_id.to_s
1243
1269
 
1244
- request(:get, :client_r0, "/directory/list/room/#{room_id}", query: query)
1270
+ request(:get, client_api_latest, "/directory/list/room/#{room_id}", query: query)
1245
1271
  end
1246
1272
 
1247
1273
  # Sets the room directory visibility status for a room
@@ -1261,7 +1287,7 @@ module MatrixSdk::Protocols::CS
1261
1287
 
1262
1288
  room_id = ERB::Util.url_encode room_id.to_s
1263
1289
 
1264
- request(:put, :client_r0, "/directory/list/room/#{room_id}", body: body, query: query)
1290
+ request(:put, client_api_latest, "/directory/list/room/#{room_id}", body: body, query: query)
1265
1291
  end
1266
1292
 
1267
1293
  def get_user_tags(user_id, room_id, **params)
@@ -1271,7 +1297,7 @@ module MatrixSdk::Protocols::CS
1271
1297
  room_id = ERB::Util.url_encode room_id.to_s
1272
1298
  user_id = ERB::Util.url_encode user_id.to_s
1273
1299
 
1274
- request(:get, :client_r0, "/user/#{user_id}/rooms/#{room_id}/tags", query: query)
1300
+ request(:get, client_api_latest, "/user/#{user_id}/rooms/#{room_id}/tags", query: query)
1275
1301
  end
1276
1302
 
1277
1303
  def remove_user_tag(user_id, room_id, tag, **params)
@@ -1282,7 +1308,7 @@ module MatrixSdk::Protocols::CS
1282
1308
  user_id = ERB::Util.url_encode user_id.to_s
1283
1309
  tag = ERB::Util.url_encode tag.to_s
1284
1310
 
1285
- request(:delete, :client_r0, "/user/#{user_id}/rooms/#{room_id}/tags/#{tag}", query: query)
1311
+ request(:delete, client_api_latest, "/user/#{user_id}/rooms/#{room_id}/tags/#{tag}", query: query)
1286
1312
  end
1287
1313
 
1288
1314
  def add_user_tag(user_id, room_id, tag, **params)
@@ -1300,7 +1326,7 @@ module MatrixSdk::Protocols::CS
1300
1326
  user_id = ERB::Util.url_encode user_id.to_s
1301
1327
  tag = ERB::Util.url_encode tag.to_s
1302
1328
 
1303
- request(:put, :client_r0, "/user/#{user_id}/rooms/#{room_id}/tags/#{tag}", body: content, query: query)
1329
+ request(:put, client_api_latest, "/user/#{user_id}/rooms/#{room_id}/tags/#{tag}", body: content, query: query)
1304
1330
  end
1305
1331
 
1306
1332
  def get_account_data(user_id, type_key, **params)
@@ -1310,7 +1336,7 @@ module MatrixSdk::Protocols::CS
1310
1336
  user_id = ERB::Util.url_encode user_id.to_s
1311
1337
  type_key = ERB::Util.url_encode type_key.to_s
1312
1338
 
1313
- request(:get, :client_r0, "/user/#{user_id}/account_data/#{type_key}", query: query)
1339
+ request(:get, client_api_latest, "/user/#{user_id}/account_data/#{type_key}", query: query)
1314
1340
  end
1315
1341
 
1316
1342
  def set_account_data(user_id, type_key, account_data, **params)
@@ -1320,7 +1346,7 @@ module MatrixSdk::Protocols::CS
1320
1346
  user_id = ERB::Util.url_encode user_id.to_s
1321
1347
  type_key = ERB::Util.url_encode type_key.to_s
1322
1348
 
1323
- request(:put, :client_r0, "/user/#{user_id}/account_data/#{type_key}", body: account_data, query: query)
1349
+ request(:put, client_api_latest, "/user/#{user_id}/account_data/#{type_key}", body: account_data, query: query)
1324
1350
  end
1325
1351
 
1326
1352
  def get_room_account_data(user_id, room_id, type_key, **params)
@@ -1331,7 +1357,7 @@ module MatrixSdk::Protocols::CS
1331
1357
  room_id = ERB::Util.url_encode room_id.to_s
1332
1358
  type_key = ERB::Util.url_encode type_key.to_s
1333
1359
 
1334
- request(:get, :client_r0, "/user/#{user_id}/rooms/#{room_id}/account_data/#{type_key}", query: query)
1360
+ request(:get, client_api_latest, "/user/#{user_id}/rooms/#{room_id}/account_data/#{type_key}", query: query)
1335
1361
  end
1336
1362
 
1337
1363
  def set_room_account_data(user_id, room_id, type_key, account_data, **params)
@@ -1342,7 +1368,7 @@ module MatrixSdk::Protocols::CS
1342
1368
  room_id = ERB::Util.url_encode room_id.to_s
1343
1369
  type_key = ERB::Util.url_encode type_key.to_s
1344
1370
 
1345
- request(:put, :client_r0, "/user/#{user_id}/rooms/#{room_id}/account_data/#{type_key}", body: account_data, query: query)
1371
+ request(:put, client_api_latest, "/user/#{user_id}/rooms/#{room_id}/account_data/#{type_key}", body: account_data, query: query)
1346
1372
  end
1347
1373
 
1348
1374
  # Retrieve user information
@@ -1354,7 +1380,7 @@ module MatrixSdk::Protocols::CS
1354
1380
  def whois(user_id)
1355
1381
  user_id = ERB::Util.url_encode user_id.to_s
1356
1382
 
1357
- request(:get, :client_r0, "/admin/whois/#{user_id}")
1383
+ request(:get, client_api_latest, "/admin/whois/#{user_id}")
1358
1384
  end
1359
1385
 
1360
1386
  def get_filter(user_id, filter_id, **params)
@@ -1364,7 +1390,7 @@ module MatrixSdk::Protocols::CS
1364
1390
  user_id = ERB::Util.url_encode user_id.to_s
1365
1391
  filter_id = ERB::Util.url_encode filter_id.to_s
1366
1392
 
1367
- request(:get, :client_r0, "/user/#{user_id}/filter/#{filter_id}", query: query)
1393
+ request(:get, client_api_latest, "/user/#{user_id}/filter/#{filter_id}", query: query)
1368
1394
  end
1369
1395
 
1370
1396
  # Creates a filter for future use
@@ -1377,7 +1403,7 @@ module MatrixSdk::Protocols::CS
1377
1403
 
1378
1404
  user_id = ERB::Util.url_encode user_id.to_s
1379
1405
 
1380
- request(:post, :client_r0, "/user/#{user_id}/filter", body: filter_params, query: query)
1406
+ request(:post, client_api_latest, "/user/#{user_id}/filter", body: filter_params, query: query)
1381
1407
  end
1382
1408
 
1383
1409
  def media_upload(content, content_type, **params)
@@ -1393,7 +1419,7 @@ module MatrixSdk::Protocols::CS
1393
1419
 
1394
1420
  user_id = ERB::Util.url_encode user_id.to_s
1395
1421
 
1396
- request(:get, :client_r0, "/profile/#{user_id}/displayname", query: query)
1422
+ request(:get, client_api_latest, "/profile/#{user_id}/displayname", query: query)
1397
1423
  end
1398
1424
 
1399
1425
  def set_display_name(user_id, display_name, **params)
@@ -1406,7 +1432,7 @@ module MatrixSdk::Protocols::CS
1406
1432
 
1407
1433
  user_id = ERB::Util.url_encode user_id.to_s
1408
1434
 
1409
- request(:put, :client_r0, "/profile/#{user_id}/displayname", body: content, query: query)
1435
+ request(:put, client_api_latest, "/profile/#{user_id}/displayname", body: content, query: query)
1410
1436
  end
1411
1437
 
1412
1438
  def get_avatar_url(user_id, **params)
@@ -1415,7 +1441,7 @@ module MatrixSdk::Protocols::CS
1415
1441
 
1416
1442
  user_id = ERB::Util.url_encode user_id.to_s
1417
1443
 
1418
- request(:get, :client_r0, "/profile/#{user_id}/avatar_url", query: query)
1444
+ request(:get, client_api_latest, "/profile/#{user_id}/avatar_url", query: query)
1419
1445
  end
1420
1446
 
1421
1447
  # Sets the avatar URL for a user
@@ -1435,7 +1461,7 @@ module MatrixSdk::Protocols::CS
1435
1461
  # api.set_avatar_url(api.whoami?[:user_id], mxc)
1436
1462
  #
1437
1463
  # @param [String,MXID] user_id The ID of the user to set the avatar for
1438
- # @param [String,URI::MATRIX] url The new avatar URL, should be a mxc:// URL
1464
+ # @param [String,URI::MXC] url The new avatar URL, should be a mxc:// URL
1439
1465
  # @return [Response] An empty response hash if the change was successful
1440
1466
  # @see https://matrix.org/docs/spec/client_server/latest#put-matrix-client-r0-profile-userid-avatar-url
1441
1467
  # The Matrix Spec, for more information about the event and data
@@ -1449,7 +1475,7 @@ module MatrixSdk::Protocols::CS
1449
1475
 
1450
1476
  user_id = ERB::Util.url_encode user_id.to_s
1451
1477
 
1452
- request(:put, :client_r0, "/profile/#{user_id}/avatar_url", body: content, query: query)
1478
+ request(:put, client_api_latest, "/profile/#{user_id}/avatar_url", body: content, query: query)
1453
1479
  end
1454
1480
 
1455
1481
  # Gets the combined profile object of a user.
@@ -1466,7 +1492,7 @@ module MatrixSdk::Protocols::CS
1466
1492
 
1467
1493
  user_id = ERB::Util.url_encode user_id.to_s
1468
1494
 
1469
- request(:get, :client_r0, "/profile/#{user_id}", query: query)
1495
+ request(:get, client_api_latest, "/profile/#{user_id}", query: query)
1470
1496
  end
1471
1497
 
1472
1498
  # Gets TURN server connection information and credentials
@@ -1475,7 +1501,7 @@ module MatrixSdk::Protocols::CS
1475
1501
  # @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-voip-turnserver
1476
1502
  # The Matrix Spec, for more information about the event and data
1477
1503
  def get_turn_server
1478
- request(:get, :client_r0, '/voip/turnServer')
1504
+ request(:get, client_api_latest, '/voip/turnServer')
1479
1505
  end
1480
1506
 
1481
1507
  # Sets the typing status for a user
@@ -1496,7 +1522,7 @@ module MatrixSdk::Protocols::CS
1496
1522
  timeout: timeout ? timeout * 1000 : nil
1497
1523
  }.compact
1498
1524
 
1499
- request(:put, :client_r0, "/rooms/#{room_id}/typing/#{user_id}", body: body)
1525
+ request(:put, client_api_latest, "/rooms/#{room_id}/typing/#{user_id}", body: body)
1500
1526
  end
1501
1527
 
1502
1528
  # Gets the presence status of a user
@@ -1508,7 +1534,7 @@ module MatrixSdk::Protocols::CS
1508
1534
  def get_presence_status(user_id)
1509
1535
  user_id = ERB::Util.url_encode user_id.to_s
1510
1536
 
1511
- request(:get, :client_r0, "/presence/#{user_id}/status")
1537
+ request(:get, client_api_latest, "/presence/#{user_id}/status")
1512
1538
  end
1513
1539
 
1514
1540
  # Sets the presence status of a user
@@ -1528,7 +1554,7 @@ module MatrixSdk::Protocols::CS
1528
1554
  status_msg: message
1529
1555
  }.compact
1530
1556
 
1531
- request(:put, :client_r0, "/presence/#{user_id}/status", body: body)
1557
+ request(:put, client_api_latest, "/presence/#{user_id}/status", body: body)
1532
1558
  end
1533
1559
 
1534
1560
  # Converts a Matrix content URL (mxc://) to a media download URL
@@ -1545,7 +1571,7 @@ module MatrixSdk::Protocols::CS
1545
1571
  # # => #<URI::HTTPS https://matrix.org/_matrix/media/r0/download/example.com/media_hash>
1546
1572
  def get_download_url(mxcurl, source: nil, **_params)
1547
1573
  mxcurl = URI.parse(mxcurl.to_s) unless mxcurl.is_a? URI
1548
- raise 'Not a mxc:// URL' unless mxcurl.is_a? URI::MATRIX
1574
+ raise 'Not a mxc:// URL' unless mxcurl.is_a? URI::MXC
1549
1575
 
1550
1576
  if source
1551
1577
  source = "https://#{source}" unless source.include? '://'
@@ -1605,7 +1631,7 @@ module MatrixSdk::Protocols::CS
1605
1631
  messages: messages
1606
1632
  }.compact
1607
1633
 
1608
- request(:put, :client_r0, "/sendToDevice/#{event_type}/#{txn_id}", body: body)
1634
+ request(:put, client_api_latest, "/sendToDevice/#{event_type}/#{txn_id}", body: body)
1609
1635
  end
1610
1636
 
1611
1637
  # Gets the room ID for an alias
@@ -1618,7 +1644,7 @@ module MatrixSdk::Protocols::CS
1618
1644
 
1619
1645
  room_alias = ERB::Util.url_encode room_alias.to_s
1620
1646
 
1621
- request(:get, :client_r0, "/directory/room/#{room_alias}", query: query)
1647
+ request(:get, client_api_latest, "/directory/room/#{room_alias}", query: query)
1622
1648
  end
1623
1649
 
1624
1650
  # Sets the room ID for an alias
@@ -1635,7 +1661,7 @@ module MatrixSdk::Protocols::CS
1635
1661
  }
1636
1662
  room_alias = ERB::Util.url_encode room_alias.to_s
1637
1663
 
1638
- request(:put, :client_r0, "/directory/room/#{room_alias}", body: content, query: query)
1664
+ request(:put, client_api_latest, "/directory/room/#{room_alias}", body: content, query: query)
1639
1665
  end
1640
1666
 
1641
1667
  # Remove an alias from its room
@@ -1647,7 +1673,7 @@ module MatrixSdk::Protocols::CS
1647
1673
 
1648
1674
  room_alias = ERB::Util.url_encode room_alias.to_s
1649
1675
 
1650
- request(:delete, :client_r0, "/directory/room/#{room_alias}", query: query)
1676
+ request(:delete, client_api_latest, "/directory/room/#{room_alias}", query: query)
1651
1677
  end
1652
1678
 
1653
1679
  # Gets a list of all the members in a room
@@ -1661,7 +1687,7 @@ module MatrixSdk::Protocols::CS
1661
1687
 
1662
1688
  room_id = ERB::Util.url_encode room_id.to_s
1663
1689
 
1664
- request(:get, :client_r0, "/rooms/#{room_id}/members", query: query.merge(params))
1690
+ request(:get, client_api_latest, "/rooms/#{room_id}/members", query: query.merge(params))
1665
1691
  end
1666
1692
 
1667
1693
  # Gets a list of the joined members in a room
@@ -1676,7 +1702,7 @@ module MatrixSdk::Protocols::CS
1676
1702
 
1677
1703
  room_id = ERB::Util.url_encode room_id.to_s
1678
1704
 
1679
- request(:get, :client_r0, "/rooms/#{room_id}/joined_members", query: query)
1705
+ request(:get, client_api_latest, "/rooms/#{room_id}/joined_members", query: query)
1680
1706
  end
1681
1707
 
1682
1708
  # Gets a list of the current users registered devices
@@ -1684,7 +1710,7 @@ module MatrixSdk::Protocols::CS
1684
1710
  # @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-devices
1685
1711
  # The Matrix Spec, for more information about the data
1686
1712
  def get_devices
1687
- request(:get, :client_r0, '/devices')
1713
+ request(:get, client_api_latest, '/devices')
1688
1714
  end
1689
1715
 
1690
1716
  # Gets the information about a certain client device
@@ -1695,7 +1721,7 @@ module MatrixSdk::Protocols::CS
1695
1721
  def get_device(device_id)
1696
1722
  device_id = ERB::Util.url_encode device_id.to_s
1697
1723
 
1698
- request(:get, :client_r0, "/devices/#{device_id}")
1724
+ request(:get, client_api_latest, "/devices/#{device_id}")
1699
1725
  end
1700
1726
 
1701
1727
  # Sets the metadata for a device
@@ -1706,7 +1732,7 @@ module MatrixSdk::Protocols::CS
1706
1732
  def set_device(device_id, display_name:)
1707
1733
  device_id = ERB::Util.url_encode device_id.to_s
1708
1734
 
1709
- request(:put, :client_r0, "/devices/#{device_id}", body: { display_name: display_name })
1735
+ request(:put, client_api_latest, "/devices/#{device_id}", body: { display_name: display_name })
1710
1736
  end
1711
1737
 
1712
1738
  # Removes a device from the current user
@@ -1719,7 +1745,7 @@ module MatrixSdk::Protocols::CS
1719
1745
  def delete_device(device_id, auth:)
1720
1746
  device_id = ERB::Util.url_encode device_id.to_s
1721
1747
 
1722
- request(:delete, :client_r0, "/devices/#{device_id}", body: { auth: auth })
1748
+ request(:delete, client_api_latest, "/devices/#{device_id}", body: { auth: auth })
1723
1749
  end
1724
1750
 
1725
1751
  # Run a query for device keys
@@ -1744,7 +1770,7 @@ module MatrixSdk::Protocols::CS
1744
1770
  body[:timeout] = params[:timeout_ms] if params.key? :timeout_ms
1745
1771
  body[:token] = token if token
1746
1772
 
1747
- request(:post, :client_r0, '/keys/query', body: body)
1773
+ request(:post, client_api_latest, '/keys/query', body: body)
1748
1774
  end
1749
1775
 
1750
1776
  # Claim one-time keys for pre-key messaging
@@ -1759,7 +1785,7 @@ module MatrixSdk::Protocols::CS
1759
1785
  one_time_keys: one_time_keys,
1760
1786
  timeout: timeout * 1000
1761
1787
  }
1762
- request(:post, :client_r0, '/keys/claim', body: body)
1788
+ request(:post, client_api_latest, '/keys/claim', body: body)
1763
1789
  end
1764
1790
 
1765
1791
  # Retrieve device key changes between two sync requests
@@ -1775,7 +1801,7 @@ module MatrixSdk::Protocols::CS
1775
1801
  to: to
1776
1802
  }
1777
1803
 
1778
- request(:get, :client_r0, '/keys/changes', query: query)
1804
+ request(:get, client_api_latest, '/keys/changes', query: query)
1779
1805
  end
1780
1806
 
1781
1807
  # Gets the list of registered pushers for the current user
@@ -1784,7 +1810,7 @@ module MatrixSdk::Protocols::CS
1784
1810
  # @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushers
1785
1811
  # The Matrix Spec, for more information about the parameters and data
1786
1812
  def get_pushers
1787
- request(:get, :client_r0, '/pushers')
1813
+ request(:get, client_api_latest, '/pushers')
1788
1814
  end
1789
1815
 
1790
1816
  # rubocop:disable Metrics/ParameterLists
@@ -1817,7 +1843,7 @@ module MatrixSdk::Protocols::CS
1817
1843
  append: params[:append]
1818
1844
  }.compact
1819
1845
 
1820
- request(:post, :client_r0, '/pushers/set', body: body)
1846
+ request(:post, client_api_latest, '/pushers/set', body: body)
1821
1847
  end
1822
1848
  # rubocop:enable Metrics/ParameterLists
1823
1849
 
@@ -1838,7 +1864,7 @@ module MatrixSdk::Protocols::CS
1838
1864
  only: only
1839
1865
  }.compact
1840
1866
 
1841
- request(:get, :client_r0, '/notifications', query: query)
1867
+ request(:get, client_api_latest, '/notifications', query: query)
1842
1868
  end
1843
1869
 
1844
1870
  # Retrieves the full list of registered push rules for the current user
@@ -1847,7 +1873,7 @@ module MatrixSdk::Protocols::CS
1847
1873
  # @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushrules
1848
1874
  # The Matrix Spec, for more information about the parameters and data
1849
1875
  def get_pushrules
1850
- request(:get, :client_r0, '/pushrules/')
1876
+ request(:get, client_api_latest, '/pushrules/')
1851
1877
  end
1852
1878
 
1853
1879
  # Retrieves a single registered push rule for the current user
@@ -1863,7 +1889,7 @@ module MatrixSdk::Protocols::CS
1863
1889
  kind = ERB::Util.url_encode kind.to_s
1864
1890
  id = ERB::Util.url_encode id.to_s
1865
1891
 
1866
- request(:get, :client_r0, "/pushrules/#{scope}/#{kind}/#{id}")
1892
+ request(:get, client_api_latest, "/pushrules/#{scope}/#{kind}/#{id}")
1867
1893
  end
1868
1894
 
1869
1895
  # Checks if a push rule for the current user is enabled
@@ -1879,7 +1905,7 @@ module MatrixSdk::Protocols::CS
1879
1905
  kind = ERB::Util.url_encode kind.to_s
1880
1906
  id = ERB::Util.url_encode id.to_s
1881
1907
 
1882
- request(:get, :client_r0, "/pushrules/#{scope}/#{kind}/#{id}/enabled")
1908
+ request(:get, client_api_latest, "/pushrules/#{scope}/#{kind}/#{id}/enabled")
1883
1909
  end
1884
1910
 
1885
1911
  # Enabled/Disables a specific push rule for the current user
@@ -1900,7 +1926,7 @@ module MatrixSdk::Protocols::CS
1900
1926
  enabled: enabled
1901
1927
  }
1902
1928
 
1903
- request(:put, :client_r0, "/pushrules/#{scope}/#{kind}/#{id}/enabled", body: body)
1929
+ request(:put, client_api_latest, "/pushrules/#{scope}/#{kind}/#{id}/enabled", body: body)
1904
1930
  end
1905
1931
 
1906
1932
  # Gets the current list of actions for a specific push rule for the current user
@@ -1916,7 +1942,7 @@ module MatrixSdk::Protocols::CS
1916
1942
  kind = ERB::Util.url_encode kind.to_s
1917
1943
  id = ERB::Util.url_encode id.to_s
1918
1944
 
1919
- request(:get, :client_r0, "/pushrules/#{scope}/#{kind}/#{id}/actions")
1945
+ request(:get, client_api_latest, "/pushrules/#{scope}/#{kind}/#{id}/actions")
1920
1946
  end
1921
1947
 
1922
1948
  # Replaces the list of actions for a push rule for the current user
@@ -1939,7 +1965,7 @@ module MatrixSdk::Protocols::CS
1939
1965
  actions: actions
1940
1966
  }
1941
1967
 
1942
- request(:put, :client_r0, "/pushrules/#{scope}/#{kind}/#{id}/actions", body: body)
1968
+ request(:put, client_api_latest, "/pushrules/#{scope}/#{kind}/#{id}/actions", body: body)
1943
1969
  end
1944
1970
 
1945
1971
  # Gets the MXID of the currently logged-in user
@@ -1948,7 +1974,7 @@ module MatrixSdk::Protocols::CS
1948
1974
  query = {}
1949
1975
  query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
1950
1976
 
1951
- request(:get, :client_r0, '/account/whoami', query: query)
1977
+ request(:get, client_api_latest, '/account/whoami', query: query)
1952
1978
  end
1953
1979
  end
1954
1980
  # rubocop:enable Metrics/ModuleLength