matrix_dbus 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/Rakefile +3 -3
- data/bin/console +3 -3
- data/exe/matrix-dbus +19 -11
- data/lib/matrix_dbus/dbus.rb +29 -18
- data/lib/matrix_dbus/version.rb +1 -1
- metadata +2 -3
- data/lib/matrix_dbus/api.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a4b6b0fe7996571369fee0429fbf8df75dae94a
|
4
|
+
data.tar.gz: '0802e9e5e39f75a8d42093f5aef34ac0c8f9d864'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc2516b28cabd6ceef5c23f32b4cf48ad93c109b6c0643ca824ba8610cfa0e63eaf4cf07bde1ae045803bf07ed7317582e45548e956270b98c8710efc7106d53
|
7
|
+
data.tar.gz: 86a8bcee1901c314acf4992657cfaf972fd1e0c6c317f23cf5cdd693667a1bf807b268733365677c8f9351753ccb63dc2fc1d53a23aa33b69f1db8ffb740cda4
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
3
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in matrix_dbus.gemspec
|
6
6
|
gemspec
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'matrix_dbus'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "matrix_dbus"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
data/exe/matrix-dbus
CHANGED
@@ -4,25 +4,33 @@ require 'matrix_dbus'
|
|
4
4
|
Thread.abort_on_exception = true
|
5
5
|
|
6
6
|
def send_if_exist(obj, name, json)
|
7
|
-
obj.
|
7
|
+
obj.send name, JSON.pretty_generate(json) unless json.empty?
|
8
8
|
end
|
9
9
|
|
10
10
|
def matrix2dbus(c, obj)
|
11
|
-
|
12
|
-
|
11
|
+
json = c.json
|
12
|
+
%i[normal rooms device].each { |a| send a, obj, json }
|
13
|
+
end
|
14
|
+
|
15
|
+
def normal(obj, json)
|
16
|
+
obj.all JSON.pretty_generate json
|
13
17
|
|
14
|
-
%
|
15
|
-
send_if_exist obj, name,
|
18
|
+
%w[account_data to_device presence].each do |name|
|
19
|
+
send_if_exist obj, name, json[name]['events']
|
16
20
|
end
|
21
|
+
end
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
|
23
|
+
def rooms(obj, json)
|
24
|
+
send_if_exist obj, :rooms, json['rooms']
|
25
|
+
%w[leave join invite].each do |name|
|
26
|
+
send_if_exist obj, name, json['rooms'][name]
|
21
27
|
end
|
28
|
+
end
|
22
29
|
|
23
|
-
|
24
|
-
|
25
|
-
|
30
|
+
def device(obj, json)
|
31
|
+
send_if_exist obj, :device_lists, json['device_lists']
|
32
|
+
%w[changed left].each do |name|
|
33
|
+
send_if_exist obj, name, json['device_lists'][name]
|
26
34
|
end
|
27
35
|
end
|
28
36
|
|
data/lib/matrix_dbus/dbus.rb
CHANGED
@@ -12,16 +12,26 @@ module MatrixDBus
|
|
12
12
|
Thread.new { @matrix.run }
|
13
13
|
end
|
14
14
|
|
15
|
+
def self.return(info)
|
16
|
+
[JSON.pretty_generate(info)]
|
17
|
+
end
|
18
|
+
|
19
|
+
# rubocop:disable Metrics/BlockLength
|
15
20
|
dbus_interface 'org.dastudio.matrix' do
|
16
|
-
%i[post put].each do |way|
|
21
|
+
%i[post put get delete].each do |way|
|
17
22
|
dbus_method way, 'in url:s, in args:s, out res:s' do |url, args|
|
18
23
|
args = '{}' if args == ''
|
19
24
|
args = JSON.parse args
|
20
|
-
|
21
|
-
|
22
|
-
|
25
|
+
if %i[get delete].include? way
|
26
|
+
args[:access_token] = @matrix.access_token
|
27
|
+
elsif %i[post put].include? way
|
28
|
+
url = URI(url)
|
29
|
+
url.query = URI.encode_www_form access_token: @matrix.access_token
|
30
|
+
url = url.to_s
|
31
|
+
else raise 'Connot raise'
|
32
|
+
end
|
23
33
|
begin
|
24
|
-
|
34
|
+
Matrix2DBus.return @matrix.network.method(way).call(url, args)
|
25
35
|
rescue RestClient::Exception => e
|
26
36
|
puts e
|
27
37
|
puts e.response.body
|
@@ -29,23 +39,24 @@ module MatrixDBus
|
|
29
39
|
end
|
30
40
|
end
|
31
41
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
rescue RestClient::Exception => e
|
40
|
-
puts e
|
41
|
-
puts e.response.body
|
42
|
-
end
|
42
|
+
dbus_method :post_raw, 'in url:s, in body:s, out res:s' do |url, body|
|
43
|
+
begin
|
44
|
+
data = Base64.decode64 body
|
45
|
+
Matrix2DBus.return @matrix.network.post_raw(url, data)
|
46
|
+
rescue RestClient::Exception => e
|
47
|
+
puts e
|
48
|
+
puts e.response.body
|
43
49
|
end
|
44
50
|
end
|
45
51
|
|
46
|
-
dbus_method :
|
52
|
+
dbus_method :upload_file, 'in file:s, out mxc:s' do |file|
|
53
|
+
url = URI('/upload')
|
54
|
+
url.query = URI.encode_www_form access_token: @matrix.access_token
|
55
|
+
url = url.to_s
|
47
56
|
begin
|
48
|
-
|
57
|
+
File.open(file, 'rb') do |f|
|
58
|
+
Matrix2DBus.return @matrix.network.post_raw(url, f)
|
59
|
+
end
|
49
60
|
rescue RestClient::Exception => e
|
50
61
|
puts e
|
51
62
|
puts e.response.body
|
data/lib/matrix_dbus/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matrix_dbus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 71e6fd52
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -99,7 +99,6 @@ files:
|
|
99
99
|
- bin/setup
|
100
100
|
- exe/matrix-dbus
|
101
101
|
- lib/matrix_dbus.rb
|
102
|
-
- lib/matrix_dbus/api.rb
|
103
102
|
- lib/matrix_dbus/dbus.rb
|
104
103
|
- lib/matrix_dbus/matrix.rb
|
105
104
|
- lib/matrix_dbus/network.rb
|
data/lib/matrix_dbus/api.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
#
|
2
|
-
module MatrixAPI
|
3
|
-
def get(url)
|
4
|
-
uri = @host + '/_matrix/client/r0' + url
|
5
|
-
puts 'GET URL:', uri if $VERBOSE
|
6
|
-
JSON.parse RestClient.get(uri).body
|
7
|
-
rescue RestClient::Exceptions::OpenTimeout
|
8
|
-
retry
|
9
|
-
rescue RestClient::BadGateway
|
10
|
-
retry
|
11
|
-
end
|
12
|
-
|
13
|
-
def post(url, body)
|
14
|
-
uri = @host + '/_matrix/client/r0' + url
|
15
|
-
puts 'POST URL:', uri if $VERBOSE
|
16
|
-
JSON.parse RestClient.post(
|
17
|
-
uri,
|
18
|
-
body,
|
19
|
-
content_type: :json,
|
20
|
-
accept: :json
|
21
|
-
).body
|
22
|
-
rescue RestClient::Exceptions::OpenTimeout
|
23
|
-
retry
|
24
|
-
rescue RestClient::BadGateway
|
25
|
-
retry
|
26
|
-
end
|
27
|
-
|
28
|
-
def put(url, body)
|
29
|
-
uri = @host + '/_matrix/client/r0' + url
|
30
|
-
puts 'PUT URL:', uri if $VERBOSE
|
31
|
-
JSON.parse RestClient.put(
|
32
|
-
uri,
|
33
|
-
body.to_json,
|
34
|
-
content_type: :json,
|
35
|
-
accept: :json
|
36
|
-
).body
|
37
|
-
rescue RestClient::Exceptions::OpenTimeout
|
38
|
-
retry
|
39
|
-
rescue RestClient::BadGateway
|
40
|
-
retry
|
41
|
-
end
|
42
|
-
|
43
|
-
def upload_file(file, token)
|
44
|
-
uri = @host + '/_matrix/media/r0/upload?access_token=' + token
|
45
|
-
puts 'POST URL:', uri if $VERBOSE
|
46
|
-
JSON.parse(RestClient.post(uri, file).body)['content_uri']
|
47
|
-
rescue RestClient::Exceptions::OpenTimeout
|
48
|
-
retry
|
49
|
-
rescue RestClient::BadGateway
|
50
|
-
retry
|
51
|
-
end
|
52
|
-
end
|