Sha256: 3f5888e5a64dfd0309f4f643351fc2a80203399b04d71a6744d5b3c319c0a6d9

Contents?: true

Size: 1.85 KB

Versions: 22

Compression:

Stored size: 1.85 KB

Contents

# Toplevel Pubnub module.
module Pubnub
  # Validator module that holds all validators modules
  module Validator
    # Validator for Grant event
    module Grant
      include CommonValidator

      def validate!
        return if @skip_validate

        validate_keys!
        validate_ttl!
        validate_uuids!
      end

      private

      def validate_keys!
        raise(
          ArgumentError.new(object: self, message: ':subscribe_key is required for grant event.'),
          ':subscribe_key is required for grant event.'
        ) if @subscribe_key.nil? || @subscribe_key.empty?

        raise(
          ArgumentError.new(object: self, message: ':publish_key is required for grant event.'),
          ':publish_key is required for grant event.'
        ) if @publish_key.nil? || @publish_key.empty?
      end

      def validate_ttl!
        return unless !@ttl.nil? && !@ttl.is_a?(Integer)

        raise(
          ArgumentError.new(object: self, message: ':ttl has to be kind of Integer for grant event.'),
          ':ttl has to be kind of Integer for grant event.'
        )
      end

      def validate_uuids!
        return if @uuids.nil?

        raise(
          ArgumentError.new(object: self, message: ':uuid should not be empty for grant event.'),
          ':uuid should not be empty for grant event.'
        ) if @uuid.empty?

        raise(
          ArgumentError.new(object: self, message: ':auth_key required for grant event on uuids.'),
          ':uuid should not be empty for grant event on uuids.'
        ) if @auth_key.nil? || @auth_key.blank?

        raise(
          ArgumentError.new(object: self, message: ':uuid can\'t be used along with channel/channel_groups for grant event.'),
          ':uuid can\'t be used along with channel/channel_groups for grant event.'
        ) if !@channels.nil? || !@channel_groups.nil?
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
pubnub-5.5.0 lib/pubnub/validators/grant.rb
pubnub-5.4.0 lib/pubnub/validators/grant.rb
pubnub-5.3.5 lib/pubnub/validators/grant.rb
pubnub-5.3.4 lib/pubnub/validators/grant.rb
pubnub-5.3.3 lib/pubnub/validators/grant.rb
pubnub-5.3.2 lib/pubnub/validators/grant.rb
pubnub-5.3.1 lib/pubnub/validators/grant.rb
pubnub-5.3.0 lib/pubnub/validators/grant.rb
pubnub-5.2.2 lib/pubnub/validators/grant.rb
pubnub-5.2.1 lib/pubnub/validators/grant.rb
pubnub-5.2.0 lib/pubnub/validators/grant.rb
pubnub-5.1.2 lib/pubnub/validators/grant.rb
pubnub-5.1.1 lib/pubnub/validators/grant.rb
pubnub-5.1.0 lib/pubnub/validators/grant.rb
pubnub-5.0.0 lib/pubnub/validators/grant.rb
pubnub-4.8.0 lib/pubnub/validators/grant.rb
pubnub-4.7.1 lib/pubnub/validators/grant.rb
pubnub-4.7.0 lib/pubnub/validators/grant.rb
pubnub-4.6.2 lib/pubnub/validators/grant.rb
pubnub-4.6.1 lib/pubnub/validators/grant.rb