Module: HAP::Parser

Included in:
Client
Defined in:
lib/hap_client/parser.rb

Instance Method Summary collapse

Instance Method Details

#init_parserObject



5
6
7
# File 'lib/hap_client/parser.rb', line 5

def init_parser
  @parser = Http::Parser.new(self)
end

#on_body(chunk) ⇒ Object



30
31
32
# File 'lib/hap_client/parser.rb', line 30

def on_body(chunk)
  @body << chunk
end

#on_headers_complete(headers) ⇒ Object



26
27
28
# File 'lib/hap_client/parser.rb', line 26

def on_headers_complete(headers)
  @headers = headers
end

#on_message_beginObject



21
22
23
24
# File 'lib/hap_client/parser.rb', line 21

def on_message_begin
  @headers = nil
  @body = ''
end

#on_message_completeObject



34
35
36
# File 'lib/hap_client/parser.rb', line 34

def on_message_complete
  parse_message(@body)
end

#receive_data(data) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/hap_client/parser.rb', line 9

def receive_data(data)
  if encryption_ready?
    data = decrypt(data)

    if data.start_with?("EVENT/")
      data.sub!("EVENT/","HTTP/")
    end
  end

  @parser << data
end