chatrix 1.0.0 → 1.1.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 +4 -4
- data/.rubocop.yml +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -1
- data/Rakefile +3 -0
- data/bin/console +2 -0
- data/chatrix.gemspec +4 -0
- data/lib/chatrix.rb +3 -0
- data/lib/chatrix/api/api_component.rb +4 -0
- data/lib/chatrix/api/media.rb +3 -0
- data/lib/chatrix/api/push.rb +3 -0
- data/lib/chatrix/api/room_actions.rb +3 -0
- data/lib/chatrix/api/rooms.rb +3 -0
- data/lib/chatrix/api/session.rb +3 -0
- data/lib/chatrix/api/users.rb +4 -0
- data/lib/chatrix/client.rb +4 -2
- data/lib/chatrix/components/admin.rb +3 -0
- data/lib/chatrix/components/messaging.rb +3 -0
- data/lib/chatrix/components/permissions.rb +3 -0
- data/lib/chatrix/components/state.rb +28 -20
- data/lib/chatrix/components/timeline.rb +7 -1
- data/lib/chatrix/errors.rb +4 -1
- data/lib/chatrix/events.rb +3 -0
- data/lib/chatrix/matrix.rb +4 -1
- data/lib/chatrix/message.rb +24 -13
- data/lib/chatrix/room.rb +18 -8
- data/lib/chatrix/rooms.rb +3 -0
- data/lib/chatrix/user.rb +12 -8
- data/lib/chatrix/users.rb +3 -0
- data/lib/chatrix/version.rb +4 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c4ccf55e9b611ac9df88a62fbc8e1924815abf3
|
4
|
+
data.tar.gz: cb828784148992194d31f5771a7a653c07b9fa24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ce6a0c0835155c222cebaf4f4621f544f343c067fd60db25b250f1210fa2cf09082f7916a6de15e3fe47ab78987020f5037462f74747c45bd177c4bccad0cd0
|
7
|
+
data.tar.gz: f0d9572000576c1085f211807e3eac8063fa4f4f88e5fadc936230b5b454440a416bd0f8f8b24ae1205506d9e0694baa06cc20fce745654dd19a89c80f3dc0cb
|
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
source 'https://rubygems.org'
|
2
5
|
|
3
6
|
# Specify your gem's dependencies in ratrix.gemspec
|
@@ -14,7 +17,7 @@ group :test do
|
|
14
17
|
end
|
15
18
|
|
16
19
|
group :development, :test do
|
17
|
-
gem 'rubocop', '~> 0.
|
20
|
+
gem 'rubocop', '~> 0.41.0'
|
18
21
|
end
|
19
22
|
|
20
23
|
group :doc do
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/chatrix.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
lib = File.expand_path('../lib', __FILE__)
|
3
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
6
|
require 'chatrix/version'
|
@@ -22,6 +24,8 @@ Gem::Specification.new do |spec|
|
|
22
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
25
|
spec.require_paths = ['lib']
|
24
26
|
|
27
|
+
spec.required_ruby_version = '>= 2.0.0'
|
28
|
+
|
25
29
|
spec.add_runtime_dependency 'httparty', '~> 0.13'
|
26
30
|
spec.add_runtime_dependency 'wisper', '~> 1.6'
|
27
31
|
|
data/lib/chatrix.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
module Chatrix
|
2
5
|
module Api
|
3
6
|
# Wraps a matrix instance for use in calling API endpoints.
|
4
7
|
class ApiComponent
|
5
8
|
# Initializes a new ApiComponent instance.
|
9
|
+
# @param matrix [Matrix] The matrix API instance.
|
6
10
|
def initialize(matrix)
|
7
11
|
@matrix = matrix
|
8
12
|
end
|
data/lib/chatrix/api/media.rb
CHANGED
data/lib/chatrix/api/push.rb
CHANGED
data/lib/chatrix/api/rooms.rb
CHANGED
data/lib/chatrix/api/session.rb
CHANGED
data/lib/chatrix/api/users.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
require 'chatrix/api/api_component'
|
2
5
|
|
3
6
|
module Chatrix
|
@@ -49,6 +52,7 @@ module Chatrix
|
|
49
52
|
#
|
50
53
|
# @param (see #get_user)
|
51
54
|
# @raise (see #get_user)
|
55
|
+
# @return [String] The user's display name.
|
52
56
|
def get_displayname(user)
|
53
57
|
make_request(:get, "/profile/#{user}/displayname")['displayname']
|
54
58
|
rescue NotFoundError => e
|
data/lib/chatrix/client.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
require 'chatrix/matrix'
|
2
5
|
require 'chatrix/users'
|
3
6
|
require 'chatrix/rooms'
|
@@ -9,8 +12,7 @@ module Chatrix
|
|
9
12
|
class Client
|
10
13
|
include Wisper::Publisher
|
11
14
|
|
12
|
-
#
|
13
|
-
# @return [User] The user associated with the access token.
|
15
|
+
# @return [User] The user associated with the access token.
|
14
16
|
attr_reader :me
|
15
17
|
|
16
18
|
# Initializes a new Client instance.
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
require 'chatrix/events'
|
2
5
|
|
3
6
|
require 'chatrix/components/permissions'
|
@@ -11,26 +14,31 @@ module Chatrix
|
|
11
14
|
class State
|
12
15
|
include Wisper::Publisher
|
13
16
|
|
14
|
-
#
|
15
|
-
#
|
16
|
-
|
17
|
-
|
18
|
-
#
|
19
|
-
|
20
|
-
|
21
|
-
#
|
22
|
-
|
23
|
-
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
#
|
28
|
-
#
|
29
|
-
|
30
|
-
|
31
|
-
#
|
32
|
-
attr_reader :
|
33
|
-
|
17
|
+
# @return [String,nil] The canonical alias, or `nil` if none has
|
18
|
+
# been set.
|
19
|
+
attr_reader :canonical_alias
|
20
|
+
|
21
|
+
# @return [String,nil] The name, or `nil` if none has been set.
|
22
|
+
attr_reader :name
|
23
|
+
|
24
|
+
# @return [String,nil] The topic, or `nil` if none has been set.
|
25
|
+
attr_reader :topic
|
26
|
+
|
27
|
+
# @return [User] The user who created the room.
|
28
|
+
attr_reader :creator
|
29
|
+
|
30
|
+
# @return [Boolean] `true` if guests are allowed in the room,
|
31
|
+
# otherwise `false`.
|
32
|
+
attr_reader :guest_access
|
33
|
+
|
34
|
+
# @return [String] Join rules for the room.
|
35
|
+
attr_reader :join_rule
|
36
|
+
|
37
|
+
# @return [String] The room's history visibility.
|
38
|
+
attr_reader :history_visibility
|
39
|
+
|
40
|
+
# @return [Permissions] Check room permissions.
|
41
|
+
attr_reader :permissions
|
34
42
|
|
35
43
|
# Initializes a new State instance.
|
36
44
|
#
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
require 'chatrix/message'
|
2
5
|
require 'chatrix/events'
|
3
6
|
|
@@ -41,7 +44,10 @@ module Chatrix
|
|
41
44
|
# Process a message event.
|
42
45
|
# @param event [Hash] Event data.
|
43
46
|
def handle_message(event)
|
44
|
-
|
47
|
+
sender = @users[event['sender']]
|
48
|
+
timestamp = event['origin_server_ts'] || Time.now.to_i
|
49
|
+
content = event['content']
|
50
|
+
message = Message.new sender, timestamp, content
|
45
51
|
broadcast(:message, @room, message)
|
46
52
|
Events.processed event
|
47
53
|
end
|
data/lib/chatrix/errors.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
module Chatrix
|
2
5
|
# Generic faults from the library.
|
3
6
|
class ChatrixError < StandardError
|
@@ -116,7 +119,7 @@ module Chatrix
|
|
116
119
|
# Set data to be the error response hash WITHOUT the error code and
|
117
120
|
# error values. This will leave it with only the data relevant for
|
118
121
|
# handling authentication.
|
119
|
-
@data = error.select { |key| !%w
|
122
|
+
@data = error.select { |key| !%w(errcode error).include? key }
|
120
123
|
end
|
121
124
|
end
|
122
125
|
end
|
data/lib/chatrix/events.rb
CHANGED
data/lib/chatrix/matrix.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
require 'chatrix/errors'
|
2
5
|
|
3
6
|
require 'chatrix/api/session'
|
@@ -230,7 +233,7 @@ module Chatrix
|
|
230
233
|
# and value.
|
231
234
|
def make_body(content)
|
232
235
|
key = content.respond_to?(:read) ? :body_stream : :body
|
233
|
-
value = content.is_a?
|
236
|
+
value = content.is_a?(Hash) ? content.to_json : content
|
234
237
|
{ key => value }
|
235
238
|
end
|
236
239
|
|
data/lib/chatrix/message.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
module Chatrix
|
2
5
|
# Describes a message sent in a room.
|
3
6
|
class Message
|
@@ -10,29 +13,37 @@ module Chatrix
|
|
10
13
|
'm.notice' => :notice
|
11
14
|
}.freeze
|
12
15
|
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
#
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
#
|
21
|
-
|
22
|
-
|
23
|
-
#
|
24
|
-
|
16
|
+
# @return [Hash] The raw message data (the `content` field).
|
17
|
+
attr_reader :raw
|
18
|
+
|
19
|
+
# @return [Symbol,nil] The type of message. Will be nil if the type
|
20
|
+
# failed to parse.
|
21
|
+
attr_reader :type
|
22
|
+
|
23
|
+
# @return [User] The user who sent this message.
|
24
|
+
attr_reader :sender
|
25
|
+
|
26
|
+
# @return [String] The text content of the message. If the message is
|
27
|
+
# of `:html` type, this will contain HTML format. To get the raw
|
28
|
+
# message text, use the `'body'` field of the {#raw} hash.
|
29
|
+
attr_reader :body
|
30
|
+
|
31
|
+
# @return [Integer] The timestamp of the message, indicating when
|
32
|
+
# it was sent, according to the origin server.
|
33
|
+
attr_reader :timestamp
|
25
34
|
|
26
35
|
# Initializes a new Message instance.
|
27
36
|
#
|
28
37
|
# @param sender [User] The user who sent the message.
|
38
|
+
# @param timestamp [Integer] The timestamp of the message.
|
29
39
|
# @param content [Hash] The message content.
|
30
|
-
def initialize(sender, content)
|
40
|
+
def initialize(sender, timestamp, content)
|
31
41
|
@raw = content
|
32
42
|
|
33
43
|
@type = TYPES[@raw['msgtype']]
|
34
44
|
@body = @raw['body']
|
35
45
|
@sender = sender
|
46
|
+
@timestamp = timestamp
|
36
47
|
|
37
48
|
parse_body!
|
38
49
|
end
|
data/lib/chatrix/room.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
require 'chatrix/components/state'
|
2
5
|
require 'chatrix/components/timeline'
|
3
6
|
require 'chatrix/components/messaging'
|
@@ -9,14 +12,21 @@ module Chatrix
|
|
9
12
|
class Room
|
10
13
|
include Wisper::Publisher
|
11
14
|
|
12
|
-
#
|
13
|
-
|
14
|
-
|
15
|
-
#
|
16
|
-
|
17
|
-
|
18
|
-
#
|
19
|
-
attr_reader :
|
15
|
+
# @return [String] The ID of this room.
|
16
|
+
attr_reader :id
|
17
|
+
|
18
|
+
# @return [State] The state object for this room.
|
19
|
+
attr_reader :state
|
20
|
+
|
21
|
+
# @return [Timeline] The timeline object for this room.
|
22
|
+
attr_reader :timeline
|
23
|
+
|
24
|
+
# @return [Admin] Administration object for carrying out administrative
|
25
|
+
# actions like kicking and banning of users.
|
26
|
+
attr_reader :admin
|
27
|
+
|
28
|
+
# @return [Messaging] Handle various message actions through this object.
|
29
|
+
attr_reader :messaging
|
20
30
|
|
21
31
|
# Initializes a new Room instance.
|
22
32
|
#
|
data/lib/chatrix/rooms.rb
CHANGED
data/lib/chatrix/user.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
require 'chatrix/events'
|
2
5
|
|
3
6
|
require 'wisper'
|
@@ -7,14 +10,15 @@ module Chatrix
|
|
7
10
|
class User
|
8
11
|
include Wisper::Publisher
|
9
12
|
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
#
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
# @return [String] The user ID of this user.
|
14
|
+
attr_reader :id
|
15
|
+
|
16
|
+
# @return [String,nil] The display name of this user, if one has
|
17
|
+
# been set.
|
18
|
+
attr_reader :displayname
|
19
|
+
|
20
|
+
# @return [String,nil] This user's avatar URL, if one has been set.
|
21
|
+
attr_reader :avatar
|
18
22
|
|
19
23
|
# Initializes a new User instance.
|
20
24
|
# @param id [String] The user ID.
|
data/lib/chatrix/users.rb
CHANGED
data/lib/chatrix/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chatrix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Hellberg
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- ".editorconfig"
|
63
63
|
- ".gitignore"
|
64
64
|
- ".rspec"
|
65
|
+
- ".rubocop.yml"
|
65
66
|
- ".travis.yml"
|
66
67
|
- ".yardopts"
|
67
68
|
- Gemfile
|
@@ -106,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
107
|
requirements:
|
107
108
|
- - ">="
|
108
109
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
110
|
+
version: 2.0.0
|
110
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
112
|
requirements:
|
112
113
|
- - ">="
|