Class: Porteo::Sms_protocol
- Defined in:
- lib/protocols/sms_protocol.rb
Overview
Implementation of SMS protocol to be used in Porteo system. It only define specific behavior for this protocol.
Instance Attribute Summary
Attributes inherited from Protocol
Instance Method Summary collapse
-
#check_message_sections ⇒ nil
Check for the required fields to exists.
-
#override_tags ⇒ nil
Implementates the parent method to ensure that sms receptor is the one set at receiver instance variable not the :phone template tag.
Methods inherited from Protocol
#initialize, #message, #send_message, #set_template, #set_template_params
Constructor Details
This class inherits a constructor from Porteo::Protocol
Instance Method Details
#check_message_sections ⇒ nil
Check for the required fields to exists.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/protocols/sms_protocol.rb', line 36 def raise ArgumentError, "Protocol Error. There are not text section" if @message_sections[:text] == nil # The sms must match GSM alphabet, double counting these chars # [ , ], <FF>, ^, \, {, }, ~, | and € count = 0 @message_sections[:text].each_char do | c | count = count + 1 if c =~ /[\[\]\^\\\{\}\~\|€]/ count = count + 1 end raise ArgumentError, "Protocol Error. The message is too long" if count > 160 raise ArgumentError, "Protocol Error. The phone number is invalid" unless @message_sections[:phone] =~ /^\d{9}$/ raise ArgumentError, "Protocol Error. The country phone code is invalid" unless @message_sections[:code] =~ /^\d{2,4}$/ raise ArgumentError, "Protocol Error. The sender is invalid" unless @message_sections[:sender] =~ /^[A-Za-z0-9]{1,11}$/ end |
#override_tags ⇒ nil
Implementates the parent method to ensure that sms receptor is the one set at receiver instance variable not the :phone template tag
61 62 63 64 65 |
# File 'lib/protocols/sms_protocol.rb', line 61 def # In sms protocol, the receiver instance variable has precedence over # :phone tag in template @message_sections[:phone] = @receiver unless @receiver == nil end |