CQHTTP 0.2.1 → 0.3.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
  SHA1:
3
- metadata.gz: 32f5a329e4ce5dc8b0472737f61d828a43e95c6f
4
- data.tar.gz: 959f0d0984d8121fe4e525a618aba376f712cae9
3
+ metadata.gz: 1af39bae6b5ce49f4525cb37041f90a35f685833
4
+ data.tar.gz: b4c17f35245594f7c576a79710c14495af48df95
5
5
  SHA512:
6
- metadata.gz: 1d487d975cfcf243045d29bdaf35c7702907e7867d2074cb22d6f075bcfc30807a7a3f173bf6e9d68b9ac493e4f2d4fb41734c655d853b1a660ae7bbd19ed0f3
7
- data.tar.gz: e02241186ec51057dd9b82636876503c1094e01f241a8cdeb11b0ac30a4df68714dcee21b8e4df5816505ac8681bf5b438b7db494b16eda5f4ea7f010b87357f
6
+ metadata.gz: 66b73f44ef7f147a2811bb324cfa427e5f9ac941337c3ed705e97b5e8612ce3a36198060f6db4c76efa0297e3d349642636aeb3fb7f4132c6b0ce8cc650b6ceb
7
+ data.tar.gz: fb11483346c7dff8a5b2fc0170d4e33bd2c336ec87c9b3f2957376d960acdf47e27993ce59105e2a8bbfccff54c38c32c4c29b140156659e76e2c42daa066aeb
data/CQHTTP.gemspec CHANGED
@@ -21,4 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency 'bundler', '~> 1.15'
22
22
  spec.add_development_dependency 'rake', '~> 10.0'
23
23
  spec.add_development_dependency 'rspec', '~> 3.0'
24
+
25
+ spec.add_dependency 'ruby-dbus', '~> 0.13.0'
24
26
  end
data/exe/cqhttp-dbus ADDED
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'CQHTTP'
4
+ require 'dbus'
5
+ Thread.abort_on_exception = true
6
+
7
+ # DBus
8
+ class CQHTTP2DBus < DBus::Object
9
+ dbus_interface 'org.dastudio.cqhttp' do
10
+ dbus_signal :message, 'message_type:s, json:s'
11
+ dbus_signal :event, 'event:s, json:s'
12
+ dbus_signal :friend_request, 'json:s'
13
+ dbus_signal :join_request, 'json:s'
14
+ dbus_signal :invite_request, 'json:s'
15
+ dbus_signal :all, 'json:s'
16
+ dbus_signal :unknow, 'json:s'
17
+ end
18
+ end
19
+
20
+ def cqhttp2dbus(c, obj)
21
+ j = c.json
22
+ obj.all j.to_json
23
+ case j['post_type']
24
+ when 'message' then obj.message j['message_type'], j.to_json
25
+ when 'event' then obj.event j['event'], j.to_json
26
+ when 'request'
27
+ case j['request_type']
28
+ when 'friend' then obj.friend_request j.to_json
29
+ when 'group'
30
+ case j['sub_type']
31
+ when 'add' then obj.join_request j.to_json
32
+ when 'invite' then obj.invite_request j.to_json
33
+ else obj.unknow j.to_json
34
+ end
35
+ else obj.unknow j.to_json
36
+ end
37
+ else obj.unknow j.to_json
38
+ end
39
+ end
40
+
41
+ bus = DBus::SessionBus.instance
42
+ service = bus.request_service 'org.dastudio.qq'
43
+ obj = CQHTTP2DBus.new '/org/dastudio/qq'
44
+ service.export obj
45
+
46
+ cqhttp = CQHTTP::Service.new
47
+ cqhttp.bind ->(c) { cqhttp2dbus c, obj }
48
+
49
+ Thread.new { cqhttp.run }
50
+
51
+ main = DBus::Main.new
52
+ main << bus
53
+ main.run
@@ -0,0 +1,42 @@
1
+ module CQHTTP
2
+ # TODO
3
+ class Service
4
+ attr_reader :json
5
+
6
+ def initialize(hostname: '0.0.0.0', port: 9455)
7
+ @server = TCPServer.new(hostname, port)
8
+ @event_method = []
9
+ end
10
+
11
+ def bind(func)
12
+ @event_method << func
13
+ end
14
+
15
+ def run
16
+ loop do
17
+ socket = @server.accept
18
+
19
+ head socket if $VERBOSE
20
+
21
+ socket.print "HTTP/1.1 204\r\nContent-Type: application/json\r\n\r\n"
22
+ data = socket.gets
23
+ @json = JSON.parse data
24
+
25
+ @event_method.each { |func| func.call self }
26
+
27
+ socket.close
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def head(socket)
34
+ puts 'head'
35
+ while (line = socket.gets) != "\r\n"
36
+ print ' '
37
+ puts line
38
+ end
39
+ puts 'end'
40
+ end
41
+ end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module CQHTTP
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/CQHTTP.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'CQHTTP/version'
2
2
 
3
- require 'CQHTTP/api.rb'
4
- require 'CQHTTP/network.rb'
3
+ require 'CQHTTP/api'
4
+ require 'CQHTTP/network'
5
+ require 'CQHTTP/service'
5
6
 
6
7
  require 'uri'
7
8
  require 'net/http'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: CQHTTP
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.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-02 00:00:00.000000000 Z
11
+ date: 2017-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,10 +52,25 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ruby-dbus
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.13.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.13.0
55
69
  description:
56
70
  email:
57
71
  - DAStudio.71e6fd52@gmail.com
58
- executables: []
72
+ executables:
73
+ - cqhttp-dbus
59
74
  extensions: []
60
75
  extra_rdoc_files: []
61
76
  files:
@@ -69,10 +84,12 @@ files:
69
84
  - bin/console
70
85
  - bin/gen_api_list
71
86
  - bin/setup
87
+ - exe/cqhttp-dbus
72
88
  - lib/CQHTTP.rb
73
89
  - lib/CQHTTP/API.md
74
90
  - lib/CQHTTP/api.rb
75
91
  - lib/CQHTTP/network.rb
92
+ - lib/CQHTTP/service.rb
76
93
  - lib/CQHTTP/version.rb
77
94
  homepage: https://github.com/71e6fd52/cqhttp-ruby
78
95
  licenses: []