Sha256: 112c012dd26b35fdf5273939879794794c1f43916c61023faa6cbf7da8f4f6ec

Contents?: true

Size: 1.46 KB

Versions: 7

Compression:

Stored size: 1.46 KB

Contents

module Pubnub
  class HereNow
    include Pubnub::Event
    include Pubnub::SingleEvent
    include Pubnub::Formatter
    include Pubnub::Validator

    def initialize(options, app)
      super
      @channel = @channel.first
      @allow_multiple_channels = false
      @event = 'here_now'
    end

    def validate!
      super

      # check channel
      raise ArgumentError.new(:object => self, :message => 'Invalid channel format! Should be type of: String, Symbol') unless [String, Symbol, NilClass].include?(@channel.class)

    end

    private

    def path(app)
      unless @channel.blank?
        '/' + [
            'v2',
            'presence',
            'sub-key',
            @subscribe_key,
            'channel',
            @channel
        ].join('/')
      else
        $logger.debug('Pubnub'){'Global here_now'}
        '/' + [
            'v2',
            'presence',
            'sub-key',
            @subscribe_key
        ].join('/')
      end
    end

    def format_envelopes(response, app, error)
      parsed_response = Parser.parse_json(response.body) if Parser.valid_json?(response.body)

      envelopes = Array.new
      envelopes << Envelope.new(
          {
              :message           => parsed_response,
              :channel           => @channel,
              :response_message  => parsed_response
          },
          app
      )

      envelopes = add_common_data_to_envelopes(envelopes, response, app, error)

      envelopes
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pubnub-3.5.14 lib/pubnub/events/here_now.rb
pubnub-3.5.12 lib/pubnub/events/here_now.rb
pubnub-3.5.8 lib/pubnub/events/here_now.rb
pubnub-3.5.7 lib/pubnub/events/here_now.rb
pubnub-3.5.6 lib/pubnub/events/here_now.rb
pubnub-3.5.5 lib/pubnub/events/here_now.rb
pubnub-3.5.3 lib/pubnub/events/here_now.rb