class Wor::Push::Notifications::Aws::PushNotificationsValidator

Public Class Methods

new(model, device_token = nil, device_type = nil) click to toggle source
# File lib/wor/push/notifications/aws/validators/push_notifications_validator.rb, line 6
def initialize(model, device_token = nil, device_type = nil)
  @model = model
  @device_token = device_token
  @device_type = device_type
end
validate_message_content(message_content) click to toggle source
# File lib/wor/push/notifications/aws/validators/push_notifications_validator.rb, line 29
def validate_message_content(message_content)
  raise ArgumentError, message_content_type_error unless message_content.is_a?(Hash)
  message_content = message_content.with_indifferent_access
  raise ArgumentError, message_content_error if message_content[:message].blank?
  badge_check(message_content)
end

Private Class Methods

badge_check(message_content) click to toggle source
# File lib/wor/push/notifications/aws/validators/push_notifications_validator.rb, line 46
def badge_check(message_content)
  message_content[:badge] ||= 1
  message_content
end
message_content_error() click to toggle source
# File lib/wor/push/notifications/aws/validators/push_notifications_validator.rb, line 38
def message_content_error
  "the message_content must have a 'message' field"
end
message_content_type_error() click to toggle source
# File lib/wor/push/notifications/aws/validators/push_notifications_validator.rb, line 42
def message_content_type_error
  'message_content must be a Hash'
end

Public Instance Methods

validate_add_token() click to toggle source
# File lib/wor/push/notifications/aws/validators/push_notifications_validator.rb, line 12
def validate_add_token
  validate_model_existance
  validate_existence_of_attributes_in_model
  validate_parameters
end
validate_delete_token() click to toggle source
# File lib/wor/push/notifications/aws/validators/push_notifications_validator.rb, line 18
def validate_delete_token
  validate_model_existance
  validate_existence_of_attributes_in_model
end
validate_model() click to toggle source
# File lib/wor/push/notifications/aws/validators/push_notifications_validator.rb, line 23
def validate_model
  validate_model_existance
  validate_existence_of_attributes_in_model
end

Private Instance Methods

device_type_valid?() click to toggle source
# File lib/wor/push/notifications/aws/validators/push_notifications_validator.rb, line 86
def device_type_valid?
  Wor::Push::Notifications::Aws.device_types.include? @device_type
end
message_for_invalid_device_type() click to toggle source
# File lib/wor/push/notifications/aws/validators/push_notifications_validator.rb, line 69
def message_for_invalid_device_type
  "Invalid device_type. It has to be one of the types configured \
   #{Wor::Push::Notifications::Aws.device_types}."
end
message_for_missing_attribute_in_model() click to toggle source
# File lib/wor/push/notifications/aws/validators/push_notifications_validator.rb, line 74
def message_for_missing_attribute_in_model
  'Missing attribute device_tokens for model. Have you run the gem migration?'
end
message_for_nil_device_token() click to toggle source
# File lib/wor/push/notifications/aws/validators/push_notifications_validator.rb, line 78
def message_for_nil_device_token
  'device_token cannot be nil.'
end
message_for_nil_model() click to toggle source
# File lib/wor/push/notifications/aws/validators/push_notifications_validator.rb, line 82
def message_for_nil_model
  'your entity instance cannot be nil.'
end
validate_existence_of_attributes_in_model() click to toggle source
# File lib/wor/push/notifications/aws/validators/push_notifications_validator.rb, line 58
def validate_existence_of_attributes_in_model
  return if @model.has_attribute?(:device_tokens)
  raise Wor::Push::Notifications::Aws::Exceptions::ModelWithoutDeviceTokensAttribute,
        message_for_missing_attribute_in_model
end
validate_model_existance() click to toggle source
# File lib/wor/push/notifications/aws/validators/push_notifications_validator.rb, line 54
def validate_model_existance
  raise ArgumentError, message_for_nil_model if @model.nil?
end
validate_parameters() click to toggle source
# File lib/wor/push/notifications/aws/validators/push_notifications_validator.rb, line 64
def validate_parameters
  raise ArgumentError, message_for_invalid_device_type unless device_type_valid?
  raise ArgumentError, message_for_nil_device_token if @device_token.blank?
end