Class: Chatterbox::Services::Email

Inherits:
Object
  • Object
show all
Defined in:
lib/chatterbox/services/email.rb,
lib/chatterbox/services/email/mailer.rb

Defined Under Namespace

Classes: Mailer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Email

Creates a new Email service with provided options. See Email::deliver for the valid options



39
40
41
42
43
44
# File 'lib/chatterbox/services/email.rb', line 39

def initialize(options = {})
  @options = options
  merge_configs
  merge_message
  validate_options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/chatterbox/services/email.rb', line 6

def options
  @options
end

Class Method Details

.configure(config_options) ⇒ Object

Configure Email service with default options



13
14
15
# File 'lib/chatterbox/services/email.rb', line 13

def self.configure(config_options)
  @default_configuration = config_options.with_indifferent_access
end

.default_configurationObject

Return default configuration - defaults to empty hash



8
9
10
# File 'lib/chatterbox/services/email.rb', line 8

def self.default_configuration
  @default_configuration ||= {}
end

.deliver(options = {}) ⇒ Object

Deliver the a notification via email

Options

  • :summary - The subject of the message - required.

  • :body - The body of the email - if none provided, you will just send an email with a blank body.

  • :config - A sub-hash of configuration options.

    Optional if you have configured a default configuration with #configure. Config can contain any of the following options, all of which are pretty self explanatory:

    :to
    :from
    :content_type
    :reply_to
    :bcc
    :cc
    


33
34
35
# File 'lib/chatterbox/services/email.rb', line 33

def self.deliver(options = {})
  new(options).deliver
end

Instance Method Details

#deliverObject

Deliver a notificaiton – normally you should just use the class level method Email::deliver



47
48
49
# File 'lib/chatterbox/services/email.rb', line 47

def deliver
  Mailer.deliver_message(options)
end