matrix_sdk 1.2.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7caf62bbb9e17fc9bde42dcba441902469abd8a9457e80b150861cf598fe75f
4
- data.tar.gz: 4b5ab256c15ab0d049e3116eac211c452a7f031fd1fb12ea39a7fe362cf3eb9e
3
+ metadata.gz: 44e3f36b32757df6369cafc95f4b6d9b42cff5a8b5152373519556a227aa6be4
4
+ data.tar.gz: dfdb434855b6ceea028a2f374f239aeec92504f36d52e8400d500193d0642d80
5
5
  SHA512:
6
- metadata.gz: 3c055dabe5d53ca57cd9ca26c7b3d7e1bbe0631f0e118d81bf6b076aff4172c59afd109e32b7c1ab9573a91bc0771f6d1708c17ec1e607a2754b692242b0e3d8
7
- data.tar.gz: 3ad9198ca10caca92f0a7efa8a7ac8c4362693e3be9fa140d6e1187d0f22b0fd94517714f7e1777092b9aabe82d53334d7e04c3fbc593fcd7e5917701383b7f9
6
+ metadata.gz: c5a57bafba59ce9616041f64172c4e5c117f7a46455612c8ae8c74693c691037e25dc5037be90c3d18600a3b30cdc2827761bfdcd9baea7ef5e5f6e7cbccc4cc
7
+ data.tar.gz: 99792cb46ab43e6e9d0757c5f2c171da05233d5b8d697ef1ad9d60eb2e2bdb707dca57e35b157687b6ea77ecfb955c579f72289d684699077af1f29de4ce0e54
@@ -1,3 +1,14 @@
1
+ ## 1.4.0 - 2019-09-30
2
+
3
+ - Adds the option to change the logger globally or per-object.
4
+
5
+ ## 1.3.0 - 2019-07-16
6
+
7
+ - Improves response handling to add accessors recursively
8
+ - Removes MatrixSdk extensions from the global scope,
9
+ if you've been using these in your own code you must now remember to
10
+ `extend MatrixSdk::Extensions` in order for them to be available.
11
+
1
12
  ## 1.2.1 - 2019-07-02
2
13
 
3
14
  - Fixes mxc download URL generation
@@ -39,4 +39,13 @@ module MatrixSdk
39
39
  logger.level = :info
40
40
  end
41
41
  end
42
+
43
+ def self.logger=(global_logger)
44
+ @logger = global_logger
45
+ @use_global_logger = !global_logger.nil?
46
+ end
47
+
48
+ def self.global_logger?
49
+ @use_global_logger || false
50
+ end
42
51
  end
@@ -9,6 +9,7 @@ require 'uri'
9
9
 
10
10
  module MatrixSdk
11
11
  class Api
12
+ extend MatrixSdk::Extensions
12
13
  include MatrixSdk::Logging
13
14
  include MatrixSdk::Protocols::AS
14
15
  include MatrixSdk::Protocols::CS
@@ -6,6 +6,7 @@ require 'forwardable'
6
6
 
7
7
  module MatrixSdk
8
8
  class Client
9
+ extend MatrixSdk::Extensions
9
10
  include MatrixSdk::Logging
10
11
  extend Forwardable
11
12
 
@@ -20,61 +20,69 @@ unless Object.respond_to? :yield_self
20
20
  end
21
21
  end
22
22
 
23
- def events(*symbols)
24
- module_name = "#{name}Events"
25
-
26
- initializers = []
27
- readers = []
28
- methods = []
29
-
30
- symbols.each do |sym|
31
- name = sym.to_s
32
-
33
- initializers << "
34
- @on_#{name} = MatrixSdk::EventHandlerArray.new
35
- "
36
- readers << ":on_#{name}"
37
- methods << "
38
- def fire_#{name}(ev, filter = nil)
39
- @on_#{name}.fire(ev, filter)
40
- when_#{name}(ev) if !ev.handled?
23
+ module MatrixSdk
24
+ module Extensions
25
+ def events(*symbols)
26
+ module_name = "#{name}Events"
27
+
28
+ initializers = []
29
+ readers = []
30
+ methods = []
31
+
32
+ symbols.each do |sym|
33
+ name = sym.to_s
34
+
35
+ initializers << "
36
+ @on_#{name} = MatrixSdk::EventHandlerArray.new
37
+ "
38
+ readers << ":on_#{name}"
39
+ methods << "
40
+ def fire_#{name}(ev, filter = nil)
41
+ @on_#{name}.fire(ev, filter)
42
+ when_#{name}(ev) if !ev.handled?
43
+ end
44
+
45
+ def when_#{name}(ev); end
46
+ "
41
47
  end
42
48
 
43
- def when_#{name}(ev); end
44
- "
45
- end
49
+ class_eval "
50
+ module #{module_name}
51
+ attr_reader #{readers.join ', '}
46
52
 
47
- class_eval "
48
- module #{module_name}
49
- attr_reader #{readers.join ', '}
53
+ def event_initialize
54
+ #{initializers.join}
55
+ end
50
56
 
51
- def event_initialize
52
- #{initializers.join}
53
- end
57
+ #{methods.join}
58
+ end
54
59
 
