class ActionTexter::Validator::Message

Attributes

message[R]

Public Class Methods

new(message) click to toggle source
# File lib/action_texter/validator/message.rb, line 13
def initialize(message)
  @message = message

  fail FromMissing, 'The value for the from attribute is missing.' unless sender_present?
  fail FromTooLong, 'The value for the sender attribute must contain 1..11 characters.' unless sender_length?
  fail ToMissing, 'The value for the to attribute is missing.' unless receiver_present?
  fail BodyMissing, 'The body of the message is missing.' unless body_present?
  fail BodyTooLong, 'The body of the message has a length greater than 160.' unless body_correct_length?
  fail ToUnplausible, "The given value for the to attribute is not a plausible phone number.\nMaybe the country code is missing." unless receiver_plausible?
end

Public Instance Methods

body_correct_length?() click to toggle source
# File lib/action_texter/validator/message.rb, line 44
def body_correct_length?
  body_present? && message.body.length <= 160
end
body_present?() click to toggle source
# File lib/action_texter/validator/message.rb, line 40
def body_present?
  !message.body.nil? && !message.body.empty?
end
product_token_present?() click to toggle source
# File lib/action_texter/validator/message.rb, line 48
def product_token_present?
  !ActionTexter.config.product_token.nil? && !ActionTexter.config.product_token.empty?
end
receiver_plausible?() click to toggle source
# File lib/action_texter/validator/message.rb, line 24
def receiver_plausible?
  receiver_present? && Phony.plausible?(message.to)
end
receiver_present?() click to toggle source
# File lib/action_texter/validator/message.rb, line 28
def receiver_present?
  !message.to.nil? && !message.to.empty?
end
sender_length?() click to toggle source
# File lib/action_texter/validator/message.rb, line 36
def sender_length?
  sender_present? && message.from.length <= 11
end
sender_present?() click to toggle source
# File lib/action_texter/validator/message.rb, line 32
def sender_present?
  !message.from.nil? && !message.from.empty?
end