lib/cm_sms/message.rb in cm-sms-0.1.0 vs lib/cm_sms/message.rb in cm-sms-0.1.1

- old
+ new

@@ -5,10 +5,11 @@ module CmSms class Message class FromMissing < ArgumentError; end class ToMissing < ArgumentError; end class BodyMissing < ArgumentError; end + class BodyToLong < ArgumentError; end class ToUnplausible < ArgumentError; end attr_accessor :from, :to, :body, :dcs, :reference def initialize(attributes = {}) @@ -35,10 +36,14 @@ def body_present? !body.nil? && !body.empty? end + def body_correct_length? + body_present? && body.length <= 160 + end + def product_token_present? !@product_token.nil? && !@product_token.empty? end def request @@ -53,9 +58,10 @@ def deliver! raise FromMissing.new('The from attribute is missing.') unless sender_present? raise ToMissing.new('The to attribute is missing.') unless receiver_present? raise BodyMissing.new('The body of the message is missing.') unless body_present? + raise BodyToLong.new('The body of the message has a length greater than 160.') unless body_correct_length? raise ToUnplausible.new("THe given to attribute is not a plausible phone number.\nMaybe the country code is missing.") unless receiver_plausible? deliver end \ No newline at end of file