Class: QQ

Inherits:
Object
  • Object
show all
Includes:
QQAPI
Defined in:
lib/CQHTTP/qq.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#jsonObject (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

#runObject



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