Class: MatrixSdk::ApplicationService

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/matrix_sdk/application_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger

Constructor Details

#initialize(hs_url, as_token:, hs_token:, default_routes: true, **params) ⇒ ApplicationService

Returns a new instance of ApplicationService.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/matrix_sdk/application_service.rb', line 14

def initialize(hs_url, as_token:, hs_token:, default_routes: true, **params)
  logger.warning 'This abstraction is still under HEAVY development, expect errors'

  params = { protocols: %i[AS CS] }.merge(params).merge(access_token: as_token)
  if hs_url.is_a? Api
    @api = hs_url
    params.each do |k, v|
      api.instance_variable_set("@#{k}", v) if api.instance_variable_defined? "@#{k}"
    end
  else
    @api = Api.new hs_url, params
  end

  @id = params.fetch(:id, MatrixSdk::Api::USER_AGENT)
  @port = params.fetch(:port, 8888)
  @url = params.fetch(:url, URI("http://localhost:#{@port}"))
  @as_token = as_token
  @hs_token = hs_token

  @method_map = {}

  if default_routes
    add_method(:GET, '/_matrix/app/v1/users/', %r{^/_matrix/app/v1/users/(?<user>[^/]+)$}, :do_get_user)
    add_method(:GET, '/_matrix/app/v1/rooms/', %r{^/_matrix/app/v1/rooms/(?<room>[^/]+)$}, :do_get_room)

    add_method(:GET, '/_matrix/app/v1/thirdparty/protocol/', %r{^/_matrix/app/v1/thirdparty/protocol/(?<protocol>[^/]+)$}, :do_get_3p_protocol_p)
    add_method(:GET, '/_matrix/app/v1/thirdparty/user/', %r{^/_matrix/app/v1/thirdparty/user/(?<protocol>[^/]+)$}, :do_get_3p_user_p)
    add_method(:GET, '/_matrix/app/v1/thirdparty/location/', %r{^/_matrix/app/v1/thirdparty/location/(?<protocol>[^/]+)$}, :do_get_3p_location_p)
    add_method(:GET, '/_matrix/app/v1/thirdparty/user', %r{^/_matrix/app/v1/thirdparty/user$}, :do_get_3p_user)
    add_method(:GET, '/_matrix/app/v1/thirdparty/location', %r{^/_matrix/app/v1/thirdparty/location$}, :do_get_3p_location)

    add_method(:PUT, '/_matrix/app/v1/transactions/', %r{^/_matrix/app/v1/transactions/(?<txn_id>[^/]+)$}, :do_put_transaction)

    if params.fetch(:legacy_routes, false)
      add_method(:GET, '/users/', %r{^/users/(?<user>[^/]+)$}, :do_get_user)
      add_method(:GET, '/rooms/', %r{^/rooms/(?<room>[^/]+)$}, :do_get_room)

      add_method(:GET, '/_matrix/app/unstable/thirdparty/protocol/', %r{^/_matrix/app/unstable/thirdparty/protocol/(?<protocol>[^/]+)$}, :do_get_3p_protocol_p)
      add_method(:GET, '/_matrix/app/unstable/thirdparty/user/', %r{^/_matrix/app/unstable/thirdparty/user/(?<protocol>[^/]+)$}, :do_get_3p_user_p)
      add_method(:GET, '/_matrix/app/unstable/thirdparty/location/', %r{^/_matrix/app/unstable/thirdparty/location/(?<protocol>[^/]+)$}, :do_get_3p_location_p)
      add_method(:GET, '/_matrix/app/unstable/thirdparty/user', %r{^/_matrix/app/unstable/thirdparty/user$}, :do_get_3p_user)
      add_method(:GET, '/_matrix/app/unstable/thirdparty/location', %r{^/_matrix/app/unstable/thirdparty/location$}, :do_get_3p_location)

      add_method(:PUT, '/transactions/', %r{^/transactions/(?<txn_id>[^/]+)$}, :do_put_transaction)
    end
  end

  start_server
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



8
9
10
# File 'lib/matrix_sdk/application_service.rb', line 8

def api
  @api
end

#portObject

Returns the value of attribute port.



8
9
10
# File 'lib/matrix_sdk/application_service.rb', line 8

def port
  @port
end

Instance Method Details

#registrationObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/matrix_sdk/application_service.rb', line 64

def registration
  {
    id: @id,
    url: @url,
    as_token: @as_token,
    hs_token: @hs_token,
    sender_localpart: '',
    namespaces: {
      users: [],
      aliases: [],
      rooms: []
    },
    rate_limited: false,
    protocols: []
  }
end