Class: SimpleStream::Response
- Inherits:
-
Object
- Object
- SimpleStream::Response
- Defined in:
- lib/simple_stream/response.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#tokenizer ⇒ Object
readonly
Returns the value of attribute tokenizer.
Instance Method Summary collapse
- #<<(data) ⇒ Object
-
#initialize(&block) ⇒ Response
constructor
A new instance of Response.
- #on_body(data) ⇒ Object
- #on_headers_complete(headers) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 |
# File 'lib/simple_stream/response.rb', line 9 def initialize(&block) @block = block @parser = Http::Parser.new(self) @tokenizer = BufferedTokenizer.new("\r\n") end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block
7 8 9 |
# File 'lib/simple_stream/response.rb', line 7 def block @block end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser
7 8 9 |
# File 'lib/simple_stream/response.rb', line 7 def parser @parser end |
#tokenizer ⇒ Object (readonly)
Returns the value of attribute tokenizer
7 8 9 |
# File 'lib/simple_stream/response.rb', line 7 def tokenizer @tokenizer end |
Instance Method Details
#<<(data) ⇒ Object
15 16 17 |
# File 'lib/simple_stream/response.rb', line 15 def <<(data) parser << data end |
#on_body(data) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/simple_stream/response.rb', line 24 def on_body(data) tokenizer.extract(data).each do |line| next if line.empty? block.call(JSON.parse(line, symbolize_names: true)) end end |
#on_headers_complete(headers) ⇒ Object
19 20 21 22 |
# File 'lib/simple_stream/response.rb', line 19 def on_headers_complete(headers) # TODO p(status_code: parser.status_code, header: headers) unless parser.status_code == 200 end |