Module: MatrixSdk::Protocols::CS
- Included in:
- Api
- Defined in:
- lib/matrix_sdk/protocols/cs.rb
Instance Method Summary collapse
- #add_user_tag(user_id, room_id, tag, **params) ⇒ Object
- #ban_user(room_id, user_id, reason: '', **params) ⇒ Object
-
#client_api_unstable_features ⇒ Array
Gets the list of available unstable client API features.
-
#client_api_versions ⇒ Array
Gets the available client API versions.
- #create_filter(user_id, filter_params, **params) ⇒ Object
-
#create_room(visibility: :public, **params) ⇒ Response
Creates a new room.
- #delete_device(device_id, auth:) ⇒ Object
- #forget_room(room_id, **params) ⇒ Object
- #get_account_data(user_id, type_key, **params) ⇒ Object
- #get_avatar_url(user_id, **params) ⇒ Object
- #get_device(device_id) ⇒ Object
- #get_devices ⇒ Object
- #get_display_name(user_id, **params) ⇒ Object
- #get_download_url(mxcurl, **_params) ⇒ Object
- #get_filter(user_id, filter_id, **params) ⇒ Object
- #get_membership(room_id, user_id, **params) ⇒ Object
- #get_power_levels(room_id, **params) ⇒ Object
- #get_room_account_data(user_id, room_id, type_key, **params) ⇒ Object
- #get_room_id(room_alias, **params) ⇒ Object
- #get_room_members(room_id, **params) ⇒ Object
-
#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 display name of a room.
-
#get_room_state(room_id, state_type, **params) ⇒ Response
Reads the latest instance of a room state event.
- #get_room_topic(room_id, **params) ⇒ Object
- #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.
- #keys_query(timeout: nil, device_keys:, token: nil, **params) ⇒ Object
- #kick_user(room_id, user_id, **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 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.
- #remove_room_alias(room_alias, **params) ⇒ Object
- #remove_user_tag(user_id, room_id, tag, **params) ⇒ Object
-
#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.
- #set_account_data(user_id, type_key, account_data, **params) ⇒ Object
- #set_avatar_url(user_id, url, **params) ⇒ Object
- #set_device(device_id, display_name:) ⇒ Object
- #set_display_name(user_id, display_name, **params) ⇒ Object
- #set_guest_access(room_id, guest_access, **params) ⇒ Object
- #set_join_rule(room_id, join_rule, **params) ⇒ Object
- #set_membership(room_id, user_id, membership, reason: '', **params) ⇒ Object
- #set_power_levels(room_id, content, **params) ⇒ Object
- #set_room_account_data(user_id, room_id, type_key, account_data, **params) ⇒ Object
- #set_room_alias(room_id, room_alias, **params) ⇒ Object
- #set_room_name(room_id, name, **params) ⇒ Object
- #set_room_topic(room_id, topic, **params) ⇒ Object
-
#sync(timeout: 30.0, **params) ⇒ Response
Runs the client API /sync method.
- #unban_user(room_id, user_id, **params) ⇒ Object
- #whoami?(**params) ⇒ Boolean
Instance Method Details
#add_user_tag(user_id, room_id, tag, **params) ⇒ Object
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 564 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 |
#ban_user(room_id, user_id, reason: '', **params) ⇒ Object
518 519 520 521 522 523 524 525 526 527 528 529 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 518 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 |
#client_api_unstable_features ⇒ Array
Gets the list of available unstable client API features
16 17 18 19 20 21 22 23 24 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 16 def client_api_unstable_features @client_api_unstable_features ||= request(:get, :client, '/versions').unstable_features.tap do |vers| vers.instance_eval " def has?(feature)\n fetch(feature, nil)\n end\n CODE\n end\nend\n", __FILE__, __LINE__ + 1 |
#client_api_versions ⇒ Array
Gets the available client API versions
4 5 6 7 8 9 10 11 12 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 4 def client_api_versions @client_api_versions ||= request(:get, :client, '/versions').versions.tap do |vers| vers.instance_eval " def latest\n latest\n end\n CODE\n end\nend\n", __FILE__, __LINE__ + 1 |
#create_filter(user_id, filter_params, **params) ⇒ Object
634 635 636 637 638 639 640 641 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 634 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
143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 143 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[:room_alias] if params[:room_alias] content[:invite] = [params[:invite]].flatten if params[:invite] request(:post, :client_r0, '/createRoom', content, query: query) end |
#delete_device(device_id, auth:) ⇒ Object
776 777 778 779 780 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 776 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
471 472 473 474 475 476 477 478 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 471 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_account_data(user_id, type_key, **params) ⇒ Object
582 583 584 585 586 587 588 589 590 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 582 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
672 673 674 675 676 677 678 679 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 672 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) ⇒ Object
764 765 766 767 768 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 764 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 ⇒ Object
760 761 762 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 760 def get_devices request(:get, :client_r0, '/devices') end |
#get_display_name(user_id, **params) ⇒ Object
650 651 652 653 654 655 656 657 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 650 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, **_params) ⇒ Object
694 695 696 697 698 699 700 701 702 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 694 def get_download_url(mxcurl, **_params) mxcurl = URI.parse(mxcurl.to_s) unless mxcurl.is_a? URI raise 'Not a mxc:// URL' unless mxcurl.is_a? URI::MATRIX homeserver.dup.tap do |u| full_path = ERB::Util.url_encode mxcurl.full_path.to_s u.path = "/_matrix/media/r0/download/#{full_path}" end end |
#get_filter(user_id, filter_id, **params) ⇒ Object
624 625 626 627 628 629 630 631 632 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 624 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_membership(room_id, user_id, **params) ⇒ Object
497 498 499 500 501 502 503 504 505 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 497 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_power_levels(room_id, **params) ⇒ Object
453 454 455 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 453 def get_power_levels(room_id, **params) get_room_state(room_id, 'm.room.power_levels', params) end |
#get_room_account_data(user_id, room_id, type_key, **params) ⇒ Object
602 603 604 605 606 607 608 609 610 611 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 602 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_id(room_alias, **params) ⇒ Object
704 705 706 707 708 709 710 711 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 704 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_members(room_id, **params) ⇒ Object
734 735 736 737 738 739 740 741 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 734 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) end |
#get_room_messages(room_id, token, direction, limit: 10, **params) ⇒ Response
Retrieve additional messages in a room
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 391 def (room_id, token, direction, limit: 10, **params) query = { roomId: room_id, 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 display name of a room
431 432 433 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 431 def get_room_name(room_id, **params) get_room_state(room_id, 'm.room.name', params) end |
#get_room_state(room_id, state_type, **params) ⇒ Response
Reads the latest instance of a room state event
414 415 416 417 418 419 420 421 422 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 414 def get_room_state(room_id, state_type, **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 request(:get, :client_r0, "/rooms/#{room_id}/state/#{state_type}", query: query) end |
#get_room_topic(room_id, **params) ⇒ Object
442 443 444 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 442 def get_room_topic(room_id, **params) get_room_state(room_id, 'm.room.topic', params) end |
#get_user_tags(user_id, room_id, **params) ⇒ Object
543 544 545 546 547 548 549 550 551 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 543 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
480 481 482 483 484 485 486 487 488 489 490 491 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 480 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
Joins a room
163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 163 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 |
#keys_query(timeout: nil, device_keys:, token: nil, **params) ⇒ Object
782 783 784 785 786 787 788 789 790 791 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 782 def keys_query(timeout: nil, device_keys:, 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, **params) ⇒ Object
493 494 495 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 493 def kick_user(room_id, user_id, **params) set_membership(room_id, user_id, 'leave', params) end |
#leave_room(room_id, **params) ⇒ Object
462 463 464 465 466 467 468 469 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 462 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
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 104 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 user
128 129 130 131 132 133 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 128 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 |
#media_upload(content, content_type, **params) ⇒ Object
643 644 645 646 647 648 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 643 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
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 229 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
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 65 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 |
#remove_room_alias(room_alias, **params) ⇒ Object
725 726 727 728 729 730 731 732 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 725 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
553 554 555 556 557 558 559 560 561 562 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 553 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 |
#send_content(room_id, url, name, msg_type, **params) ⇒ Response
Send a content message to a room
287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 287 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
353 354 355 356 357 358 359 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 353 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
312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 312 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
335 336 337 338 339 340 341 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 335 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
206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 206 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
371 372 373 374 375 376 377 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 371 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
186 187 188 189 190 191 192 193 194 195 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 186 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 |
#set_account_data(user_id, type_key, account_data, **params) ⇒ Object
592 593 594 595 596 597 598 599 600 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 592 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) ⇒ Object
681 682 683 684 685 686 687 688 689 690 691 692 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 681 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
770 771 772 773 774 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 770 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
659 660 661 662 663 664 665 666 667 668 669 670 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 659 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_guest_access(room_id, guest_access, **params) ⇒ Object
751 752 753 754 755 756 757 758 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 751 def set_guest_access(room_id, guest_access, **params) # raise ArgumentError, '`guest_access` must be one of [:can_join, :forbidden]' unless %i[can_join forbidden].include? guest_access content = { guest_access: guest_access } send_state_event(room_id, 'm.room.guest_access', params.merge(content)) end |
#set_join_rule(room_id, join_rule, **params) ⇒ Object
743 744 745 746 747 748 749 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 743 def set_join_rule(room_id, join_rule, **params) content = { join_rule: join_rule } send_state_event(room_id, 'm.room.join_rules', params.merge(content)) end |
#set_membership(room_id, user_id, membership, reason: '', **params) ⇒ Object
507 508 509 510 511 512 513 514 515 516 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 507 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_power_levels(room_id, content, **params) ⇒ Object
457 458 459 460 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 457 def set_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_account_data(user_id, room_id, type_key, account_data, **params) ⇒ Object
613 614 615 616 617 618 619 620 621 622 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 613 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) ⇒ Object
713 714 715 716 717 718 719 720 721 722 723 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 713 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_name(room_id, name, **params) ⇒ Object
435 436 437 438 439 440 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 435 def set_room_name(room_id, name, **params) content = { name: name } send_state_event(room_id, 'm.room.name', content, params) end |
#set_room_topic(room_id, topic, **params) ⇒ Object
446 447 448 449 450 451 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 446 def set_room_topic(room_id, topic, **params) content = { topic: topic } send_state_event(room_id, 'm.room.topic', content, params) end |
#sync(timeout: 30.0, **params) ⇒ Response
Runs the client API /sync method
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 36 def sync(timeout: 30.0, **params) query = { timeout: timeout }.merge(params).select do |k, _v| i[since filter full_state set_presence].include? k end query[:timeout] = (query.fetch(:timeout, 30) * 1000).to_i 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
531 532 533 534 535 536 537 538 539 540 541 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 531 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 |
#whoami?(**params) ⇒ Boolean
793 794 795 796 797 798 |
# File 'lib/matrix_sdk/protocols/cs.rb', line 793 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 |