Method: MatrixSdk::Protocols::CS#register

Defined in:
lib/matrix_sdk/protocols/cs.rb

#register(kind: 'user', **params) ⇒ Response

Registers a user using the client API /register endpoint

Examples:

Regular user registration and login

api.register(username: 'example', password: 'NotARealPass')
# => { user_id: '@example:matrix.org', access_token: '...', home_server: 'matrix.org', device_id: 'ABCD123' }
api.whoami?
# => { user_id: '@example:matrix.org' }

Parameters:

  • kind (String, Symbol) (defaults to: 'user')

    (‘user’) The kind of registration to use

  • params (Hash)

    The registration information, all not handled by Ruby will be passed as JSON in the body

Options Hash (**params):

  • :store_token (Boolean) — default: true

    Should the resulting access token be stored for the API

  • :store_device_id (Boolean) — default: store_token value

    Should the resulting device ID be stored for the API

Returns:

See Also:



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