Module: Deepstream::Helpers

Defined in:
lib/deepstream/helpers.rb

Constant Summary collapse

SCHEME =
'ws://'
DEFAULT_PORT =
6020
DEFAULT_PATH =
'deepstream'

Class Method Summary collapse

Class Method Details

.default_optionsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/deepstream/helpers.rb', line 33

def self.default_options
  {
    ack_timeout: nil,
    autologin: true,
    credentials: {},
    heartbeat_interval: nil,
    max_reconnect_attempts: nil,
    max_reconnect_interval: 30,
    reconnect_interval: 1,
    emit_timeout: 0,
    verbose: false,
    debug: false
  }
end

.to_deepstream_type(value) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/deepstream/helpers.rb', line 9

def self.to_deepstream_type(value)
  case value
  when Hash then "O#{value.to_json}"
  when String then "S#{value}"
  when Numeric then "N#{value}"
  when TrueClass then 'T'
  when FalseClass then 'F'
  when NilClass then 'L'
  end
end

.to_type(payload) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/deepstream/helpers.rb', line 20

def self.to_type(payload)
  case payload[0]
  when 'O' then JSON.parse(payload[1..-1])
  when '{' then JSON.parse(payload)
  when 'S' then payload[1..-1]
  when 'N' then payload[1..-1].to_f
  when 'T' then true
  when 'F' then false
  when 'L' then nil
  else JSON.parse(payload)
  end
end

.url(url) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/deepstream/helpers.rb', line 48

def self.url(url)
  url.tap do |url|
    url.prepend(SCHEME) unless url.start_with?(SCHEME)
    url.concat(":#{DEFAULT_PORT}") unless url[/\:\d+/]
    url.concat("/#{DEFAULT_PATH}") unless url[/\/\w+$/]
  end
end