Class: Porteo::Mail_protocol

Inherits:
Protocol show all
Defined in:
lib/protocols/mail_protocol.rb

Overview

Implementation of email protocol to be used in Porteo system. It only define specific behavior for this protocol.

Constant Summary collapse

MAIL_REQUIRED_FIELDS =

Necessary fields to send a valid email

[:to, :body]

Instance Attribute Summary

Attributes inherited from Protocol

#gw_config, #receiver

Instance Method Summary collapse

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_sectionsnil

Check for all required field to exist and contain valid values. If any required field is missing or its syntax is not valid an ArgumentException is raised.

Returns:

  • (nil)

Raises:

  • (ArgumentError)

    When no template sections are present or no required parameter is given.



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/protocols/mail_protocol.rb', line 49

def check_message_sections
  raise ArgumentError, "Protocol Error. There are no template sections. Maybe you didn't load a complete template" unless @message_sections != nil

  # Check for required fields
  MAIL_REQUIRED_FIELDS.each do |field|
    raise ArgumentError, "Protocol Error. #{field.to_s.capitalize} is a required field for this protocol and it was not defined" unless @message_sections[field] != nil
  end

  # Check for correct syntax
  if not @message_sections[:to] =~ /[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}/
    raise ArgumentError, "Protocol Error. Bad syntax in :to section"
  end
end

#override_tagsnil

Implementates the parent method to ensure that email receptor is the one set at receiver instance variable not the :to template tag

Returns:

  • (nil)


37
38
39
40
41
# File 'lib/protocols/mail_protocol.rb', line 37

def override_tags
  # In mail protocol, the receiver instance variable has precedence over
  # :to tag in template
  @message_sections[:to] = @receiver unless @receiver == nil
end