Class: Twitter::Streaming::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter/streaming/response.rb

Instance Method Summary (collapse)

Constructor Details

- (Twitter::Streaming::Response) initialize(&block)

Initializes a new Response object



9
10
11
12
13
# File 'lib/twitter/streaming/response.rb', line 9

def initialize(&block)
  @block     = block
  @parser    = Http::Parser.new(self)
  @tokenizer = BufferedTokenizer.new("\r\n")
end

Instance Method Details

- (Object) <<(data)



15
16
17
# File 'lib/twitter/streaming/response.rb', line 15

def <<(data)
  @parser << data
end

- (Object) on_body(data)



24
25
26
27
28
29
# File 'lib/twitter/streaming/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

- (Object) on_headers_complete(_headers)



19
20
21
22
# File 'lib/twitter/streaming/response.rb', line 19

def on_headers_complete(_headers)
  error = Twitter::Error.errors[@parser.status_code]
  fail error.new if error
end