matrix_sdk 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4cf8d41f930fae4069a51d6fff87e211a790529c5f157ff6402c15b44770f64d
4
- data.tar.gz: 7c06c98e08232dd24f9667dfbb850a2d12ed2021b2f30cb3ad0cbd2a38e8f6e0
3
+ metadata.gz: dee0d341f6962b850245ebbea4e85a9e4e3ac14d809a3f3bf1236d5458e9ef80
4
+ data.tar.gz: 9a1c731a321aee4f85ad4b6f39f85c975aa763308c069494448b200c7b88b1d3
5
5
  SHA512:
6
- metadata.gz: dfc1717d3b368fffd50f3fb717a3742bf821f3863e4c493797117f15a724ee4bf15be3b45d2dc1d7971a0206e1f21febf128eef389cdd8fa42274e6da1208530
7
- data.tar.gz: 1025e4fc9d9f6fe7718971ba3b4c74a0ac35297eb0bb592ad3e25505ec2ec39a36c5d518a835e357b93994db4197066566b17c0696c2298017cdc560e7e7a1ee
6
+ metadata.gz: ce68baa4997e7ba558c06458d3660d8c1429f352989c1dbef9b47943d77180bb646d45c8a727d29928318f3908ca51240335851b8ee66a345750bef71fd5bfd7
7
+ data.tar.gz: 51d7bb564f54c1f4f82700ea7f149837b24035859319be96357bfcb538d948a07b62dbe78e570ebc0090befcd099c5892422c71cc2ab3567296250772af70ae9
data/.gitlab-ci.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- image: "ruby:2.4"
2
+ image: "ruby:2.6"
3
3
 
4
4
  # Cache gems in between builds
5
5
  cache:
@@ -17,9 +17,13 @@ rubocop:
17
17
  - rubocop lib
18
18
 
19
19
  test:
20
+ coverage: '/\((\d+.\d+\%)\) covered/'
20
21
  script:
21
22
  - GENERATE_REPORTS=true CI_REPORTS=reports bundle exec rake test
22
23
  artifacts:
24
+ expire_in: 1 week
25
+ paths:
26
+ - coverage/
23
27
  reports:
24
28
  junit: "reports/TEST-*.xml"
25
29
 
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.2
2
+ TargetRubyVersion: 2.6
3
3
  Exclude:
4
4
  - '*.spec'
5
5
  - 'Rakefile'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v1.0.0 - 2019-05-17
2
+
3
+ - Improves testing and code coverage of existing code
4
+ - Fixes a series of minor bugs found during the writing of tests
5
+
1
6
  ## v0.1.0 - 2019-05-10
2
7
 
3
8
  - Adds code for handling member lazy load in the client abstraction, and activates it by default
data/lib/matrix_sdk.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'matrix_sdk/extensions'
2
4
  require 'matrix_sdk/version'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'matrix_sdk'
2
4
 
3
5
  require 'erb'
@@ -13,7 +15,7 @@ module MatrixSdk
13
15
  include MatrixSdk::Protocols::IS
14
16
  include MatrixSdk::Protocols::CS
15
17
 