55
- #{methods.join}
60
+ include #{module_name}
61
+ ", __FILE__, __LINE__ - 12
56
62
  end
57
63
 
58
- include #{module_name}
59
- ", __FILE__, __LINE__ - 12
60
- end
61
-
62
- def ignore_inspect(*symbols)
63
- class_eval %*
64
- def inspect
65
- reentrant = caller_locations.any? { |l| l.absolute_path == __FILE__ && l.label == 'inspect' }
66
- "\#{to_s[0..-2]} \#{instance_variables
67
- .reject { |f| %i[#{symbols.map { |s| "@#{s}" }.join ' '}].include? f }
68
- .map { |f| "\#{f}=\#{reentrant ? instance_variable_get(f) : instance_variable_get(f).inspect}" }.join " " }}>"
64
+ def ignore_inspect(*symbols)
65
+ class_eval %*
66
+ def inspect
67
+ reentrant = caller_locations.any? { |l| l.absolute_path == __FILE__ && l.label == 'inspect' }
68
+ "\#{to_s[0..-2]} \#{instance_variables
69
+ .reject { |f| %i[#{symbols.map { |s| "@#{s}" }.join ' '}].include? f }
70
+ .map { |f| "\#{f}=\#{reentrant ? instance_variable_get(f) : instance_variable_get(f).inspect}" }.join " " }}>"
71
+ end
72
+ *, __FILE__, __LINE__ - 7
69
73
  end
70
- *, __FILE__, __LINE__ - 7
71
- end
74
+ end
72
75
 
73
- module MatrixSdk
74
76
  module Logging
75
77
  def logger
78
+ return MatrixSdk.logger if MatrixSdk.global_logger?
79
+
76
80
  @logger ||= ::Logging.logger[self]
77
81
  end
82
+
83
+ def logger=(logger)
84
+ @logger = logger
85
+ end
78
86
  end
79
87
 
80
88
  class EventHandlerArray < Hash
@@ -110,6 +118,8 @@ module MatrixSdk
110
118
  end
111
119
 
112
120
  class Event
121
+ extend MatrixSdk::Extensions
122
+
113
123
  attr_writer :handled
114
124
 
115
125
  ignore_inspect :sender
@@ -1009,6 +1009,10 @@ module MatrixSdk::Protocols::CS
1009
1009
  request(:get, :client_r0, "/user/#{user_id}/filter/#{filter_id}", query: query)
1010
1010
  end
1011
1011
 
1012
+ # Creates a filter for future use
1013
+ #
1014
+ # @param [String,MXID] user_id The user to create the filter for
1015
+ # @param [Hash] filter_params The filter to create
1012
1016
  def create_filter(user_id, filter_params, **params)
1013
1017
  query = {}
1014
1018
  query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
@@ -1069,6 +1073,14 @@ module MatrixSdk::Protocols::CS
1069
1073
  request(:put, :client_r0, "/profile/#{user_id}/avatar_url", body: content, query: query)
1070
1074
  end
1071
1075
 
1076
+ # Gets the combined profile object of a user.
1077
+ #
1078
+ # This includes their display name and avatar
1079
+ #
1080
+ # @param [String,MXID] user_id The User ID to read the profile for
1081
+ # @return [Response] The user profile object
1082
+ # @see #get_display_name
1083
+ # @see #get_avatar_url
1072
1084
  def get_profile(user_id, **params)
1073
1085
  query = {}
1074
1086
  query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
@@ -24,6 +24,10 @@ module MatrixSdk
24
24
  def self.new(api, data)
25
25
  data.extend(Extensions)
26
26
  data.instance_variable_set(:@api, api)
27
+
28
+ data.select { |_k, v| v.is_a? Hash }
29
+ .each { |_v, v| Response.new api, v }
30
+
27
31
  data
28
32
  end
29
33
 
@@ -5,6 +5,7 @@ require 'matrix_sdk'
5
5
  module MatrixSdk
6
6
  # A class for tracking the information about a room on Matrix
7
7
  class Room
8
+ extend MatrixSdk::Extensions
8
9
  include MatrixSdk::Logging
9
10
 
10
11
  # @!attribute [rw] canonical_alias
@@ -5,6 +5,8 @@ require 'matrix_sdk'
5
5
  module MatrixSdk
6
6
  # A class for tracking information about a user on Matrix
7
7
  class User
8
+ extend MatrixSdk::Extensions
9
+
8
10
  # @!attribute [r] id
9
11
  # @return [String] the MXID of the user
10
12
  # @!attribute [r] client
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MatrixSdk
4
- VERSION = '1.2.1'
4
+ VERSION = '1.4.0'
5
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: 1.2.1
4
+ version: 1.4.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-07-02 00:00:00.000000000 Z
11
+ date: 2019-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mocha
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  - !ruby/object:Gem::Version
128
128
  version: '0'
129
129
  requirements: []
130
- rubygems_version: 3.0.3
130
+ rubygems_version: 3.0.6
131
131
  signing_key:
132
132
  specification_version: 4
133
133
  summary: SDK for applications using the Matrix protocol