Module: Pubnub::Event::EFormatter

Included in:
Pubnub::Event
Defined in:
lib/pubnub/event/formatter.rb

Overview

Module that holds formatters for events

Instance Method Summary collapse

Instance Method Details

#format_channelsObject



29
30
31
32
33
34
# File 'lib/pubnub/event/formatter.rb', line 29

def format_channels
  @channel = Formatter.format_channel(@channel || @channels)
  @channel += Formatter.format_presence_channel(@presence)
  @channel += Formatter.format_presence_channel(@channel || @channels) if @with_presence
  @wildcard_channel = @channel.select { |e| e.index('.*') } || []
end

#format_envelopes(response, request) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pubnub/event/formatter.rb', line 7

def format_envelopes(response, request)
  if response.is_a?(HTTPClient::TimeoutError) || response.is_a?(OpenSSL::SSL::SSLError)
    return error_envelope(nil,
                          response,
                          request: request,
                          response: response)
  elsif response.is_a?(StandardError)
    # unexpected error response
    raise response
  end

  parsed_response, error = Formatter.parse_json(response.body)

  error = response if parsed_response && response.code.to_i != 200

  if error
    error_envelope(parsed_response, error, request: request, response: response)
  else
    valid_envelope(parsed_response, request: request, response: response)
  end
end

#format_groupObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pubnub/event/formatter.rb', line 36

def format_group
  @group = (@channel_group || @channel_groups) if (@channel_group || @channel_groups) && @group.blank?
  @group = Formatter.format_group(@group)

  if @group.first.to_s.count(':') > 0
    @namespace_id, @group_id = @group.first.to_s.split(':')
  else
    @namespace_id = nil
    @group_id = @group.first.to_s
  end
end