matrix_sdk 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +39 -0
- data/README.md +27 -2
- data/examples/simple_client.rb +93 -0
- data/lib/matrix_sdk/api.rb +402 -31
- data/lib/matrix_sdk/client.rb +234 -0
- data/lib/matrix_sdk/errors.rb +21 -5
- data/lib/matrix_sdk/extensions.rb +119 -0
- data/lib/matrix_sdk/room.rb +471 -0
- data/lib/matrix_sdk/user.rb +49 -0
- data/lib/matrix_sdk/version.rb +1 -1
- data/lib/matrix_sdk.rb +24 -2
- data/matrix-sdk.gemspec +9 -7
- metadata +27 -8
@@ -0,0 +1,471 @@
|
|
1
|
+
require 'matrix_sdk'
|
2
|
+
|
3
|
+
module MatrixSdk
|
4
|
+
# A class for tracking the information about a room on Matrix
|
5
|
+
class Room
|
6
|
+
# @!attribute [rw] canonical_alias
|
7
|
+
# @return [String, nil] the canonical alias of the room
|
8
|
+
# @!attribute [rw] event_history_limit
|
9
|
+
# @return [Fixnum] the limit of events to keep in the event log
|
10
|
+
attr_accessor :canonical_alias, :event_history_limit
|
11
|
+
# @!attribute [r] id
|
12
|
+
# @return [String] the internal ID of the room
|
13
|
+
# @!attribute [r] client
|
14
|
+
# @return [Client] the client for the room
|
15
|
+
# @!attribute [rw] name
|
16
|
+
# @return [String, nil] the user-provided name of the room
|
17
|
+
# @see reload_name!
|
18
|
+
# @!attribute [rw] topic
|
19
|
+
# @return [String, nil] the user-provided topic of the room
|
20
|
+
# @see reload_topic!
|
21
|
+
# @!attribute [r] aliases
|
22
|
+
# @return [Array(String)] a list of user-set aliases for the room
|
23
|
+
# @see add_alias
|
24
|
+
# @see reload_alias!
|
25
|
+
# @!attribute [rw] join_rule
|
26
|
+
# @return [:invite, :public] the join rule for the room -
|
27
|
+
# either +:invite+ or +:public+
|
28
|
+
# @!attribute [rw] guest_access
|
29
|
+
# @return [:can_join, :forbidden] the guest access for the room -
|
30
|
+
# either +:can_join+ or +:forbidden+
|
31
|
+
# @!attribute [r] members
|
32
|
+
# @return [Array(User)] the members of the room
|
33
|
+
# @see reload_members!
|
34
|
+
# @!attribute [r] events
|
35
|
+
# @return [Array(Object)] the last +event_history_limit+ events to arrive in the room
|
36
|
+
# @see https://matrix.org/docs/spec/client_server/r0.3.0.html#get-matrix-client-r0-sync
|
37
|
+
# The timeline events are what will end up in here
|
38
|
+
attr_reader :id, :client, :name, :topic, :aliases, :join_rule, :guest_access, :members, :events
|
39
|
+
|
40
|
+
# @!attribute [r] on_event
|
41
|
+
# @return [EventHandlerArray] The list of event handlers for all events
|
42
|
+
# @!attribute [r] on_state_event
|
43
|
+
# @return [EventHandlerArray] The list of event handlers for only state events
|
44
|
+
# @!attribute [r] on_ephemeral_event
|
45
|
+
# @return [EventHandlerArray] The list of event handlers for only ephemeral events
|
46
|
+
events :event, :state_event, :ephemeral_event
|
47
|
+
# @!method inspect
|
48
|
+
# An inspect method that skips a handful of instance variables to avoid
|
49
|
+
# flooding the terminal with debug data.
|
50
|
+
# @return [String] a regular inspect string without the data for some variables
|
51
|
+
ignore_inspect :client, :members, :events, :prev_batch,
|
52
|
+
:on_event, :on_state_event, :on_ephemeral_event
|
53
|
+
|
54
|
+
alias room_id id
|
55
|
+
|
56
|
+
def initialize(client, room_id, data = {})
|
57
|
+
event_initialize
|
58
|
+
@client = client
|
59
|
+
@id = room_id.to_s
|
60
|
+
|
61
|
+
@name = nil
|
62
|
+
@topic = nil
|
63
|
+
@canonical_alias = nil
|
64
|
+
@aliases = []
|
65
|
+
@join_rule = nil
|
66
|
+
@guest_access = nil
|
67
|
+
@members = []
|
68
|
+
@events = []
|
69
|
+
@event_history_limit = 10
|
70
|
+
|
71
|
+
@prev_batch = nil
|
72
|
+
|
73
|
+
data.each do |k, v|
|
74
|
+
instance_variable_set("@#{k}", v) if instance_variable_defined? "@#{k}"
|
75
|
+
end
|
76
|
+
|
77
|
+
logger.debug "Created room #{room_id}"
|
78
|
+
end
|
79
|
+
|
80
|
+
def logger
|
81
|
+
Logging.logger[self.class.name]
|
82
|
+
end
|
83
|
+
|
84
|
+
#
|
85
|
+
# State readers
|
86
|
+
#
|
87
|
+
|
88
|
+
# Gets a human-readable name for the room
|
89
|
+
#
|
90
|
+
# This will return #name or #canonical_alias if they've been set,
|
91
|
+
# otherwise it will query the API for members and generate a string from
|
92
|
+
# a subset of their names.
|
93
|
+
#
|
94
|
+
# @return [String] a human-readable name for the room
|
95
|
+
# @note This method will populate the #members list if it has to fall back
|
96
|
+
# to the member name generation.
|
97
|
+
def display_name
|
98
|
+
return name if name
|
99
|
+
return canonical_alias if canonical_alias
|
100
|
+
|
101
|
+
members = joined_members
|
102
|
+
.reject { |m| m.user_id == client.mxid }
|
103
|
+
.map(&:get_display_name)
|
104
|
+
|
105
|
+
return members.first if members.one?
|
106
|
+
return "#{members.first} and #{members.last}" if members.count == 2
|
107
|
+
return "#{members.first} and #{members.count - 1} others" if members.count > 2
|
108
|
+
|
109
|
+
'Empty Room'
|
110
|
+
end
|
111
|
+
|
112
|
+
# Populates and returns the #members array
|
113
|
+
def joined_members
|
114
|
+
return members unless members.empty?
|
115
|
+
|
116
|
+
client.api.get_room_members(id)[:chunk].each do |chunk|
|
117
|
+
next unless chunk [:content][:membership] == 'join'
|
118
|
+
ensure_member(User.new(client, chunk[:state_key], display_name: chunk[:content].fetch(:displayname)))
|
119
|
+
end
|
120
|
+
members
|
121
|
+
end
|
122
|
+
|
123
|
+
# Checks if +guest_access+ is set to +:can_join+
|
124
|
+
def guest_access?
|
125
|
+
guest_access == :can_join
|
126
|
+
end
|
127
|
+
|
128
|
+
# Checks if +join_rule+ is set to +:invite+
|
129
|
+
def invite_only?
|
130
|
+
join_rule == :invite
|
131
|
+
end
|
132
|
+
|
133
|
+
#
|
134
|
+
# Message handling
|
135
|
+
#
|
136
|
+
|
137
|
+
# Sends a plain-text message to the room
|
138
|
+
# @param text [String] the message to send
|
139
|
+
def send_text(text)
|
140
|
+
client.api.send_message(id, text)
|
141
|
+
end
|
142
|
+
|
143
|
+
# Sends a custom HTML message to the room
|
144
|
+
# @param html [String] the HTML message to send
|
145
|
+
# @param body [String,nil] a plain-text representation of the object
|
146
|
+
# (Will default to the HTML with tags stripped away)
|
147
|
+
# @param msg_type [String] A message type for the message
|
148
|
+
# @see https://matrix.org/docs/spec/client_server/r0.3.0.html#m-room-message-msgtypes
|
149
|
+
# Possible message types as defined by the spec
|
150
|
+
def send_html(html, body = nil, msg_type = 'm.text')
|
151
|
+
content = {
|
152
|
+
body: body ? body : html.gsub(/<\/?[^>]*>/, ''),
|
153
|
+
msgtype: msg_type,
|
154
|
+
format: 'org.matrix.custom.html',
|
155
|
+
formatted_body: html
|
156
|
+
}
|
157
|
+
|
158
|
+
client.api.send_message_event(id, 'm.room.message', content)
|
159
|
+
end
|
160
|
+
|
161
|
+
# Sends an emote (/me) message to the room
|
162
|
+
# @param text [String] the emote to send
|
163
|
+
def send_emote(text)
|
164
|
+
client.api.send_emote(id, text)
|
165
|
+
end
|
166
|
+
|
167
|
+
# Sends a link to a generic file to the room
|
168
|
+
# @param url [String,URI] the URL to the file
|
169
|
+
# @param name [String] the name of the file
|
170
|
+
# @param file_info [Hash] extra information about the file
|
171
|
+
# @option file_info [String] :mimetype the MIME type of the file
|
172
|
+
# @option file_info [Integer] :size the size of the file in bytes
|
173
|
+
# @option file_info [String,URI] :thumbnail_url the URL to a thumbnail of the file
|
174
|
+
# @option file_info [Hash] :thumbnail_info ThumbnailInfo about the thumbnail file
|
175
|
+
# @note The URLs should all be of the 'mxc://' schema
|
176
|
+
def send_file(url, name, file_info = {})
|
177
|
+
client.api.send_content(id, url, name, 'm.file', extra_information: file_info)
|
178
|
+
end
|
179
|
+
|
180
|
+
# Sends a notice (bot) message to the room
|
181
|
+
# @param text [String] the notice to send
|
182
|
+
def send_notice(text)
|
183
|
+
client.api.send_notice(id, text)
|
184
|
+
end
|
185
|
+
|
186
|
+
# Sends a link to an image to the room
|
187
|
+
# @param url [String,URI] the URL to the image
|
188
|
+
# @param name [String] the name of the image
|
189
|
+
# @param image_info [Hash] extra information about the image
|
190
|
+
# @option image_info [Integer] :h the height of the image in pixels
|
191
|
+
# @option image_info [Integer] :w the width of the image in pixels
|
192
|
+
# @option image_info [String] :mimetype the MIME type of the image
|
193
|
+
# @option image_info [Integer] :size the size of the image in bytes
|
194
|
+
# @option image_info [String,URI] :thumbnail_url the URL to a thumbnail of the image
|
195
|
+
# @option image_info [Hash] :thumbnail_info ThumbnailInfo about the thumbnail image
|
196
|
+
# @note The URLs should all be of the 'mxc://' schema
|
197
|
+
def send_image(url, name, image_info = {})
|
198
|
+
client.api.send_content(id, url, name, 'm.image', extra_information: image_info)
|
199
|
+
end
|
200
|
+
|
201
|
+
# Sends a location object to the room
|
202
|
+
# @param geo_uri [String,URI] the geo-URL (e.g. geo:<coords>) of the location
|
203
|
+
# @param name [String] the name of the location
|
204
|
+
# @param thumbnail_url [String,URI] the URL to a thumbnail image of the location
|
205
|
+
# @param thumbnail_info [Hash] a ThumbnailInfo for the location thumbnail
|
206
|
+
# @note The thumbnail URL should be of the 'mxc://' schema
|
207
|
+
def send_location(geo_uri, name, thumbnail_url = nil, thumbnail_info = {})
|
208
|
+
client.api.send_location(id, geo_uri, name, thumbnail_url: thumbnail_url, thumbnail_info: thumbnail_info)
|
209
|
+
end
|
210
|
+
|
211
|
+
# Sends a link to a video to the room
|
212
|
+
# @param url [String,URI] the URL to the video
|
213
|
+
# @param name [String] the name of the video
|
214
|
+
# @param video_info [Hash] extra information about the video
|
215
|
+
# @option video_info [Integer] :duration the duration of the video in milliseconds
|
216
|
+
# @option video_info [Integer] :h the height of the video in pixels
|
217
|
+
# @option video_info [Integer] :w the width of the video in pixels
|
218
|
+
# @option video_info [String] :mimetype the MIME type of the video
|
219
|
+
# @option video_info [Integer] :size the size of the video in bytes
|
220
|
+
# @option video_info [String,URI] :thumbnail_url the URL to a thumbnail of the video
|
221
|
+
# @option video_info [Hash] :thumbnail_info ThumbnailInfo about the thumbnail of the video
|
222
|
+
# @note The URLs should all be of the 'mxc://' schema
|
223
|
+
def send_video(url, name, video_info = {})
|
224
|
+
client.api.send_content(id, url, name, 'm.video', extra_information: video_info)
|
225
|
+
end
|
226
|
+
|
227
|
+
# Sends a link to an audio clip to the room
|
228
|
+
# @param url [String,URI] the URL to the audio clip
|
229
|
+
# @param name [String] the name of the audio clip
|
230
|
+
# @param audio_info [Hash] extra information about the audio clip
|
231
|
+
# @option audio_info [Integer] :duration the duration of the audio clip in milliseconds
|
232
|
+
# @option audio_info [String] :mimetype the MIME type of the audio clip
|
233
|
+
# @option audio_info [Integer] :size the size of the audio clip in bytes
|
234
|
+
# @note The URLs should all be of the 'mxc://' schema
|
235
|
+
def send_audio(url, name, audio_info = {})
|
236
|
+
client.api.send_content(id, url, name, 'm.audio', extra_information: audio_info)
|
237
|
+
end
|
238
|
+
|
239
|
+
# Redacts a message from the room
|
240
|
+
# @param event_id [String] the ID of the event to redact
|
241
|
+
# @param reason [String,nil] the reason for the redaction
|
242
|
+
def redact_message(event_id, reason = nil)
|
243
|
+
client.api.redact_event(id, event_id, reason: reason)
|
244
|
+
end
|
245
|
+
|
246
|
+
# Backfills messages into the room history
|
247
|
+
# @param reverse [Boolean] whether to fill messages in reverse or not
|
248
|
+
# @param limit [Integer] the maximum number of messages to backfill
|
249
|
+
# @note This will trigger the `on_event` events as messages are added
|
250
|
+
def backfill_messages(reverse = false, limit = 10)
|
251
|
+
data = client.api.get_room_messages(id, @prev_batch, direction: :b, limit: limit)
|
252
|
+
|
253
|
+
events = data[:chunk]
|
254
|
+
events.reverse! unless reverse
|
255
|
+
events.each do |ev|
|
256
|
+
put_event(ev)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
#
|
261
|
+
# User Management
|
262
|
+
#
|
263
|
+
|
264
|
+
def invite_user(user_id)
|
265
|
+
client.api.invite_user(id, user_id)
|
266
|
+
true
|
267
|
+
rescue MatrixError
|
268
|
+
false
|
269
|
+
end
|
270
|
+
|
271
|
+
def kick_user(user_id, reason = '')
|
272
|
+
client.api.kick_user(id, user_id, reason: reason)
|
273
|
+
true
|
274
|
+
rescue MatrixError
|
275
|
+
false
|
276
|
+
end
|
277
|
+
|
278
|
+
def ban_user(user_id, reason = '')
|
279
|
+
client.api.ban_user(id, user_id, reason: reason)
|
280
|
+
true
|
281
|
+
rescue MatrixError
|
282
|
+
false
|
283
|
+
end
|
284
|
+
|
285
|
+
def unban_user(user_id)
|
286
|
+
client.api.unban_user(id, user_id)
|
287
|
+
true
|
288
|
+
rescue MatrixError
|
289
|
+
false
|
290
|
+
end
|
291
|
+
|
292
|
+
def leave
|
293
|
+
client.api.leave_room(id)
|
294
|
+
client.rooms.delete id
|
295
|
+
true
|
296
|
+
rescue MatrixError
|
297
|
+
false
|
298
|
+
end
|
299
|
+
|
300
|
+
def get_account_data(type)
|
301
|
+
client.api.get_room_account_data(client.mxid, id, type)
|
302
|
+
end
|
303
|
+
|
304
|
+
def set_account_data(type, account_data)
|
305
|
+
client.api.set_room_account_data(client.mxid, id, type, account_data)
|
306
|
+
end
|
307
|
+
|
308
|
+
def set_user_profile(params = {})
|
309
|
+
return nil unless params[:display_name] || params[:avatar_url]
|
310
|
+
data = client.api.get_membership(id, client.mxid)
|
311
|
+
raise "Can't set profile if you haven't joined the room" unless data[:membership] == 'join'
|
312
|
+
|
313
|
+
data[:displayname] = params[:display_name] unless params[:display_name].nil?
|
314
|
+
data[:avatar_url] = params[:avatar_url] unless params[:avatar_url].nil?
|
315
|
+
|
316
|
+
client.api.set_membership(id, client.mxid, 'join', params.fetch(:reason, 'Updating room profile information'), data)
|
317
|
+
end
|
318
|
+
|
319
|
+
def tags
|
320
|
+
client.api.get_user_tags(client.mxid, id)
|
321
|
+
end
|
322
|
+
|
323
|
+
def remove_tag(tag)
|
324
|
+
client.api.remove_user_tag(client.mxid, id, tag)
|
325
|
+
end
|
326
|
+
|
327
|
+
def add_tag(tag, params = {})
|
328
|
+
client.api.add_user_tag(client.mxid, id, tag, params)
|
329
|
+
end
|
330
|
+
|
331
|
+
#
|
332
|
+
# State updates
|
333
|
+
#
|
334
|
+
|
335
|
+
def name=(name)
|
336
|
+
client.api.set_room_name(id, name)
|
337
|
+
@name = name
|
338
|
+
rescue MatrixError
|
339
|
+
nil
|
340
|
+
end
|
341
|
+
|
342
|
+
def reload_name!
|
343
|
+
data = client.api.get_room_name(id)
|
344
|
+
changed = data[:name] != name
|
345
|
+
@name = data[:name] if changed
|
346
|
+
changed
|
347
|
+
rescue MatrixError
|
348
|
+
false
|
349
|
+
end
|
350
|
+
|
351
|
+
def topic=(topic)
|
352
|
+
client.api.set_room_topic(id, topic)
|
353
|
+
@topic = topic
|
354
|
+
rescue MatrixError
|
355
|
+
nil
|
356
|
+
end
|
357
|
+
|
358
|
+
def reload_topic!
|
359
|
+
data = client.api.get_room_topic(id)
|
360
|
+
changed = data[:topic] != topic
|
361
|
+
@topic = data[:topic] if changed
|
362
|
+
changed
|
363
|
+
rescue MatrixError
|
364
|
+
false
|
365
|
+
end
|
366
|
+
|
367
|
+
# Add an alias to the room
|
368
|
+
# @return [Boolean] if the addition was successful or not
|
369
|
+
def add_alias(room_alias)
|
370
|
+
client.api.set_room_alias(id, room_alias)
|
371
|
+
@aliases << room_alias
|
372
|
+
true
|
373
|
+
rescue MatrixError
|
374
|
+
false
|
375
|
+
end
|
376
|
+
|
377
|
+
# Reloads the list of aliases by an API query
|
378
|
+
# @return [Boolean] if the alias list was updated or not
|
379
|
+
# @note The list of aliases is not sorted, ordering changes will result in
|
380
|
+
# alias list updates.
|
381
|
+
def reload_aliases!
|
382
|
+
data = client.api.get_room_state(id)
|
383
|
+
new_aliases = data.select { |chunk| chunk.key?(:content) && chunk[:content].key?(:aliases) }
|
384
|
+
.map { |chunk| chunk[:content][:aliases] }
|
385
|
+
.flatten
|
386
|
+
.reject(&:nil?)
|
387
|
+
return false if new_aliases.nil?
|
388
|
+
|
389
|
+
changed = new_aliases != aliases
|
390
|
+
@aliases = new_aliases if changed
|
391
|
+
changed
|
392
|
+
rescue MatrixError
|
393
|
+
false
|
394
|
+
end
|
395
|
+
|
396
|
+
def invite_only=(invite_only)
|
397
|
+
self.join_rule = invite_only ? :invite : :public
|
398
|
+
@join_rule == :invite # rubocop:disable Lint/Void
|
399
|
+
end
|
400
|
+
|
401
|
+
def join_rule=(join_rule)
|
402
|
+
client.api.set_join_rule(id, join_rule)
|
403
|
+
@join_rule = join_rule
|
404
|
+
rescue MatrixError
|
405
|
+
nil
|
406
|
+
end
|
407
|
+
|
408
|
+
def allow_guests=(allow_guests)
|
409
|
+
self.guest_access = (allow_guests ? :can_join : :forbidden)
|
410
|
+
@guest_access == :can_join # rubocop:disable Lint/Void
|
411
|
+
end
|
412
|
+
|
413
|
+
def guest_access=(guest_access)
|
414
|
+
client.api.set_guest_access(id, guest_access)
|
415
|
+
@guest_access = guest_access
|
416
|
+
rescue MatrixError
|
417
|
+
nil
|
418
|
+
end
|
419
|
+
|
420
|
+
def modify_user_power_levels(users = nil, users_default = nil)
|
421
|
+
return false if users.nil? && users_default.nil?
|
422
|
+
data = client.api.get_power_levels(id)
|
423
|
+
data[:users_default] = users_default unless users_default.nil?
|
424
|
+
|
425
|
+
if users
|
426
|
+
data[:users] = {} unless data.key? :users
|
427
|
+
data[:users].merge!(users)
|
428
|
+
data[:users].delete_if { |_k, v| v.nil? }
|
429
|
+
end
|
430
|
+
|
431
|
+
client.api.set_power_levels(id, data)
|
432
|
+
true
|
433
|
+
rescue MatrixError
|
434
|
+
false
|
435
|
+
end
|
436
|
+
|
437
|
+
def modify_required_power_levels(events = nil, params = {})
|
438
|
+
return false if events.nil? && (params.nil? || params.empty?)
|
439
|
+
data = client.api.get_power_levels(id)
|
440
|
+
data.merge!(params)
|
441
|
+
data.delete_if { |_k, v| v.nil? }
|
442
|
+
|
443
|
+
if events
|
444
|
+
data[:events] = {} unless data.key? :events
|
445
|
+
data[:events].merge!(events)
|
446
|
+
data[:events].delete_if { |_k, v| v.nil? }
|
447
|
+
end
|
448
|
+
|
449
|
+
client.api.set_power.levels(id, data)
|
450
|
+
rescue MatrixError
|
451
|
+
false
|
452
|
+
end
|
453
|
+
|
454
|
+
private
|
455
|
+
|
456
|
+
def ensure_member(member)
|
457
|
+
members << member unless members.any? { |m| m.id == member.id }
|
458
|
+
end
|
459
|
+
|
460
|
+
def put_event(event)
|
461
|
+
@events.push event
|
462
|
+
@events.shift if @events.length > @event_history_limit
|
463
|
+
|
464
|
+
fire_event MatrixEvent.new(self, event)
|
465
|
+
end
|
466
|
+
|
467
|
+
def put_ephemeral_event(event)
|
468
|
+
fire_ephemeral_event MatrixEvent.new(self, event)
|
469
|
+
end
|
470
|
+
end
|
471
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'matrix_sdk'
|
2
|
+
|
3
|
+
module MatrixSdk
|
4
|
+
# A class for tracking information about a user on Matrix
|
5
|
+
class User
|
6
|
+
attr_reader :id, :client
|
7
|
+
alias user_id :id
|
8
|
+
|
9
|
+
ignore_inspect :client
|
10
|
+
|
11
|
+
def initialize(client, id, data = {})
|
12
|
+
@client = client
|
13
|
+
@id = id
|
14
|
+
|
15
|
+
@display_name = nil
|
16
|
+
@avatar_url = nil
|
17
|
+
|
18
|
+
data.each do |k, v|
|
19
|
+
instance_variable_set("@#{k}", v) if instance_variable_defined? "@#{k}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def display_name
|
24
|
+
@display_name ||= client.api.get_display_name(id)[:displayname]
|
25
|
+
end
|
26
|
+
|
27
|
+
def display_name=(name)
|
28
|
+
client.api.set_display_name(id, name)
|
29
|
+
@display_name = name
|
30
|
+
rescue MatrixError
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def friendly_name
|
35
|
+
display_name || id
|
36
|
+
end
|
37
|
+
|
38
|
+
def avatar_url
|
39
|
+
@avatar_url ||= client.api.get_avatar_url(id)[:avatar_url]
|
40
|
+
end
|
41
|
+
|
42
|
+
def avatar_url=(url)
|
43
|
+
client.api.set_avatar_url(id, url)
|
44
|
+
@avatar_url = url
|
45
|
+
rescue MatrixError
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/matrix_sdk/version.rb
CHANGED
data/lib/matrix_sdk.rb
CHANGED
@@ -1,5 +1,27 @@
|
|
1
|
-
require
|
1
|
+
require 'matrix_sdk/extensions'
|
2
|
+
require 'matrix_sdk/version'
|
3
|
+
|
4
|
+
autoload :Logging, 'logging'
|
2
5
|
|
3
6
|
module MatrixSdk
|
4
|
-
|
7
|
+
autoload :Api, 'matrix_sdk/api'
|
8
|
+
autoload :Client, 'matrix_sdk/client'
|
9
|
+
autoload :Room, 'matrix_sdk/room'
|
10
|
+
autoload :User, 'matrix_sdk/user'
|
11
|
+
|
12
|
+
autoload :MatrixError, 'matrix_sdk/errors'
|
13
|
+
autoload :MatrixRequestError, 'matrix_sdk/errors'
|
14
|
+
autoload :MatrixConnectionError, 'matrix_sdk/errors'
|
15
|
+
autoload :MatrixUnexpectedResponseError, 'matrix_sdk/errors'
|
16
|
+
|
17
|
+
def self.debug!
|
18
|
+
logger.level = :debug
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.logger
|
22
|
+
@logger ||= Logging.logger[name].tap do |logger|
|
23
|
+
logger.add_appenders Logging.appenders.stdout
|
24
|
+
logger.level = :warn
|
25
|
+
end
|
26
|
+
end
|
5
27
|
end
|
data/matrix-sdk.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require File.join File.expand_path('lib', __dir__), 'matrix_sdk/version'
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
|
-
spec.name =
|
4
|
+
spec.name = 'matrix_sdk'
|
5
5
|
spec.version = MatrixSdk::VERSION
|
6
|
-
spec.authors = [
|
7
|
-
spec.email = [
|
6
|
+
spec.authors = ['Alexander Olofsson']
|
7
|
+
spec.email = ['ace@haxalot.com']
|
8
8
|
|
9
9
|
spec.summary = ''
|
10
10
|
spec.description = ''
|
@@ -14,9 +14,11 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
15
15
|
f.match(%r{^(test|spec|features)/})
|
16
16
|
end
|
17
|
-
spec.require_paths = [
|
17
|
+
spec.require_paths = ['lib']
|
18
18
|
|
19
|
-
spec.
|
20
|
-
|
21
|
-
spec.add_development_dependency
|
19
|
+
spec.add_dependency 'logging', '~> 2'
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
22
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
22
24
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matrix_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Olofsson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: logging
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -25,33 +39,33 @@ dependencies:
|
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '1.14'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
42
|
+
name: minitest
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '5.0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '5.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '10.0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '10.0'
|
55
69
|
description: ''
|
56
70
|
email:
|
57
71
|
- ace@haxalot.com
|
@@ -60,15 +74,20 @@ extensions: []
|
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
62
76
|
- ".gitignore"
|
77
|
+
- ".rubocop.yml"
|
63
78
|
- ".travis.yml"
|
64
79
|
- Gemfile
|
65
80
|
- LICENSE.txt
|
66
81
|
- README.md
|
67
82
|
- Rakefile
|
83
|
+
- examples/simple_client.rb
|
68
84
|
- lib/matrix_sdk.rb
|
69
85
|
- lib/matrix_sdk/api.rb
|
70
86
|
- lib/matrix_sdk/client.rb
|
71
87
|
- lib/matrix_sdk/errors.rb
|
88
|
+
- lib/matrix_sdk/extensions.rb
|
89
|
+
- lib/matrix_sdk/room.rb
|
90
|
+
- lib/matrix_sdk/user.rb
|
72
91
|
- lib/matrix_sdk/version.rb
|
73
92
|
- matrix-sdk.gemspec
|
74
93
|
homepage: https://github.com/ananace/ruby_matrix_sdk
|