Sha256: f14cb43d8a59a174ee11189631babda359f364be5f8c6d552ed783e26354dbb9

Contents?: true

Size: 1.71 KB

Versions: 22

Compression:

Stored size: 1.71 KB

Contents

# Toplevel Pubnub module.
module Pubnub
  # Validator module that holds all validators modules
  module Validator
    # Validator for Client object
    module CommonValidator
      # Validates given origin
      def validate_origin(origin, required = false)
        if !origin && required
          raise(
            InitializationError.new,
            'Missing required :origins_pool parameter.'
          )
        elsif !(origin.is_a?(String) || origin.blank?)
          raise(
            InitializationError.new,
            'origins_pool parameter is not valid. \
                   Should be type of String.'
          )
        end
      end

      # Validates given subscribe key
      def validate_subscribe_key(subscribe_key, required = false)
        if !subscribe_key && required
          raise(
            InitializationError.new,
            'Missing required :subscribe_key parameter.'
          )
        elsif ![String, Symbol].include?(subscribe_key.class)
          raise(
            InitializationError.new,
            'Subscribe key parameter is not valid. \
                   Should be type of String or Symbol.'
          )
        end
      end

      # Validates given publish key
      def validate_publish_key(publish_key, required = false)
        if !publish_key && required
          raise(
            InitializationError.new,
            'Missing required :subscribe_key parameter.'
          )
        elsif !([String, Symbol].include?(publish_key.class) ||
               publish_key.blank?)
          raise(
            InitializationError.new,
            'Publish key parameter is not valid. \
                   Should be type of String or Symbol.'
          )
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
pubnub-4.8.0 lib/pubnub/validators/common_validator.rb
pubnub-4.7.1 lib/pubnub/validators/common_validator.rb
pubnub-4.7.0 lib/pubnub/validators/common_validator.rb
pubnub-4.6.2 lib/pubnub/validators/common_validator.rb
pubnub-4.6.1 lib/pubnub/validators/common_validator.rb
pubnub-4.6.0 lib/pubnub/validators/common_validator.rb
pubnub-4.5.0 lib/pubnub/validators/common_validator.rb
pubnub-4.4.0 lib/pubnub/validators/common_validator.rb
pubnub-4.3.0 lib/pubnub/validators/common_validator.rb
pubnub-4.2.7 lib/pubnub/validators/common_validator.rb
pubnub-4.2.6 lib/pubnub/validators/common_validator.rb
pubnub-4.2.5 lib/pubnub/validators/common_validator.rb
pubnub-4.2.4 lib/pubnub/validators/common_validator.rb
pubnub-4.2.3 lib/pubnub/validators/common_validator.rb
pubnub-4.2.2 lib/pubnub/validators/common_validator.rb
pubnub-4.2.1 lib/pubnub/validators/common_validator.rb
pubnub-4.2.0 lib/pubnub/validators/common_validator.rb
pubnub-4.1.6 lib/pubnub/validators/common_validator.rb
pubnub-4.1.5 lib/pubnub/validators/common_validator.rb
pubnub-4.1.2 lib/pubnub/validators/common_validator.rb