class SoarSr::Validator

Public Instance Methods

authorized?(result) click to toggle source
# File lib/soar_sr/validator.rb, line 38
def authorized?(result)
  raise ValidationError, 'not authorized' if (notifications_include?(result, 'E_authTokenRequired')) or 
                                             (notifications_include?(result, 'E_keyUnavailable')) or
                                             (notifications_include?(result, 'E_userMismatch')) or
                                             (notifications_include?(result, 'not authorized'))
  true
end
contact?(contact) click to toggle source
# File lib/soar_sr/validator.rb, line 70
def contact?(contact)
  error = 'invalid contact details provided'
  raise ValidationError, error if not contact.is_a?(Hash)
  raise ValidationError, error if contact['name'].nil? or contact['name'].strip == ""
  true
end
credentials?(credentials) click to toggle source
# File lib/soar_sr/validator.rb, line 34
def credentials?(credentials)
    provided?(credentials, 'credentials') and provided?(credentials['username'], 'username') and provided?(credentials['password'], 'password')
end
identifier?(result, label) click to toggle source
# File lib/soar_sr/validator.rb, line 46
def identifier?(result, label)
  raise ValidationError, "invalid #{label} identifier provided" if notifications_include?(result, 'E_invalidKeyPassed')
  true
end
key_provided?(field, key, label) click to toggle source
# File lib/soar_sr/validator.rb, line 18
def key_provided?(field, key, label)
  msg_no = "no #{label} provided"
  msg_invalid = "invalid #{label} provided"
  raise ValidationError, msg_no if field.nil?
  raise ValidationError, msg_invalid if (not field.is_a? Hash)
  raise ValidationError, msg_no if field[key].nil?
  raise ValidationError, msg_invalid if (not field[key].is_a? String) or (field[key].strip == "")
  true
end
length_at_least?(field, min, label) click to toggle source
# File lib/soar_sr/validator.rb, line 29
def length_at_least?(field, min, label)
  raise ValidationError, "invalid #{label} provided" if (field.size < min)
  true
end
meta?(meta) click to toggle source
# File lib/soar_sr/validator.rb, line 56
def meta?(meta)
  raise ValidationError, 'invalid meta' if not meta.is_a?(Hash)
  true
end
one_of(type) click to toggle source
# File lib/soar_sr/validator.rb, line 77
def one_of(type)
  result = type[0..-2]
  result = 'domain perspective' if result == 'domain'
  result = 'service component' if result == 'service-component'
  result
end
present?(field) click to toggle source
# File lib/soar_sr/validator.rb, line 8
def present?(field)
  not (field.nil? or (field.is_a?(String) and field.strip == ""))
end
provided?(field, label) click to toggle source
# File lib/soar_sr/validator.rb, line 12
def provided?(field, label)
  raise ValidationError, "no #{label} provided" if field.nil?
  raise ValidationError, "invalid #{label} provided" if (field.is_a?(String) and field.strip == "")
  true
end
type?(type) click to toggle source
# File lib/soar_sr/validator.rb, line 61
def type?(type)
  ['domains', 'services', 'teams', 'service-components'].include?(type)
end
uri?(uri) click to toggle source
# File lib/soar_sr/validator.rb, line 51
def uri?(uri)
  raise ValidationError, 'invalid URI' if not (uri =~ URI::DEFAULT_PARSER.regexp[:UNSAFE]).nil?
  true
end
wadl?(definition) click to toggle source
# File lib/soar_sr/validator.rb, line 65
def wadl?(definition)
  raise ValidationError, 'invalid service definition provided' if not definition.include?("wadl")
  true
end