Sha256: 1e6fdb1fce8c46cb69d5a97a8dbb929a9ecc9e4821d2eee02a9fa9e8d730581d

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

require 'livefyre/utils/livefyre_util'

module Livefyre
  class CollectionValidator
    def self.validate(data)
      reason = ''

      reason += '\n Article id is null or blank' if data.article_id.to_s.empty?

      if data.title.to_s.empty?
        reason += '\n Title is null or blank'
      elsif data.title.length > 255
        reason += '\n Title is longer than 255 characters.'
      end

      if data.url.to_s.empty?
        reason += '\n URL is null or blank.'
      elsif !LivefyreUtil::uri?(data.url)
        reason += '\n URL is not a valid url. see http://www.ietf.org/rfc/rfc2396.txt'
      end

      if data.type == nil
        reason += '\n Type cannot be nil.'
      elsif not CollectionType.const_defined?(data.type.start_with?('live') ? data.type.sub('live', '').upcase : data.type.upcase)
        reason += '\n Type must be of valid, recognized type. See CollectionType.'
      end

      raise ArgumentError, "Problems with your collection input: #{reason}" if reason.length > 0

      data
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
livefyre-2.0.2 lib/livefyre/validator/collection_validator.rb
livefyre-2.0.1 lib/livefyre/validator/collection_validator.rb
livefyre-2.0.0 lib/livefyre/validator/collection_validator.rb