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.
8 9 10 11 12 |
# File 'lib/simple_stream/response.rb', line 8 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.
6 7 8 |
# File 'lib/simple_stream/response.rb', line 6 def block @block end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
6 7 8 |
# File 'lib/simple_stream/response.rb', line 6 def parser @parser end |
#tokenizer ⇒ Object (readonly)
Returns the value of attribute tokenizer.
6 7 8 |
# File 'lib/simple_stream/response.rb', line 6 def tokenizer @tokenizer end |
Instance Method Details
#<<(data) ⇒ Object
14 15 16 |
# File 'lib/simple_stream/response.rb', line 14 def <<(data) parser << data end |
#on_body(data) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/simple_stream/response.rb', line 23 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
18 19 20 21 |
# File 'lib/simple_stream/response.rb', line 18 def on_headers_complete(headers) # TODO p(status_code: parser.status_code, header: headers) unless parser.status_code == 200 end |