Class: QQ
Instance Attribute Summary collapse
-
#json ⇒ Object
readonly
Returns the value of attribute json.
Instance Method Summary collapse
- #bind(func) ⇒ Object
-
#initialize(hostname: '0.0.0.0', port: 9455) ⇒ QQ
constructor
A new instance of QQ.
- #run ⇒ Object
Constructor Details
#initialize(hostname: '0.0.0.0', port: 9455) ⇒ QQ
Returns a new instance of QQ.
6 7 8 9 |
# File 'lib/CQHTTP/qq.rb', line 6 def initialize(hostname: '0.0.0.0', port: 9455) @server = TCPServer.new(hostname, port) @event_method = [] end |
Instance Attribute Details
#json ⇒ Object (readonly)
Returns the value of attribute json.
4 5 6 |
# File 'lib/CQHTTP/qq.rb', line 4 def json @json end |
Instance Method Details
#bind(func) ⇒ Object
11 12 13 |
# File 'lib/CQHTTP/qq.rb', line 11 def bind(func) @event_method << func end |
#run ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/CQHTTP/qq.rb', line 15 def run loop do socket = @server.accept head socket socket.print "HTTP/1.1 204\r\nContent-Type: application/json\r\n\r\n" data = socket.gets @json = JSON.parse data @event_method.each { |func| func.call self } socket.close end end |