Sha256: a37ca5047dc00c315c9efd09102375f830e17b954fe39369b05121a682ab8784

Contents?: true

Size: 1.19 KB

Versions: 19

Compression:

Stored size: 1.19 KB

Contents

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

    def initialize(options, app)
      super
      @channel = @channel.first
      @event = 'time'
      @doesnt_require_callback = true
    end

    def validate!
      super
      # check callback
      raise ArgumentError.new(:object => self, :message => 'Callback parameter is required while using async time') if !@http_sync && @callback.blank?
    end

    private

    def path(app)
      '/time/0'
    end

    def timetoken(parsed_response)
      parsed_response.first if parsed_response.is_a? Array
    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           => timetoken(parsed_response),
              :response_message  => timetoken(parsed_response),
              :timetoken         => timetoken(parsed_response)
          },
          app
      )

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

      envelopes

    end

  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
pubnub-3.7.12 lib/pubnub/events/time.rb
pubnub-3.7.11 lib/pubnub/events/time.rb
pubnub-3.7.10 lib/pubnub/events/time.rb
pubnub-3.7.9 lib/pubnub/events/time.rb
pubnub-3.7.7 lib/pubnub/events/time.rb
pubnub-3.7.5 lib/pubnub/events/time.rb
pubnub-3.7.1 lib/pubnub/events/time.rb
pubnub-3.7.0 lib/pubnub/events/time.rb
pubnub-3.6.10 lib/pubnub/events/time.rb
pubnub-3.6.9 lib/pubnub/events/time.rb
pubnub-3.6.7 lib/pubnub/events/time.rb
pubnub-3.5.14 lib/pubnub/events/time.rb
pubnub-3.5.12 lib/pubnub/events/time.rb
pubnub-3.5.8 lib/pubnub/events/time.rb
pubnub-3.5.7 lib/pubnub/events/time.rb
pubnub-3.5.6 lib/pubnub/events/time.rb
pubnub-3.5.5 lib/pubnub/events/time.rb
pubnub-3.5.3 lib/pubnub/events/time.rb
pubnub-3.5.1 lib/pubnub/events/time.rb