class Mastodon::Streaming::Response
When someone responses to toots.
Public Class Methods
new(&block)
click to toggle source
Initializes a new Response
object
@return [Mastodon::Streaming::Response]
# File lib/mastodon/streaming/response.rb, line 15 def initialize(&block) @block = block @parser = Http::Parser.new(self) @tokenizer = BufferedTokenizer.new("\n\n") @match = Regexp.new(/event: ([a-z]+)\ndata: (.+)/m) end
Public Instance Methods
<<(data)
click to toggle source
# File lib/mastodon/streaming/response.rb, line 22 def <<(data) @parser << data end
on_body(data)
click to toggle source
# File lib/mastodon/streaming/response.rb, line 32 def on_body(data) @tokenizer.extract(data).each do |line| has_data = @match.match(line) next if has_data.nil? type = has_data[1] data = has_data[2] @block.call(type, JSON.parse(data)) end end
on_headers_complete(_headers)
click to toggle source
@note this does get called
# File lib/mastodon/streaming/response.rb, line 27 def on_headers_complete(_headers) error = Mastodon::Error::ERRORS[@parser.status_code] raise error if error end