class NchanTools::Subscriber::Client::ParserBundle
Attributes
body_buf[RW]
code[RW]
connected[RW]
etag[RW]
headers[RW]
id[RW]
last_modified[RW]
parser[RW]
sock[RW]
subparser[RW]
uri[RW]
verbose[RW]
Public Class Methods
new(uri, opt={})
click to toggle source
# File lib/nchan_tools/pubsub.rb, line 305 def initialize(uri, opt={}) @uri=uri @id=(opt[:id] or :"~").to_s.to_sym @logger = opt[:logger] open_socket end
Public Instance Methods
buffer_body!()
click to toggle source
# File lib/nchan_tools/pubsub.rb, line 325 def buffer_body! @body_buf||="" end
connected?()
click to toggle source
# File lib/nchan_tools/pubsub.rb, line 328 def connected? @connected end
on_chunk(ch=nil, &block)
click to toggle source
# File lib/nchan_tools/pubsub.rb, line 341 def on_chunk(ch=nil, &block) if block_given? @on_chunk = block else @body_buf << ch if @body_buf @logger.log @id, :chunk, ch if @logger @on_chunk.call(ch) if @on_chunk end end
on_error(msg=nil, e=nil, &block)
click to toggle source
# File lib/nchan_tools/pubsub.rb, line 361 def on_error(msg=nil, e=nil, &block) if block_given? @on_error = block else @logger.log @id, :error, "#{e.to_s}, #{msg}" if @logger @on_error.call(msg, e) if @on_error end end
on_headers(code=nil, h=nil, &block)
click to toggle source
# File lib/nchan_tools/pubsub.rb, line 331 def on_headers(code=nil, h=nil, &block) @body_buf.clear if @body_buf if block_given? @on_headers = block else @logger.log @id, :headers, "#{code or "no code"}; headers: #{h or "none"}" if @logger @on_headers.call(code, h) if @on_headers end end
on_response(code=nil, headers=nil, &block)
click to toggle source
# File lib/nchan_tools/pubsub.rb, line 351 def on_response(code=nil, headers=nil, &block) if block_given? @on_response = block else @logger.log @id, :response, "code #{code or "-"}, headers: #{headers or "-"}, body: #{@body_buf}" if @logger @on_response.call(code, headers, @body_buf) if @on_response end end
open_socket()
click to toggle source
# File lib/nchan_tools/pubsub.rb, line 311 def open_socket case uri.scheme when /^unix$/ @sock = Celluloid::IO::UNIXSocket.new(uri.host) when /^(ws|http|h2c)$/ @sock = Celluloid::IO::TCPSocket.new(uri.host, uri.port) when /^(wss|https|h2)$/ @sock = Celluloid::IO::SSLSocket.new(Celluloid::IO::TCPSocket.new(uri.host, uri.port)) else raise ArgumentError, "unexpected uri scheme #{uri.scheme}" end self end