Module: MatrixSdk::Protocols::CS
- Defined in:
- lib/matrix_sdk/protocols/cs.rb
Overview
rubocop:disable Metrics/ModuleLength
Instance Method Summary collapse
- #add_user_tag(user_id, room_id, tag, **params) ⇒ Object
-
#allowed_login_methods ⇒ Response
Gets the list of available methods for logging in.
- #ban_user(room_id, user_id, reason: '', **params) ⇒ Object
-
#bind_3pid(secret:, id_server:, id_server_token:, session:) ⇒ Response
Finishes binding a 3PID to the current user.
-
#change_password(new_password, auth:, **params) ⇒ Response
Changes the users password.
-
#claim_one_time_keys(one_time_keys, timeout: 10) ⇒ Response
Claim one-time keys for pre-key messaging.
-
#client_api_unstable_features ⇒ Hash
Gets the list of available unstable client API features.
-
#client_api_versions ⇒ Array
Gets the available client API versions.
-
#complete_3pid_add(secret:, session:, auth_data: nil) ⇒ Response
Finishes a 3PID addition to the current user.
-
#create_filter(user_id, filter_params, **params) ⇒ Object
Creates a filter for future use.
-
#create_room(visibility: :public, **params) ⇒ Response
Creates a new room.
-
#deactivate_account(auth_data, id_server: nil) ⇒ Response
Deactivates the current account, logging out all connected devices and preventing future logins.
-
#delete_3pid(medium, address, id_server:) ⇒ Response
Deletes a 3PID from the current user, this method might not unbind it from the identity server.
-
#delete_device(device_id, auth:) ⇒ Object
Removes a device from the current user.
- #forget_room(room_id, **params) ⇒ Object
- #get_3pids(**params) ⇒ Object
- #get_account_data(user_id, type_key, **params) ⇒ Object
- #get_avatar_url(user_id, **params) ⇒ Object
-
#get_device(device_id) ⇒ Response
Gets the information about a certain client device.
-
#get_devices ⇒ Response
Gets a list of the current users registered devices.
- #get_display_name(user_id, **params) ⇒ Object
-
#get_download_url(mxcurl, source: nil, **_params) ⇒ URI
Converts a Matrix content URL (mxc://) to a media download URL.
- #get_filter(user_id, filter_id, **params) ⇒ Object
-
#get_joined_rooms(**params) ⇒ Response
Gets the list of rooms joined by the current user.
-
#get_key_changes(from:, to:) ⇒ Response
Retrieve device key changes between two sync requests.
-
#get_media_config ⇒ Response
Gets the media configuration of the current server.
- #get_membership(room_id, user_id, **params) ⇒ Object
-
#get_notifications(from: nil, limit: nil, only: nil) ⇒ Response
Enumerates the list of notifies that the current user has/should have received.
-
#get_presence_status(user_id) ⇒ Response
Gets the presence status of a user.
-
#get_profile(user_id, **params) ⇒ Response
Gets the combined profile object of a user.
-
#get_public_rooms(server: nil, **params) ⇒ Response
Gets the list of public rooms on a Matrix server.
-
#get_pushers ⇒ Response
Gets the list of registered pushers for the current user.
-
#get_pushrule(kind:, id:, scope: 'global') ⇒ Response
Retrieves a single registered push rule for the current user.
-
#get_pushrule_actions(kind:, id:, scope: 'global') ⇒ Response
Gets the current list of actions for a specific push rule for the current user.
-
#get_pushrule_enabled(kind:, id:, scope: 'global') ⇒ Response
Checks if a push rule for the current user is enabled.
-
#get_pushrules ⇒ Response
Retrieves the full list of registered push rules for the current user.
- #get_room_account_data(user_id, room_id, type_key, **params) ⇒ Object
-
#get_room_aliases(room_id, **params) ⇒ Response
Gets a list of current aliases of a room.
-
#get_room_avatar(room_id, **params) ⇒ Response
Gets the current avatar URL of a room.
-
#get_room_creation_info(room_id, **params) ⇒ Response
Gets the creation configuration object for a room.
-
#get_room_directory_visibility(room_id, **params) ⇒ Response
Gets the room directory visibility status for a room.
-
#get_room_encryption_settings(room_id, **params) ⇒ Response
Gets the encryption configuration for a room.
-
#get_room_event(room_id, event_id, **params) ⇒ Response
Gets a specific event from a room.
-
#get_room_event_context(room_id, event_id, **params) ⇒ Response
Retrieves number of events that happened just before and after the specified event.
-
#get_room_guest_access(room_id, **params) ⇒ Response
Gets the guest access settings for a room.
-
#get_room_history_visibility(room_id, **params) ⇒ Response
Gets the history availabiilty for a room.
-
#get_room_id(room_alias, **params) ⇒ Response
Gets the room ID for an alias.
-
#get_room_join_rules(room_id, **params) ⇒ Response
Gets the join rules for a room.
-
#get_room_joined_members(room_id, **params) ⇒ Response
Gets a list of the joined members in a room.
-
#get_room_members(room_id, **params) ⇒ Response
Gets a list of all the members in a room.
-
#get_room_messages(room_id, token, direction, limit: 10, **params) ⇒ Response
Retrieve additional messages in a room.
-
#get_room_name(room_id, **params) ⇒ Response
Gets the current display name of a room.
-
#get_room_pinned_events(room_id, **params) ⇒ Response
Gets a list of pinned events in a room.
-
#get_room_power_levels(room_id, **params) ⇒ Response
(also: #get_power_levels)
Gets the configured power levels for a room.
-
#get_room_server_acl(room_id, **params) ⇒ Response
Gets the server ACLs for a room.
-
#get_room_state(room_id, state_type, key: nil, **params) ⇒ Response
Reads the latest instance of a room state event.
-
#get_room_state_all(room_id, **params) ⇒ Response
Retrieves all current state objects from a room.
-
#get_room_topic(room_id, **params) ⇒ Response
Gets the current topic of a room.
-
#get_turn_server ⇒ Response
Gets TURN server connection information and credentials.
-
#get_url_preview(url, timestamp: nil) ⇒ Response
Gets a preview of the given URL.
- #get_user_tags(user_id, room_id, **params) ⇒ Object
- #invite_user(room_id, user_id, **params) ⇒ Object
-
#join_room(id_or_alias, **params) ⇒ Response
Joins a room.
-
#join_room_id(room_id, third_party_signed: nil, **params) ⇒ Response
Directly joins a room by ID.
-
#keys_query(device_keys:, timeout: nil, token: nil, **params) ⇒ Object
Run a query for device keys.
- #kick_user(room_id, user_id, reason: '', **params) ⇒ Object
- #leave_room(room_id, **params) ⇒ Object
-
#login(login_type: 'm.login.password', **params) ⇒ Response
Logs in using the client API /login endpoint, and optionally stores the resulting access for API usage.
-
#logout(**params) ⇒ Response
Logs out the currently logged in device for the current user.
-
#logout_all(**params) ⇒ Response
Logs out the currently logged in user.
- #media_upload(content, content_type, **params) ⇒ Object
-
#redact_event(room_id, event_id, **params) ⇒ Response
Redact an event in a room.
-
#register(kind: 'user', **params) ⇒ Response
Registers a user using the client API /register endpoint.
-
#register_email_request(secret, email, attempt: 1, next_link: nil) ⇒ Response
Requests to register an email address to the current account.
-
#register_msisdn_request(secret, country, number, attempt: 1, next_link: nil) ⇒ Response
Requests to register a phone number to the current account.
-
#remove_room_alias(room_alias, **params) ⇒ Response
Remove an alias from its room.
- #remove_user_tag(user_id, room_id, tag, **params) ⇒ Object
-
#report_event(room_id, event_id, score:, reason:, **params) ⇒ Object
Report an event in a room.
-
#request_email_login_token(secret, email, attempt: 1, next_link: nil) ⇒ Response
Requests an authentication token based on an email address.
-
#request_msisdn_login_token(secret, country, number, attempt: 1, next_link: nil) ⇒ Response
Requests an authentication token based on a phone number.
-
#send_content(room_id, url, name, msg_type, **params) ⇒ Response
Send a content message to a room.
-
#send_emote(room_id, emote, **params) ⇒ Response
Send a plaintext emote to a room.
-
#send_location(room_id, geo_uri, name, **params) ⇒ Response
Send a geographic location to a room.
-
#send_message(room_id, message, **params) ⇒ Response
Send a plaintext message to a room.
-
#send_message_event(room_id, event_type, content, **params) ⇒ Response
Sends a message event to a room.
-
#send_notice(room_id, notice, **params) ⇒ Response
Send a plaintext notice to a room.
-
#send_state_event(room_id, event_type, content, **params) ⇒ Response
Sends a state event to a room.
-
#send_to_device(event_type, messages:, **params) ⇒ Object
Sends events directly to the specified devices.
- #set_account_data(user_id, type_key, account_data, **params) ⇒ Object
-
#set_avatar_url(user_id, url, **params) ⇒ Response
Sets the avatar URL for a user.
-
#set_device(device_id, display_name:) ⇒ Object
Sets the metadata for a device.
- #set_display_name(user_id, display_name, **params) ⇒ Object
- #set_membership(room_id, user_id, membership, reason: '', **params) ⇒ Object
-
#set_presence_status(user_id, status, message: nil) ⇒ Response
Sets the presence status of a user.
-
#set_pusher(key, kind:, app_id:, app_name:, device_name:, lang:, data:, **params) ⇒ Response
Sets a pusher on the current user.
-
#set_pushrule_actions(actions, kind:, id:, scope: 'global') ⇒ Response
Replaces the list of actions for a push rule for the current user.
-
#set_pushrule_enabled(enabled, kind:, id:, scope: 'global') ⇒ Response
Enabled/Disables a specific push rule for the current user.
- #set_room_account_data(user_id, room_id, type_key, account_data, **params) ⇒ Object
-
#set_room_alias(room_id, room_alias, **params) ⇒ Response
Sets the room ID for an alias.
-
#set_room_avatar(room_id, url, **params) ⇒ Response
Sets the avatar URL for a room.
-
#set_room_directory_visibility(room_id, visibility, **params) ⇒ Response
Sets the room directory visibility status for a room.
-
#set_room_encryption_settings(room_id, algorithm: 'm.megolm.v1.aes-sha2', rotation_period_ms: 1 * 7 * 24 * 60 * 60 * 1000, rotation_period_msgs: 100, **params) ⇒ Response
Sets the encryption configuration for a room.
-
#set_room_guest_access(room_id, guest_access, **params) ⇒ Response
Sets the guest access settings for a room.
-
#set_room_history_visibility(room_id, visibility, **params) ⇒ Response
Sets the history availability for a room.
-
#set_room_join_rules(room_id, join_rule, **params) ⇒ Response
Sets the join rules for a room.
-
#set_room_name(room_id, name, **params) ⇒ Response
Sets the display name of a room.
-
#set_room_pinned_events(room_id, events, **params) ⇒ Response
Sets the list of pinned events in a room.
-
#set_room_power_levels(room_id, content, **params) ⇒ Response
(also: #set_power_levels)
Sets the configuration for power levels in a room.
-
#set_room_server_acl(room_id, allow:, deny:, allow_ip_literals: false, **params) ⇒ Response
Sets the server ACL configuration for a room.
-
#set_room_topic(room_id, topic, **params) ⇒ Response
Sets the topic of a room.
-
#set_typing(room_id, user_id, typing: true, timeout: nil) ⇒ Response
Sets the typing status for a user.
-
#sync(timeout: 30.0, **params) ⇒ Response
Runs the client API /sync method.
- #unban_user(room_id, user_id, **params) ⇒ Object
-
#unbind_3pid(medium, address, id_server:) ⇒ Response
Unbinds a 3PID from the current user.
-
#username_available?(username) ⇒ Response
Checks if a given username is available and valid for registering.
-
#whoami?(**params) ⇒ Response
Gets the MXID of the currently logged-in user.
-
#whois(user_id) ⇒ Response
Retrieve user information.
Instance Method Details
#add_user_tag(user_id, room_id, tag, **params) ⇒ Object
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1288 def add_user_tag(user_id, room_id, tag, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) if params[:body] content = params[:body] else content = {} content[:order] = params[:order] if params.key? :order end room_id = ERB::Util.url_encode room_id.to_s user_id = ERB::Util.url_encode user_id.to_s tag = ERB::Util.url_encode tag.to_s request(:put, :client_r0, "/user/#{user_id}/rooms/#{room_id}/tags/#{tag}", body: content, query: query) end |
#allowed_login_methods ⇒ Response
Gets the list of available methods for logging in
44 45 46 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 44 def allowed_login_methods request(:get, :client_r0, '/login') end |
#ban_user(room_id, user_id, reason: '', **params) ⇒ Object
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1207 def ban_user(room_id, user_id, reason: '', **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) content = { user_id: user_id, reason: reason } room_id = ERB::Util.url_encode room_id.to_s request(:post, :client_r0, "/rooms/#{room_id}/ban", body: content, query: query) end |
#bind_3pid(secret:, id_server:, id_server_token:, session:) ⇒ Response
Finishes binding a 3PID to the current user
333 334 335 336 337 338 339 340 341 342 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 333 def bind_3pid(secret:, id_server:, id_server_token:, session:) body = { client_secret: secret, id_server: id_server, id_server_token: id_server_token, sid: session } request(:post, :client_r0, '/account/3pid/bind', body: body) end |
#change_password(new_password, auth:, **params) ⇒ Response
Changes the users password
227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 227 def change_password(new_password, auth:, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) # raise Error unless auth.is_a?(Hash) && auth.key? :type body = { new_password: new_password, auth: auth } request(:post, :client_r0, '/account/password', body: body, query: query) end |
#claim_one_time_keys(one_time_keys, timeout: 10) ⇒ Response
Claim one-time keys for pre-key messaging
1757 1758 1759 1760 1761 1762 1763 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1757 def claim_one_time_keys(one_time_keys, timeout: 10) body = { one_time_keys: one_time_keys, timeout: timeout * 1000 } request(:post, :client_r0, '/keys/claim', body: body) end |
#client_api_unstable_features ⇒ Hash
Gets the list of available unstable client API features
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 31 def client_api_unstable_features (@client_api_versions ||= request(:get, :client, '/versions')).unstable_features.tap do |vers| vers.instance_eval <<-'CODE', __FILE__, __LINE__ + 1 def has?(feature) feature = feature.to_s.to_sym unless feature.is_a? Symbol fetch(feature, nil) end CODE end end |
#client_api_versions ⇒ Array
Gets the available client API versions
13 14 15 16 17 18 19 20 21 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 13 def client_api_versions (@client_api_versions ||= request(:get, :client, '/versions')).versions.tap do |vers| vers.instance_eval <<-'CODE', __FILE__, __LINE__ + 1 def latest last end CODE end end |
#complete_3pid_add(secret:, session:, auth_data: nil) ⇒ Response
Finishes a 3PID addition to the current user
314 315 316 317 318 319 320 321 322 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 314 def complete_3pid_add(secret:, session:, auth_data: nil) body = { sid: session, client_secret: secret, auth: auth_data }.compact request(:post, :client_r0, '/account/3pid/add', body: body) end |
#create_filter(user_id, filter_params, **params) ⇒ Object
Creates a filter for future use
1374 1375 1376 1377 1378 1379 1380 1381 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1374 def create_filter(user_id, filter_params, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) user_id = ERB::Util.url_encode user_id.to_s request(:post, :client_r0, "/user/#{user_id}/filter", body: filter_params, query: query) end |
#create_room(visibility: :public, **params) ⇒ Response
Creates a new room
432 433 434 435 436 437 438 439 440 441 442 443 444 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 432 def create_room(visibility: :public, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) content = { visibility: visibility } content[:room_alias_name] = params.delete(:room_alias) if params[:room_alias] content[:invite] = [params.delete(:invite)].flatten if params[:invite] content.merge! params request(:post, :client_r0, '/createRoom', body: content, query: query) end |
#deactivate_account(auth_data, id_server: nil) ⇒ Response
Deactivates the current account, logging out all connected devices and preventing future logins
290 291 292 293 294 295 296 297 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 290 def deactivate_account(auth_data, id_server: nil) body = { auth: auth_data, id_server: id_server }.compact request(:post, :client_r0, '/account/deactivate', body: body) end |
#delete_3pid(medium, address, id_server:) ⇒ Response
Deletes a 3PID from the current user, this method might not unbind it from the identity server
352 353 354 355 356 357 358 359 360 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 352 def delete_3pid(medium, address, id_server:) body = { address: address, id_server: id_server, medium: medium } request(:post, :client_r0, '/account/3pid/delete', body: body) end |
#delete_device(device_id, auth:) ⇒ Object
Removes a device from the current user
1719 1720 1721 1722 1723 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1719 def delete_device(device_id, auth:) device_id = ERB::Util.url_encode device_id.to_s request(:delete, :client_r0, "/devices/#{device_id}", body: { auth: auth }) end |
#forget_room(room_id, **params) ⇒ Object
1131 1132 1133 1134 1135 1136 1137 1138 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1131 def forget_room(room_id, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) room_id = ERB::Util.url_encode room_id.to_s request(:post, :client_r0, "/rooms/#{room_id}/forget", query: query) end |
#get_3pids(**params) ⇒ Object
299 300 301 302 303 304 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 299 def get_3pids(**params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) request(:get, :client_r0, '/account/3pid', query: query) end |
#get_account_data(user_id, type_key, **params) ⇒ Object
1306 1307 1308 1309 1310 1311 1312 1313 1314 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1306 def get_account_data(user_id, type_key, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) user_id = ERB::Util.url_encode user_id.to_s type_key = ERB::Util.url_encode type_key.to_s request(:get, :client_r0, "/user/#{user_id}/account_data/#{type_key}", query: query) end |
#get_avatar_url(user_id, **params) ⇒ Object
1412 1413 1414 1415 1416 1417 1418 1419 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1412 def get_avatar_url(user_id, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) user_id = ERB::Util.url_encode user_id.to_s request(:get, :client_r0, "/profile/#{user_id}/avatar_url", query: query) end |
#get_device(device_id) ⇒ Response
Gets the information about a certain client device
1695 1696 1697 1698 1699 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1695 def get_device(device_id) device_id = ERB::Util.url_encode device_id.to_s request(:get, :client_r0, "/devices/#{device_id}") end |
#get_devices ⇒ Response
Gets a list of the current users registered devices
1686 1687 1688 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1686 def get_devices request(:get, :client_r0, '/devices') end |
#get_display_name(user_id, **params) ⇒ Object
1390 1391 1392 1393 1394 1395 1396 1397 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1390 def get_display_name(user_id, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) user_id = ERB::Util.url_encode user_id.to_s request(:get, :client_r0, "/profile/#{user_id}/displayname", query: query) end |
#get_download_url(mxcurl, source: nil, **_params) ⇒ URI
Converts a Matrix content URL (mxc://) to a media download URL
1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1546 def get_download_url(mxcurl, source: nil, **_params) mxcurl = URI.parse(mxcurl.to_s) unless mxcurl.is_a? URI raise 'Not a mxc:// URL' unless mxcurl.is_a? URI::MATRIX if source source = "https://#{source}" unless source.include? '://' source = URI(source.to_s) unless source.is_a?(URI) end source ||= homeserver.dup source.tap do |u| full_path = mxcurl.full_path.to_s u.path = "/_matrix/media/r0/download/#{full_path}" end end |
#get_filter(user_id, filter_id, **params) ⇒ Object
1360 1361 1362 1363 1364 1365 1366 1367 1368 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1360 def get_filter(user_id, filter_id, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) user_id = ERB::Util.url_encode user_id.to_s filter_id = ERB::Util.url_encode filter_id.to_s request(:get, :client_r0, "/user/#{user_id}/filter/#{filter_id}", query: query) end |
#get_joined_rooms(**params) ⇒ Response
Gets the list of rooms joined by the current user
384 385 386 387 388 389 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 384 def get_joined_rooms(**params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) request(:get, :client_r0, '/joined_rooms', query: query) end |
#get_key_changes(from:, to:) ⇒ Response
Retrieve device key changes between two sync requests
1772 1773 1774 1775 1776 1777 1778 1779 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1772 def get_key_changes(from:, to:) query = { from: from, to: to } request(:get, :client_r0, '/keys/changes', query: query) end |
#get_media_config ⇒ Response
Gets the media configuration of the current server
1585 1586 1587 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1585 def get_media_config request(:get, :media_r0, '/config') end |
#get_membership(room_id, user_id, **params) ⇒ Object
1186 1187 1188 1189 1190 1191 1192 1193 1194 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1186 def get_membership(room_id, user_id, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) room_id = ERB::Util.url_encode room_id.to_s user_id = ERB::Util.url_encode user_id.to_s request(:get, :client_r0, "/rooms/#{room_id}/state/m.room.member/#{user_id}", query: query) end |
#get_notifications(from: nil, limit: nil, only: nil) ⇒ Response
Enumerates the list of notifies that the current user has/should have received.
1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1832 def get_notifications(from: nil, limit: nil, only: nil) raise ArgumentError, 'Limit must be an integer' unless limit.nil? || limit.is_a?(Integer) query = { from: from, limit: limit, only: only }.compact request(:get, :client_r0, '/notifications', query: query) end |
#get_presence_status(user_id) ⇒ Response
Gets the presence status of a user
1508 1509 1510 1511 1512 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1508 def get_presence_status(user_id) user_id = ERB::Util.url_encode user_id.to_s request(:get, :client_r0, "/presence/#{user_id}/status") end |
#get_profile(user_id, **params) ⇒ Response
Gets the combined profile object of a user.
This includes their display name and avatar
1463 1464 1465 1466 1467 1468 1469 1470 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1463 def get_profile(user_id, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) user_id = ERB::Util.url_encode user_id.to_s request(:get, :client_r0, "/profile/#{user_id}", query: query) end |
#get_public_rooms(server: nil, **params) ⇒ Response
Gets the list of public rooms on a Matrix server
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 401 def get_public_rooms(server: nil, **params) query = { server: server }.compact body = nil method = :get if !params[:filter].nil? || !params[:include_all_networks].nil? || !params[:third_party_instance_id].nil? body = { limit: params[:limit], since: params[:since], filter: params[:filter], include_all_networks: params[:include_all_networks], third_party_instance_id: params[:third_party_instance_id] }.merge(params).compact method = :post else query = query.merge(params).compact end request(method, :client_r0, '/publicRooms', query: query, body: body) end |
#get_pushers ⇒ Response
Gets the list of registered pushers for the current user
1786 1787 1788 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1786 def get_pushers request(:get, :client_r0, '/pushers') end |
#get_pushrule(kind:, id:, scope: 'global') ⇒ Response
Retrieves a single registered push rule for the current user
1861 1862 1863 1864 1865 1866 1867 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1861 def get_pushrule(kind:, id:, scope: 'global') scope = ERB::Util.url_encode scope.to_s kind = ERB::Util.url_encode kind.to_s id = ERB::Util.url_encode id.to_s request(:get, :client_r0, "/pushrules/#{scope}/#{kind}/#{id}") end |
#get_pushrule_actions(kind:, id:, scope: 'global') ⇒ Response
Gets the current list of actions for a specific push rule for the current user
1914 1915 1916 1917 1918 1919 1920 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1914 def get_pushrule_actions(kind:, id:, scope: 'global') scope = ERB::Util.url_encode scope.to_s kind = ERB::Util.url_encode kind.to_s id = ERB::Util.url_encode id.to_s request(:get, :client_r0, "/pushrules/#{scope}/#{kind}/#{id}/actions") end |
#get_pushrule_enabled(kind:, id:, scope: 'global') ⇒ Response
Checks if a push rule for the current user is enabled
1877 1878 1879 1880 1881 1882 1883 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1877 def get_pushrule_enabled(kind:, id:, scope: 'global') scope = ERB::Util.url_encode scope.to_s kind = ERB::Util.url_encode kind.to_s id = ERB::Util.url_encode id.to_s request(:get, :client_r0, "/pushrules/#{scope}/#{kind}/#{id}/enabled") end |
#get_pushrules ⇒ Response
Retrieves the full list of registered push rules for the current user
1849 1850 1851 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1849 def get_pushrules request(:get, :client_r0, '/pushrules/') end |
#get_room_account_data(user_id, room_id, type_key, **params) ⇒ Object
1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1326 def get_room_account_data(user_id, room_id, type_key, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) user_id = ERB::Util.url_encode user_id.to_s room_id = ERB::Util.url_encode room_id.to_s type_key = ERB::Util.url_encode type_key.to_s request(:get, :client_r0, "/user/#{user_id}/rooms/#{room_id}/account_data/#{type_key}", query: query) end |
#get_room_aliases(room_id, **params) ⇒ Response
Gets a list of current aliases of a room
904 905 906 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 904 def get_room_aliases(room_id, **params) get_room_state(room_id, 'm.room.aliases', params) end |
#get_room_avatar(room_id, **params) ⇒ Response
Gets the current avatar URL of a room
862 863 864 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 862 def get_room_avatar(room_id, **params) get_room_state(room_id, 'm.room.avatar', params) end |
#get_room_creation_info(room_id, **params) ⇒ Response
Gets the creation configuration object for a room
1027 1028 1029 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1027 def get_room_creation_info(room_id, **params) get_room_state(room_id, 'm.room.create', params) end |
#get_room_directory_visibility(room_id, **params) ⇒ Response
Gets the room directory visibility status for a room
1238 1239 1240 1241 1242 1243 1244 1245 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1238 def get_room_directory_visibility(room_id, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) room_id = ERB::Util.url_encode room_id.to_s request(:get, :client_r0, "/directory/list/room/#{room_id}", query: query) end |
#get_room_encryption_settings(room_id, **params) ⇒ Response
Gets the encryption configuration for a room
1039 1040 1041 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1039 def get_room_encryption_settings(room_id, **params) get_room_state(room_id, 'm.room.encryption', params) end |
#get_room_event(room_id, event_id, **params) ⇒ Response
Gets a specific event from a room
727 728 729 730 731 732 733 734 735 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 727 def get_room_event(room_id, event_id, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) room_id = ERB::Util.url_encode room_id.to_s event_id = ERB::Util.url_encode event_id.to_s request(:get, :client_r0, "/rooms/#{room_id}/event/#{event_id}", query: query) end |
#get_room_event_context(room_id, event_id, **params) ⇒ Response
Retrieves number of events that happened just before and after the specified event
781 782 783 784 785 786 787 788 789 790 791 792 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 781 def get_room_event_context(room_id, event_id, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) query[:limit] = params.fetch(:limit) if params.key? :limit query[:filter] = params.fetch(:filter) if params.key? :filter room_id = ERB::Util.url_encode room_id.to_s event_id = ERB::Util.url_encode event_id.to_s request(:get, :client_r0, "/rooms/#{room_id}/context/#{event_id}", query: query) end |
#get_room_guest_access(room_id, **params) ⇒ Response
Gets the guest access settings for a room
999 1000 1001 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 999 def get_room_guest_access(room_id, **params) get_room_state(room_id, 'm.room.guest_access', params) end |
#get_room_history_visibility(room_id, **params) ⇒ Response
Gets the history availabiilty for a room
1070 1071 1072 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1070 def get_room_history_visibility(room_id, **params) get_room_state(room_id, 'm.room.history_visibility', params) end |
#get_room_id(room_alias, **params) ⇒ Response
Gets the room ID for an alias
1615 1616 1617 1618 1619 1620 1621 1622 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1615 def get_room_id(room_alias, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) room_alias = ERB::Util.url_encode room_alias.to_s request(:get, :client_r0, "/directory/room/#{room_alias}", query: query) end |
#get_room_join_rules(room_id, **params) ⇒ Response
Gets the join rules for a room
971 972 973 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 971 def get_room_join_rules(room_id, **params) get_room_state(room_id, 'm.room.join_rules', params) end |
#get_room_joined_members(room_id, **params) ⇒ Response
Gets a list of the joined members in a room
1673 1674 1675 1676 1677 1678 1679 1680 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1673 def get_room_joined_members(room_id, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) room_id = ERB::Util.url_encode room_id.to_s request(:get, :client_r0, "/rooms/#{room_id}/joined_members", query: query) end |
#get_room_members(room_id, **params) ⇒ Response
Gets a list of all the members in a room
1658 1659 1660 1661 1662 1663 1664 1665 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1658 def get_room_members(room_id, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) room_id = ERB::Util.url_encode room_id.to_s request(:get, :client_r0, "/rooms/#{room_id}/members", query: query.merge(params)) end |
#get_room_messages(room_id, token, direction, limit: 10, **params) ⇒ Response
Retrieve additional messages in a room
705 706 707 708 709 710 711 712 713 714 715 716 717 718 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 705 def (room_id, token, direction, limit: 10, **params) query = { from: token, dir: direction, limit: limit } query[:to] = params[:to] if params.key? :to query[:filter] = params.fetch(:filter) if params.key? :filter query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) room_id = ERB::Util.url_encode room_id.to_s request(:get, :client_r0, "/rooms/#{room_id}/messages", query: query) end |
#get_room_name(room_id, **params) ⇒ Response
Gets the current display name of a room
806 807 808 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 806 def get_room_name(room_id, **params) get_room_state(room_id, 'm.room.name', params) end |
#get_room_pinned_events(room_id, **params) ⇒ Response
Gets a list of pinned events in a room
917 918 919 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 917 def get_room_pinned_events(room_id, **params) get_room_state(room_id, 'm.room.pinned_events', params) end |
#get_room_power_levels(room_id, **params) ⇒ Response Also known as: get_power_levels
Gets the configured power levels for a room
944 945 946 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 944 def get_room_power_levels(room_id, **params) get_room_state(room_id, 'm.room.power_levels', params) end |
#get_room_server_acl(room_id, **params) ⇒ Response
Gets the server ACLs for a room
1098 1099 1100 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1098 def get_room_server_acl(room_id, **params) get_room_state(room_id, 'm.room.server_acl', params) end |
#get_room_state(room_id, state_type, key: nil, **params) ⇒ Response
Reads the latest instance of a room state event
744 745 746 747 748 749 750 751 752 753 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 744 def get_room_state(room_id, state_type, key: nil, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) room_id = ERB::Util.url_encode room_id.to_s state_type = ERB::Util.url_encode state_type.to_s key = ERB::Util.url_encode key.to_s request(:get, :client_r0, "/rooms/#{room_id}/state/#{state_type}#{key.empty? ? nil : "/#{key}"}", query: query) end |
#get_room_state_all(room_id, **params) ⇒ Response
Retrieves all current state objects from a room
761 762 763 764 765 766 767 768 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 761 def get_room_state_all(room_id, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) room_id = ERB::Util.url_encode room_id.to_s request(:get, :client_r0, "/rooms/#{room_id}/state", query: query) end |
#get_room_topic(room_id, **params) ⇒ Response
Gets the current topic of a room
834 835 836 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 834 def get_room_topic(room_id, **params) get_room_state(room_id, 'm.room.topic', params) end |
#get_turn_server ⇒ Response
Gets TURN server connection information and credentials
1477 1478 1479 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1477 def get_turn_server request(:get, :client_r0, '/voip/turnServer') end |
#get_url_preview(url, timestamp: nil) ⇒ Response
Gets a preview of the given URL
1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1568 def get_url_preview(url, timestamp: nil) ts = (.to_i * 1000) if .is_a? Time ts = if .is_a? Integer query = { url: url, ts: ts }.compact request(:get, :media_r0, '/preview_url', query: query) end |
#get_user_tags(user_id, room_id, **params) ⇒ Object
1267 1268 1269 1270 1271 1272 1273 1274 1275 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1267 def (user_id, room_id, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) room_id = ERB::Util.url_encode room_id.to_s user_id = ERB::Util.url_encode user_id.to_s request(:get, :client_r0, "/user/#{user_id}/rooms/#{room_id}/tags", query: query) end |
#invite_user(room_id, user_id, **params) ⇒ Object
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1160 def invite_user(room_id, user_id, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) content = { user_id: user_id } room_id = ERB::Util.url_encode room_id.to_s request(:post, :client_r0, "/rooms/#{room_id}/invite", body: content, query: query) end |
#join_room(id_or_alias, **params) ⇒ Response
Add support for 3rd-party signed objects
Joins a room
454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 454 def join_room(id_or_alias, **params) query = {} query[:server_name] = params[:server_name] if params[:server_name] query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) # id_or_alias = MXID.new id_or_alias.to_s unless id_or_alias.is_a? MXID # raise ArgumentError, 'Not a room ID or alias' unless id_or_alias.room? id_or_alias = ERB::Util.url_encode id_or_alias.to_s request(:post, :client_r0, "/join/#{id_or_alias}", query: query) end |
#join_room_id(room_id, third_party_signed: nil, **params) ⇒ Response
Directly joins a room by ID
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1147 def join_room_id(room_id, third_party_signed: nil, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) body = { third_party_signed: third_party_signed }.compact room_id = ERB::Util.url_encode room_id.to_s request(:post, :client_r0, "/rooms/#{room_id}/join", body: body, query: query) end |
#keys_query(device_keys:, timeout: nil, token: nil, **params) ⇒ Object
Run a query for device keys
1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1739 def keys_query(device_keys:, timeout: nil, token: nil, **params) body = { timeout: (timeout || 10) * 1000, device_keys: device_keys } body[:timeout] = params[:timeout_ms] if params.key? :timeout_ms body[:token] = token if token request(:post, :client_r0, '/keys/query', body: body) end |
#kick_user(room_id, user_id, reason: '', **params) ⇒ Object
1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1173 def kick_user(room_id, user_id, reason: '', **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) content = { user_id: user_id, reason: reason } room_id = ERB::Util.url_encode room_id.to_s request(:post, :client_r0, "/rooms/#{room_id}/kick", body: content, query: query) end |
#leave_room(room_id, **params) ⇒ Object
1122 1123 1124 1125 1126 1127 1128 1129 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1122 def leave_room(room_id, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) room_id = ERB::Util.url_encode room_id.to_s request(:post, :client_r0, "/rooms/#{room_id}/leave", query: query) end |
#login(login_type: 'm.login.password', **params) ⇒ Response
Logs in using the client API /login endpoint, and optionally stores the resulting access for API usage
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 179 def login(login_type: 'm.login.password', **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) = {} [:store_token] = params.delete(:store_token) { true } [:store_device_id] = params.delete(:store_device_id) { [:store_token] } data = { type: login_type, initial_device_display_name: params.delete(:initial_device_display_name) { MatrixSdk::Api::USER_AGENT } }.merge params data[:device_id] = device_id if device_id request(:post, :client_r0, '/login', body: data, query: query).tap do |resp| @access_token = resp.token if resp.key?(:token) && [:store_token] @device_id = resp.device_id if resp.key?(:device_id) && [:store_device_id] end end |
#logout(**params) ⇒ Response
Logs out the currently logged in device for the current user
203 204 205 206 207 208 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 203 def logout(**params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) request(:post, :client_r0, '/logout', query: query) end |
#logout_all(**params) ⇒ Response
Logs out the currently logged in user
214 215 216 217 218 219 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 214 def logout_all(**params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) request(:post, :client_r0, '/logout/all', query: query) end |
#media_upload(content, content_type, **params) ⇒ Object
1383 1384 1385 1386 1387 1388 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1383 def media_upload(content, content_type, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) request(:post, :media_r0, '/upload', body: content, headers: { 'content-type' => content_type }, query: query) end |
#redact_event(room_id, event_id, **params) ⇒ Response
Redact an event in a room
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 520 def redact_event(room_id, event_id, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) content = {} content[:reason] = params[:reason] if params[:reason] txn_id = transaction_id txn_id = params.fetch(:txn_id, "#{txn_id}#{Time.now.to_i}") room_id = ERB::Util.url_encode room_id.to_s event_id = ERB::Util.url_encode event_id.to_s txn_id = ERB::Util.url_encode txn_id.to_s request(:put, :client_r0, "/rooms/#{room_id}/redact/#{event_id}/#{txn_id}", body: content, query: query) end |
#register(kind: 'user', **params) ⇒ Response
Registers a user using the client API /register endpoint
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 85 def register(kind: 'user', **params) query = {} query[:kind] = kind query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) store_token = params.delete(:store_token) { !protocol?(:AS) } store_device_id = params.delete(:store_device_id) { store_token } request(:post, :client_r0, '/register', body: params, query: query).tap do |resp| @access_token = resp.token if resp.key?(:token) && store_token @device_id = resp.device_id if resp.key?(:device_id) && store_device_id end end |
#register_email_request(secret, email, attempt: 1, next_link: nil) ⇒ Response
Requests to register an email address to the current account
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 108 def register_email_request(secret, email, attempt: 1, next_link: nil) body = { client_secret: secret, email: email, send_attempt: attempt, next_link: next_link }.compact request(:post, :client_r0, '/register/email/requestToken', body: body) end |
#register_msisdn_request(secret, country, number, attempt: 1, next_link: nil) ⇒ Response
Requests to register a phone number to the current account
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 129 def register_msisdn_request(secret, country, number, attempt: 1, next_link: nil) body = { client_secret: secret, country: country, phone_number: number, send_attempt: attempt, next_link: next_link }.compact request(:post, :client_r0, '/register/msisdn/requestToken', body: body) end |
#remove_room_alias(room_alias, **params) ⇒ Response
Remove an alias from its room
1644 1645 1646 1647 1648 1649 1650 1651 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1644 def remove_room_alias(room_alias, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) room_alias = ERB::Util.url_encode room_alias.to_s request(:delete, :client_r0, "/directory/room/#{room_alias}", query: query) end |
#remove_user_tag(user_id, room_id, tag, **params) ⇒ Object
1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1277 def remove_user_tag(user_id, room_id, tag, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) room_id = ERB::Util.url_encode room_id.to_s user_id = ERB::Util.url_encode user_id.to_s tag = ERB::Util.url_encode tag.to_s request(:delete, :client_r0, "/user/#{user_id}/rooms/#{room_id}/tags/#{tag}", query: query) end |
#report_event(room_id, event_id, score:, reason:, **params) ⇒ Object
Report an event in a room
678 679 680 681 682 683 684 685 686 687 688 689 690 691 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 678 def report_event(room_id, event_id, score:, reason:, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) body = { score: score, reason: reason } room_id = ERB::Util.url_encode room_id.to_s event_id = ERB::Util.url_encode event_id.to_s request(:post, :client_r0, "/rooms/#{room_id}/report/#{event_id}", body: body, query: query) end |
#request_email_login_token(secret, email, attempt: 1, next_link: nil) ⇒ Response
Requests an authentication token based on an email address
250 251 252 253 254 255 256 257 258 259 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 250 def request_email_login_token(secret, email, attempt: 1, next_link: nil) body = { client_secret: secret, email: email, send_attempt: attempt, next_link: next_link }.compact request(:post, :client_r0, '/account/password/email/requestToken', body: body) end |
#request_msisdn_login_token(secret, country, number, attempt: 1, next_link: nil) ⇒ Response
Requests an authentication token based on a phone number
271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 271 def request_msisdn_login_token(secret, country, number, attempt: 1, next_link: nil) body = { client_secret: secret, country: country, phone_number: number, send_attempt: attempt, next_link: next_link }.compact request(:post, :client_r0, '/account/password/msisdn/requestToken', body: body) end |
#send_content(room_id, url, name, msg_type, **params) ⇒ Response
Send a content message to a room
578 579 580 581 582 583 584 585 586 587 588 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 578 def send_content(room_id, url, name, msg_type, **params) content = { url: url, msgtype: msg_type, body: name, info: params.delete(:extra_information) { {} } } content.merge!(params.fetch(:extra_content)) if params.key? :extra_content (room_id, 'm.room.message', content, params) end |
#send_emote(room_id, emote, **params) ⇒ Response
Send a plaintext emote to a room
644 645 646 647 648 649 650 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 644 def send_emote(room_id, emote, **params) content = { msgtype: params.delete(:msg_type) { 'm.emote' }, body: emote } (room_id, 'm.room.message', content, params) end |
#send_location(room_id, geo_uri, name, **params) ⇒ Response
Send a geographic location to a room
603 604 605 606 607 608 609 610 611 612 613 614 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 603 def send_location(room_id, geo_uri, name, **params) content = { geo_uri: geo_uri, msgtype: 'm.location', body: name, info: params.delete(:extra_information) { {} } } content[:info][:thumbnail_url] = params.delete(:thumbnail_url) if params.key? :thumbnail_url content[:info][:thumbnail_info] = params.delete(:thumbnail_info) if params.key? :thumbnail_info (room_id, 'm.room.message', content, params) end |
#send_message(room_id, message, **params) ⇒ Response
Send a plaintext message to a room
626 627 628 629 630 631 632 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 626 def (room_id, , **params) content = { msgtype: params.delete(:msg_type) { 'm.text' }, body: } (room_id, 'm.room.message', content, params) end |
#send_message_event(room_id, event_type, content, **params) ⇒ Response
Sends a message event to a room
497 498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 497 def (room_id, event_type, content, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) txn_id = transaction_id txn_id = params.fetch(:txn_id, "#{txn_id}#{Time.now.to_i}") room_id = ERB::Util.url_encode room_id.to_s event_type = ERB::Util.url_encode event_type.to_s txn_id = ERB::Util.url_encode txn_id.to_s request(:put, :client_r0, "/rooms/#{room_id}/send/#{event_type}/#{txn_id}", body: content, query: query) end |
#send_notice(room_id, notice, **params) ⇒ Response
Send a plaintext notice to a room
662 663 664 665 666 667 668 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 662 def send_notice(room_id, notice, **params) content = { msgtype: params.delete(:msg_type) { 'm.notice' }, body: notice } (room_id, 'm.room.message', content, params) end |
#send_state_event(room_id, event_type, content, **params) ⇒ Response
Sends a state event to a room
477 478 479 480 481 482 483 484 485 486 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 477 def send_state_event(room_id, event_type, content, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) room_id = ERB::Util.url_encode room_id.to_s event_type = ERB::Util.url_encode event_type.to_s state_key = ERB::Util.url_encode params[:state_key].to_s if params.key? :state_key request(:put, :client_r0, "/rooms/#{room_id}/state/#{event_type}#{"/#{state_key}" unless state_key.nil?}", body: content, query: query) end |
#send_to_device(event_type, messages:, **params) ⇒ Object
Sends events directly to the specified devices
1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1597 def send_to_device(event_type, messages:, **params) txn_id = transaction_id txn_id = params.fetch(:txn_id, "#{txn_id}#{Time.now.to_i}") event_type = ERB::Util.url_encode event_type.to_s txn_id = ERB::Util.url_encode txn_id.to_s body = { messages: }.compact request(:put, :client_r0, "/sendToDevice/#{event_type}/#{txn_id}", body: body) end |
#set_account_data(user_id, type_key, account_data, **params) ⇒ Object
1316 1317 1318 1319 1320 1321 1322 1323 1324 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1316 def set_account_data(user_id, type_key, account_data, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) user_id = ERB::Util.url_encode user_id.to_s type_key = ERB::Util.url_encode type_key.to_s request(:put, :client_r0, "/user/#{user_id}/account_data/#{type_key}", body: account_data, query: query) end |
#set_avatar_url(user_id, url, **params) ⇒ Response
Sets the avatar URL for a user
1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1442 def set_avatar_url(user_id, url, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) content = { avatar_url: url } user_id = ERB::Util.url_encode user_id.to_s request(:put, :client_r0, "/profile/#{user_id}/avatar_url", body: content, query: query) end |
#set_device(device_id, display_name:) ⇒ Object
Sets the metadata for a device
1706 1707 1708 1709 1710 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1706 def set_device(device_id, display_name:) device_id = ERB::Util.url_encode device_id.to_s request(:put, :client_r0, "/devices/#{device_id}", body: { display_name: display_name }) end |
#set_display_name(user_id, display_name, **params) ⇒ Object
1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1399 def set_display_name(user_id, display_name, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) content = { displayname: display_name } user_id = ERB::Util.url_encode user_id.to_s request(:put, :client_r0, "/profile/#{user_id}/displayname", body: content, query: query) end |
#set_membership(room_id, user_id, membership, reason: '', **params) ⇒ Object
1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1196 def set_membership(room_id, user_id, membership, reason: '', **params) content = { membership: membership, reason: reason } content[:displayname] = params.delete(:displayname) if params.key? :displayname content[:avatar_url] = params.delete(:avatar_url) if params.key? :avatar_url send_state_event(room_id, 'm.room.member', content, params.merge(state_key: user_id)) end |
#set_presence_status(user_id, status, message: nil) ⇒ Response
The specified user_id should be of the local user unless used for AS purposes
Sets the presence status of a user
1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1523 def set_presence_status(user_id, status, message: nil) user_id = ERB::Util.url_encode user_id.to_s body = { presence: status, status_msg: }.compact request(:put, :client_r0, "/presence/#{user_id}/status", body: body) end |
#set_pusher(key, kind:, app_id:, app_name:, device_name:, lang:, data:, **params) ⇒ Response
Sets a pusher on the current user
1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1807 def set_pusher(key, kind:, app_id:, app_name:, device_name:, lang:, data:, **params) body = { pushkey: key, kind: kind, app_id: app_id, app_display_name: app_name, device_display_name: device_name, profile_tag: params[:profile_tag], lang: lang, data: data, append: params[:append] }.compact request(:post, :client_r0, '/pushers/set', body: body) end |
#set_pushrule_actions(actions, kind:, id:, scope: 'global') ⇒ Response
Replaces the list of actions for a push rule for the current user
1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1931 def set_pushrule_actions(actions, kind:, id:, scope: 'global') scope = ERB::Util.url_encode scope.to_s kind = ERB::Util.url_encode kind.to_s id = ERB::Util.url_encode id.to_s actions = [actions] unless actions.is_a? Array body = { actions: actions } request(:put, :client_r0, "/pushrules/#{scope}/#{kind}/#{id}/actions", body: body) end |
#set_pushrule_enabled(enabled, kind:, id:, scope: 'global') ⇒ Response
Enabled/Disables a specific push rule for the current user
1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1894 def set_pushrule_enabled(enabled, kind:, id:, scope: 'global') scope = ERB::Util.url_encode scope.to_s kind = ERB::Util.url_encode kind.to_s id = ERB::Util.url_encode id.to_s body = { enabled: enabled } request(:put, :client_r0, "/pushrules/#{scope}/#{kind}/#{id}/enabled", body: body) end |
#set_room_account_data(user_id, room_id, type_key, account_data, **params) ⇒ Object
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1337 def set_room_account_data(user_id, room_id, type_key, account_data, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) user_id = ERB::Util.url_encode user_id.to_s room_id = ERB::Util.url_encode room_id.to_s type_key = ERB::Util.url_encode type_key.to_s request(:put, :client_r0, "/user/#{user_id}/rooms/#{room_id}/account_data/#{type_key}", body: account_data, query: query) end |
#set_room_alias(room_id, room_alias, **params) ⇒ Response
Sets the room ID for an alias
1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1629 def set_room_alias(room_id, room_alias, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) content = { room_id: room_id } room_alias = ERB::Util.url_encode room_alias.to_s request(:put, :client_r0, "/directory/room/#{room_alias}", body: content, query: query) end |
#set_room_avatar(room_id, url, **params) ⇒ Response
Sets the avatar URL for a room
874 875 876 877 878 879 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 874 def set_room_avatar(room_id, url, **params) content = { url: url } send_state_event(room_id, 'm.room.avatar', content, params) end |
#set_room_directory_visibility(room_id, visibility, **params) ⇒ Response
Sets the room directory visibility status for a room
1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1254 def set_room_directory_visibility(room_id, visibility, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) body = { visibility: visibility } room_id = ERB::Util.url_encode room_id.to_s request(:put, :client_r0, "/directory/list/room/#{room_id}", body: body, query: query) end |
#set_room_encryption_settings(room_id, algorithm: 'm.megolm.v1.aes-sha2', rotation_period_ms: 1 * 7 * 24 * 60 * 60 * 1000, rotation_period_msgs: 100, **params) ⇒ Response
Sets the encryption configuration for a room
1053 1054 1055 1056 1057 1058 1059 1060 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1053 def set_room_encryption_settings(room_id, algorithm: 'm.megolm.v1.aes-sha2', rotation_period_ms: 1 * 7 * 24 * 60 * 60 * 1000, rotation_period_msgs: 100, **params) content = { algorithm: algorithm, rotation_period_ms: rotation_period_ms, rotation_period_msgs: rotation_period_msgs } send_state_event(room_id, 'm.room.encryption', content, params) end |
#set_room_guest_access(room_id, guest_access, **params) ⇒ Response
Sets the guest access settings for a room
1011 1012 1013 1014 1015 1016 1017 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1011 def set_room_guest_access(room_id, guest_access, **params) content = { guest_access: guest_access } send_state_event(room_id, 'm.room.guest_access', content, params) end |
#set_room_history_visibility(room_id, visibility, **params) ⇒ Response
Sets the history availability for a room
1082 1083 1084 1085 1086 1087 1088 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1082 def set_room_history_visibility(room_id, visibility, **params) content = { history_visibility: visibility } send_state_event(room_id, 'm.room.history_visibility', content, params) end |
#set_room_join_rules(room_id, join_rule, **params) ⇒ Response
Sets the join rules for a room
983 984 985 986 987 988 989 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 983 def set_room_join_rules(room_id, join_rule, **params) content = { join_rule: join_rule } send_state_event(room_id, 'm.room.join_rules', content, params) end |
#set_room_name(room_id, name, **params) ⇒ Response
Sets the display name of a room
818 819 820 821 822 823 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 818 def set_room_name(room_id, name, **params) content = { name: name } send_state_event(room_id, 'm.room.name', content, params) end |
#set_room_pinned_events(room_id, events, **params) ⇒ Response
Sets the list of pinned events in a room
929 930 931 932 933 934 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 929 def set_room_pinned_events(room_id, events, **params) content = { pinned: events } send_state_event(room_id, 'm.room.pinned_events', content, params) end |
#set_room_power_levels(room_id, content, **params) ⇒ Response Also known as: set_power_levels
Sets the configuration for power levels in a room
957 958 959 960 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 957 def set_room_power_levels(room_id, content, **params) content[:events] = {} unless content.key? :events send_state_event(room_id, 'm.room.power_levels', content, params) end |
#set_room_server_acl(room_id, allow:, deny:, allow_ip_literals: false, **params) ⇒ Response
Sets the server ACL configuration for a room
1112 1113 1114 1115 1116 1117 1118 1119 1120 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1112 def set_room_server_acl(room_id, allow:, deny:, allow_ip_literals: false, **params) content = { allow_ip_literals: allow_ip_literals, allow: allow, deny: deny } send_state_event(room_id, 'm.room.server_acl', content, params) end |
#set_room_topic(room_id, topic, **params) ⇒ Response
Sets the topic of a room
846 847 848 849 850 851 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 846 def set_room_topic(room_id, topic, **params) content = { topic: topic } send_state_event(room_id, 'm.room.topic', content, params) end |
#set_typing(room_id, user_id, typing: true, timeout: nil) ⇒ Response
Sets the typing status for a user
1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1490 def set_typing(room_id, user_id, typing: true, timeout: nil) room_id = ERB::Util.url_encode room_id.to_s user_id = ERB::Util.url_encode user_id.to_s body = { typing: typing, timeout: timeout ? timeout * 1000 : nil }.compact request(:put, :client_r0, "/rooms/#{room_id}/typing/#{user_id}", body: body) end |
#sync(timeout: 30.0, **params) ⇒ Response
Runs the client API /sync method
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 58 def sync(timeout: 30.0, **params) query = params.select do |k, _v| %i[since filter full_state set_presence].include? k end query[:timeout] = (timeout * 1000).to_i if timeout query[:timeout] = params.delete(:timeout_ms).to_i if params.key? :timeout_ms query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) request(:get, :client_r0, '/sync', query: query) end |
#unban_user(room_id, user_id, **params) ⇒ Object
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1220 def unban_user(room_id, user_id, **params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) content = { user_id: user_id } room_id = ERB::Util.url_encode room_id.to_s request(:post, :client_r0, "/rooms/#{room_id}/unban", body: content, query: query) end |
#unbind_3pid(medium, address, id_server:) ⇒ Response
Unbinds a 3PID from the current user
370 371 372 373 374 375 376 377 378 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 370 def unbind_3pid(medium, address, id_server:) body = { address: address, id_server: id_server, medium: medium } request(:post, :client_r0, '/account/3pid/unbind', body: body) end |
#username_available?(username) ⇒ Response
Checks if a given username is available and valid for registering
150 151 152 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 150 def username_available?(username) request(:get, :client_r0, '/register/available', query: { username: username }) end |
#whoami?(**params) ⇒ Response
Gets the MXID of the currently logged-in user
1947 1948 1949 1950 1951 1952 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1947 def whoami?(**params) query = {} query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id) request(:get, :client_r0, '/account/whoami', query: query) end |
#whois(user_id) ⇒ Response
Retrieve user information
1354 1355 1356 1357 1358 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 1354 def whois(user_id) user_id = ERB::Util.url_encode user_id.to_s request(:get, :client_r0, "/admin/whois/#{user_id}") end |