Class: Subscriber::Client::ParserBundle
- Inherits:
-
Object
- Object
- Subscriber::Client::ParserBundle
- Defined in:
- lib/nchan_tools/pubsub.rb
Instance Attribute Summary collapse
-
#body_buf ⇒ Object
Returns the value of attribute body_buf.
-
#code ⇒ Object
Returns the value of attribute code.
-
#connected ⇒ Object
Returns the value of attribute connected.
-
#etag ⇒ Object
Returns the value of attribute etag.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#id ⇒ Object
Returns the value of attribute id.
-
#last_modified ⇒ Object
Returns the value of attribute last_modified.
-
#parser ⇒ Object
Returns the value of attribute parser.
-
#sock ⇒ Object
Returns the value of attribute sock.
-
#subparser ⇒ Object
Returns the value of attribute subparser.
-
#uri ⇒ Object
Returns the value of attribute uri.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #buffer_body! ⇒ Object
- #connected? ⇒ Boolean
-
#initialize(uri, opt = {}) ⇒ ParserBundle
constructor
A new instance of ParserBundle.
- #on_chunk(ch = nil, &block) ⇒ Object
- #on_error(msg = nil, e = nil, &block) ⇒ Object
- #on_headers(code = nil, h = nil, &block) ⇒ Object
- #on_response(code = nil, headers = nil, &block) ⇒ Object
- #open_socket ⇒ Object
Constructor Details
#initialize(uri, opt = {}) ⇒ ParserBundle
Returns a new instance of ParserBundle.
308 309 310 311 312 313 |
# File 'lib/nchan_tools/pubsub.rb', line 308 def initialize(uri, opt={}) @uri=uri @id=(opt[:id] or :"~").to_s.to_sym @logger = opt[:logger] open_socket end |
Instance Attribute Details
#body_buf ⇒ Object
Returns the value of attribute body_buf.
307 308 309 |
# File 'lib/nchan_tools/pubsub.rb', line 307 def body_buf @body_buf end |
#code ⇒ Object
Returns the value of attribute code.
307 308 309 |
# File 'lib/nchan_tools/pubsub.rb', line 307 def code @code end |
#connected ⇒ Object
Returns the value of attribute connected.
307 308 309 |
# File 'lib/nchan_tools/pubsub.rb', line 307 def connected @connected end |
#etag ⇒ Object
Returns the value of attribute etag.
307 308 309 |
# File 'lib/nchan_tools/pubsub.rb', line 307 def etag @etag end |
#headers ⇒ Object
Returns the value of attribute headers.
307 308 309 |
# File 'lib/nchan_tools/pubsub.rb', line 307 def headers @headers end |
#id ⇒ Object
Returns the value of attribute id.
307 308 309 |
# File 'lib/nchan_tools/pubsub.rb', line 307 def id @id end |
#last_modified ⇒ Object
Returns the value of attribute last_modified.
307 308 309 |
# File 'lib/nchan_tools/pubsub.rb', line 307 def last_modified @last_modified end |
#parser ⇒ Object
Returns the value of attribute parser.
307 308 309 |
# File 'lib/nchan_tools/pubsub.rb', line 307 def parser @parser end |
#sock ⇒ Object
Returns the value of attribute sock.
307 308 309 |
# File 'lib/nchan_tools/pubsub.rb', line 307 def sock @sock end |
#subparser ⇒ Object
Returns the value of attribute subparser.
307 308 309 |
# File 'lib/nchan_tools/pubsub.rb', line 307 def subparser @subparser end |
#uri ⇒ Object
Returns the value of attribute uri.
307 308 309 |
# File 'lib/nchan_tools/pubsub.rb', line 307 def uri @uri end |
#verbose ⇒ Object
Returns the value of attribute verbose.
307 308 309 |
# File 'lib/nchan_tools/pubsub.rb', line 307 def verbose @verbose end |
Instance Method Details
#buffer_body! ⇒ Object
328 329 330 |
# File 'lib/nchan_tools/pubsub.rb', line 328 def buffer_body! @body_buf||="" end |
#connected? ⇒ Boolean
331 332 333 |
# File 'lib/nchan_tools/pubsub.rb', line 331 def connected? @connected end |
#on_chunk(ch = nil, &block) ⇒ Object
344 345 346 347 348 349 350 351 352 |
# File 'lib/nchan_tools/pubsub.rb', line 344 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) ⇒ Object
364 365 366 367 368 369 370 371 |
# File 'lib/nchan_tools/pubsub.rb', line 364 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) ⇒ Object
334 335 336 337 338 339 340 341 342 |
# File 'lib/nchan_tools/pubsub.rb', line 334 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) ⇒ Object
354 355 356 357 358 359 360 361 362 |
# File 'lib/nchan_tools/pubsub.rb', line 354 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 ⇒ Object
314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/nchan_tools/pubsub.rb', line 314 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 |