16
- USER_AGENT = "Ruby Matrix SDK v#{MatrixSdk::VERSION}".freeze
18
+ USER_AGENT = "Ruby Matrix SDK v#{MatrixSdk::VERSION}"
17
19
  DEFAULT_HEADERS = {
18
20
  'accept' => 'application/json',
19
21
  'user-agent' => USER_AGENT
@@ -41,9 +43,11 @@ module MatrixSdk
41
43
  # @option params [Hash] :well_known The .well-known object that the server was discovered through, should not be set manually
42
44
  def initialize(homeserver, params = {})
43
45
  @homeserver = homeserver
46
+ raise ArgumentError, 'Homeserver URL must be String or URI' unless @homeserver.is_a?(String) || @homeserver.is_a?(URI)
47
+
44
48
  @homeserver = URI.parse("#{'https://' unless @homeserver.start_with? 'http'}#{@homeserver}") unless @homeserver.is_a? URI
45
49
  @homeserver.path.gsub!(/\/?_matrix\/?/, '') if @homeserver.path =~ /_matrix\/?$/
46
- raise 'Please use the base URL for your HS (without /_matrix/)' if @homeserver.path.include? '/_matrix/'
50
+ raise ArgumentError, 'Please use the base URL for your HS (without /_matrix/)' if @homeserver.path.include? '/_matrix/'
47
51
 
48
52
  @protocols = params.fetch(:protocols, %i[CS])
49
53
  @protocols = [@protocols] unless @protocols.is_a? Array
@@ -61,6 +65,7 @@ module MatrixSdk
61
65
  @well_known = params.fetch(:well_known, {})
62
66
  @global_headers = DEFAULT_HEADERS.dup
63
67
  @global_headers.merge!(params.fetch(:global_headers)) if params.key? :global_headers
68
+ @http = nil
64
69
 
65
70
  login(user: @homeserver.user, password: @homeserver.password) if @homeserver.user && @homeserver.password && !@access_token && !params[:skip_login] && protocol?(:CS)
66
71
  @homeserver.userinfo = '' unless params[:skip_login]
@@ -108,7 +113,7 @@ module MatrixSdk
108
113
  nil
109
114
  end
110
115
 
111
- target_uri = well_known['m.server'] if well_known && well_known.key?('m.server')
116
+ target_uri = well_known['m.server'] if well_known&.key?('m.server')
112
117
  else
113
118
  target_uri = URI("https://#{target_uri.target}:#{target_uri.port}")
114
119
  end
@@ -169,7 +174,7 @@ module MatrixSdk
169
174
  # TODO: DNS query for SRV information about HS?
170
175
  return unless hs_info.is_a? URI
171
176
 
172
- @http.finish if @http
177
+ @http.finish if @http && homeserver != hs_info
173
178
  @homeserver = hs_info
174
179
  end
175
180
 
@@ -264,6 +269,7 @@ module MatrixSdk
264
269
  @http.use_ssl = homeserver.scheme == 'https'
265
270
  @http.verify_mode = validate_certificate ? ::OpenSSL::SSL::VERIFY_NONE : nil
266
271
  @http.start
272
+ @http
267
273
  end
268
274
  end
269
275
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'matrix_sdk'
2
4
 
3
5
  module MatrixSdk
@@ -154,7 +156,7 @@ module MatrixSdk
154
156
  end
155
157
 
156
158
  def stop_server
157
- @server.shutdown if @server
159
+ @server&.shutdown
158
160
  @server = nil
159
161
  end
160
162
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'matrix_sdk'
2
4
 
3
5
  require 'forwardable'
@@ -73,7 +75,7 @@ module MatrixSdk
73
75
 
74
76
  def mxid
75
77
  @mxid ||= begin
76
- api.whoami?[:user_id] if api && api.access_token
78
+ api.whoami?[:user_id] if api&.access_token
77
79
  end
78
80
  end
79
81
 
@@ -96,7 +98,7 @@ module MatrixSdk
96
98
  post_authentication(data)
97
99
  end
98
100
 
99
- def register_with_password(username, password)
101
+ def register_with_password(username, password, full_state: true, **params)
100
102
  username = username.to_s unless username.is_a?(String)
101
103
  password = password.to_s unless password.is_a?(String)
102
104
 
@@ -105,6 +107,11 @@ module MatrixSdk
105
107
 
106
108
  data = api.register(auth: { type: 'm.login.dummy' }, username: username, password: password)
107
109
  post_authentication(data)
110
+
111
+ return if params[:no_sync]
112
+
113
+ sync full_state: full_state,
114
+ allow_sync_retry: params.fetch(:allow_sync_retry, nil)
108
115
  end
109
116
 
110
117
  def login(username, password, sync_timeout: 15, full_state: false, **params)
@@ -164,7 +171,7 @@ module MatrixSdk
164
171
  room_id_or_alias = MXID.new(room_id_or_alias.to_s) unless room_id_or_alias.is_a? MXID
165
172
  raise ArgumentError, 'Must be a room id or alias' unless %i[room_id room_alias].include? room_id_or_alias.type
166
173
 
167
- return @rooms.fetch(room_id_or_alias, nil) if room_id_or_alias.room_id?
174
+ return @rooms.fetch(room_id_or_alias.to_s, nil) if room_id_or_alias.room_id?
168
175
 
169
176
  return @rooms.values.find { |r| r.canonical_alias == room_id_or_alias.to_s } if only_canonical
170
177
 
@@ -216,7 +223,7 @@ module MatrixSdk
216
223
 
217
224
  attempts = 0
218
225
  data = loop do
219
- begin
226
+ begin # rubocop:disable Style/RedundantBegin
220
227
  break api.sync extra_params
221
228
  rescue MatrixSdk::MatrixTimeoutError => e
222
229
  raise e if (attempts += 1) >= params.fetch(:allow_sync_retry, 0)
@@ -239,12 +246,12 @@ module MatrixSdk
239
246
  sync(params.merge(timeout: timeout))
240
247
 
241
248
  bad_sync_timeout = orig_bad_sync_timeout
242
- sleep(sync_interval) if sync_interval > 0
249
+ sleep(sync_interval) if sync_interval.positive?
243
250
  rescue MatrixRequestError => e
244
251
  logger.warn("A #{e.class} occurred during sync")
245
252
  if e.httpstatus >= 500
246
253
  logger.warn("Serverside error, retrying in #{bad_sync_timeout} seconds...")
247
- sleep params[:bad_sync_timeout]
254
+ sleep(bad_sync_timeout) if bad_sync_timeout.positive? # rubocop:disable Metrics/BlockNesting
248
255
  bad_sync_timeout = [bad_sync_timeout * 2, @bad_sync_timeout_limit].min
249
256
  end
250
257
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MatrixSdk
2
4
  # A generic error raised for issues in the MatrixSdk
3
5
  class MatrixError < StandardError
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module URI
2
4
  class MATRIX < Generic
3
5
  def full_path
@@ -96,7 +98,7 @@ module MatrixSdk
96
98
 
97
99
  def fire(event, filter = nil)
98
100
  reverse_each do |_k, h|
99
- begin
101
+ begin # rubocop:disable Style/RedundantBegin
100
102
  h[:block].call(event) if event.matches?(h[:filter], filter)
101
103
  rescue StandardError => e
102
104
  logger.error "#{e.class.name} occurred when firing event (#{event})\n#{e}"
@@ -1,21 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MatrixSdk
2
4
  class MXID
3
5
  attr_accessor :sigil, :localpart, :domain, :port
4
6
 
5
7
  # @param identifier [String] The Matrix ID string in the format of '&<localpart>:<domain>' where '&' is the sigil
6
8
  def initialize(identifier)
7
- raise ArugmentError, 'Identifier must be a String' unless identifier.is_a? String
9
+ raise ArgumentError, 'Identifier must be a String' unless identifier.is_a? String
8
10
  raise ArgumentError, 'Identifier is too long' if identifier.size > 255
9
11
  raise ArgumentError, 'Identifier lacks required data' unless identifier =~ %r{^([@!$+#][^:]+:[^:]+(?::\d+)?)|(\$[A-Za-z0-9+/]+)$}
10
12
 
11
13
  @sigil = identifier[0]
12
14
  @localpart, @domain, @port = identifier[1..-1].split(':')
15
+ @port = @port.to_i if @port
13
16
 
14
17
  raise ArgumentError, 'Identifier is not a valid MXID' unless valid?
15
18
  end
16
19
 
17
20
  def to_s
18
- "#{sigil}#{localpart}#{domain ? ':' + domain : ''}"
21
+ port_s = port ? ':' + port.to_s : ''
22
+ "#{sigil}#{localpart}#{domain ? ':' + domain + port_s : ''}"
19
23
  end
20
24
 
21
25
  # Returns the type of the ID
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MatrixSdk::Protocols::AS
2
4
  def self.included(_klass)
3
5
  # XXX
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MatrixSdk::Protocols::CS
2
4
  # Gets the available client API versions
3
5
  # @return [Array]
@@ -5,7 +7,7 @@ module MatrixSdk::Protocols::CS
5
7
  @client_api_versions ||= request(:get, :client, '/versions').versions.tap do |vers|
6
8
  vers.instance_eval <<-'CODE', __FILE__, __LINE__ + 1
7
9
  def latest
8
- latest
10
+ last
9
11
  end
10
12
  CODE
11
13
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MatrixSdk::Protocols::IS
2
4
  def identity_status
3
5
  request(:get, :identity_api_v1, '/')
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MatrixSdk::Protocols::SS
2
4
  # Gets the server version
3
5
  def server_version
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MatrixSdk
2
4
  # An usability wrapper for API responses as an extended [Hash]
3
5
  # All results can be read as both hash keys and as read-only methods on the key
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'matrix_sdk'
2
4
 
3
5
  module MatrixSdk
@@ -306,7 +308,7 @@ module MatrixSdk
306
308
  # @return [Boolean] wether the request succeeded
307
309
  def leave
308
310
  client.api.leave_room(id)
309
- client.rooms.delete id
311
+ client.instance_variable_get(:@rooms).delete id
310
312
  true
311
313
  end
312
314
 
@@ -485,7 +487,7 @@ module MatrixSdk
485
487
  data[:events].delete_if { |_k, v| v.nil? }
486
488
  end
487
489
 
488
- client.api.set_power.levels(id, data)
490
+ client.api.set_power_levels(id, data)
489
491
  true
490
492
  end
491
493
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'matrix_sdk'
2
4
 
3
5
  module MatrixSdk
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MatrixSdk
2
- VERSION = '0.1.0'.freeze
4
+ VERSION = '1.0.0'
3
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matrix_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Olofsson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-10 00:00:00.000000000 Z
11
+ date: 2019-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logging