matrix_dbus 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be28175a6c49d37d25cd9718c6ef74d6e79b5321
4
- data.tar.gz: 3b89ba6a7be1f4aefbc5e630364af57b774419aa
3
+ metadata.gz: 5a4b6b0fe7996571369fee0429fbf8df75dae94a
4
+ data.tar.gz: '0802e9e5e39f75a8d42093f5aef34ac0c8f9d864'
5
5
  SHA512:
6
- metadata.gz: 381d61801c7ba0e06853d3c0a338b3cf14afc5e6267080b0711010c2d3c1f094368951af8d094875a94e8839ddacbf663b66eed015278e0c6ec9117b5ba30062
7
- data.tar.gz: e19887e518b3ecf90db293e70f3e7d8fd116bcb2cd75e0a1c8edd2d028f87deec5f283454dbc74cd06df08110d384119de735a79c16defe485445392fc92f062
6
+ metadata.gz: fc2516b28cabd6ceef5c23f32b4cf48ad93c109b6c0643ca824ba8610cfa0e63eaf4cf07bde1ae045803bf07ed7317582e45548e956270b98c8710efc7106d53
7
+ data.tar.gz: 86a8bcee1901c314acf4992657cfaf972fd1e0c6c317f23cf5cdd693667a1bf807b268733365677c8f9351753ccb63dc2fc1d53a23aa33b69f1db8ffb740cda4
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source "https://rubygems.org"
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
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "matrix_dbus"
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 "irb"
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.method(name).call JSON.pretty_generate json unless json.empty?
7
+ obj.send name, JSON.pretty_generate(json) unless json.empty?
8
8
  end
9
9
 
10
10
  def matrix2dbus(c, obj)
11
- j = c.json
12
- obj.all JSON.pretty_generate j
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
- %i[account_data to_device presence].each do |name|
15
- send_if_exist obj, name, j[name.to_s]['events']
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
- send_if_exist obj, :rooms, j['rooms']
19
- %i[leave join invite].each do |name|
20
- send_if_exist obj, name, j['rooms'][name.to_s]
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
- send_if_exist obj, :device_lists, j['device_lists']
24
- %i[changed left].each do |name|
25
- send_if_exist obj, name, j['device_lists'][name.to_s]
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
 
@@ -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
- url = URI(url)
21
- url.query = URI.encode_www_form access_token: @matrix.access_token
22
- url = url.to_s
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
- [@matrix.network.method(way).call(url, args).to_json]
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
- %i[get delete].each do |way|
33
- dbus_method way, 'in url:s, in args:s, out res:s' do |url, args|
34
- args = '{}' if args == ''
35
- args = JSON.parse args
36
- args[:access_token] = @matrix.access_token
37
- begin
38
- [@matrix.network.method(way).call(url, args).to_json]
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 :post_raw, 'in url:s, in body:s, out res:s' do |url, body|
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
- [@matrix.network.post_raw(url, Base64.decode64(body)).to_json]
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
@@ -1,3 +1,3 @@
1
1
  module MatrixDBus
2
- VERSION = "1.0.0"
2
+ VERSION = '1.1.0'.freeze
3
3
  end
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.0.0
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-21 00:00:00.000000000 Z
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
@@ -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