Class: Flowhook::Streaming

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

Overview

The streaming client for Flowdock API

Constant Summary collapse

STREAMING_URL =
'https://stream.flowdock.com/flows'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(token, use_private = false, flows = [], events = []) ⇒ Streaming

Returns a new instance of Streaming.



6
7
8
9
10
11
12
13
14
# File 'lib/flowhook/streaming.rb', line 6

def initialize(token, use_private = false, flows = [], events = [])
  @token = token
  @flows = flows
  @private = use_private ? 1 : 0
  @events = events
  @queue = Queue.new
  @thread = nil
  @stop = false
end

Instance Method Details

#read(&_block) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/flowhook/streaming.rb', line 24

def read(&_block)
  ensure_connection
  until stop?
    yield @queue.pop(true) until @queue.empty?
    # NOOP
  end
end

#stop!Object



20
21
22
# File 'lib/flowhook/streaming.rb', line 20

def stop!
  @stop = true
end

#stop?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/flowhook/streaming.rb', line 16

def stop?
  @stop == true
end