Class: Apnotic::Push

Inherits:
Object
  • Object
show all
Defined in:
lib/apnotic/push.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http2_request) ⇒ Push

Returns a new instance of Push.



6
7
8
9
10
11
12
13
# File 'lib/apnotic/push.rb', line 6

def initialize(http2_request)
  @http2_request = http2_request
  @headers       = {}
  @data          = ''
  @events        = {}

  listen_for_http2_events
end

Instance Attribute Details

#http2_requestObject (readonly)

Returns the value of attribute http2_request.



4
5
6
# File 'lib/apnotic/push.rb', line 4

def http2_request
  @http2_request
end

Instance Method Details

#emit(event, arg) ⇒ Object



22
23
24
25
# File 'lib/apnotic/push.rb', line 22

def emit(event, arg)
  return unless @events[event]
  @events[event].each { |b| b.call(arg) }
end

#on(event, &block) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
20
# File 'lib/apnotic/push.rb', line 15

def on(event, &block)
  raise ArgumentError, 'on event must provide a block' unless block_given?

  @events[event] ||= []
  @events[event] << block
end