Class: Brightbytes::Sendgrid::Unsubscribe

Inherits:
Object
  • Object
show all
Includes:
SubstPattern
Defined in:
lib/brightbytes/sendgrid/unsubscribe.rb

Constant Summary

Constants included from SubstPattern

SubstPattern::DEFAULT_PATTERN

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sendgrid, message) ⇒ Unsubscribe

Returns a new instance of Unsubscribe.



20
21
22
# File 'lib/brightbytes/sendgrid/unsubscribe.rb', line 20

def initialize(sendgrid, message)
  @sendgrid, @message = sendgrid, message
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



18
19
20
# File 'lib/brightbytes/sendgrid/unsubscribe.rb', line 18

def message
  @message
end

#sendgridObject (readonly)

Returns the value of attribute sendgrid.



17
18
19
# File 'lib/brightbytes/sendgrid/unsubscribe.rb', line 17

def sendgrid
  @sendgrid
end

Class Method Details



11
12
13
# File 'lib/brightbytes/sendgrid/unsubscribe.rb', line 11

def add_links(sendgrid, message)
  new(sendgrid, message).add_links
end

Instance Method Details



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/brightbytes/sendgrid/unsubscribe.rb', line 24

def add_links
  return unless feature_active?
  if categories.present?
    sendgrid.section :unsubscribe_html_section, unsubscribe.html_link % key_to_tag(:unsubscribe_url)
    sendgrid.section :unsubscribe_text_section, unsubscribe.text_link % key_to_tag(:unsubscribe_url)
    emails.each do |email|
      sendgrid.add_substitute :unsubscribe_html, key_to_tag(:unsubscribe_html_section)
      sendgrid.add_substitute :unsubscribe_text, key_to_tag(:unsubscribe_text_section)
      sendgrid.add_substitute :unsubscribe_url,  unsubscribe_url(email)
    end
  else
    sendgrid.add_substitute :unsubscribe_html, Array.new(emails.size, '')
    sendgrid.add_substitute :unsubscribe_text, Array.new(emails.size, '')
    sendgrid.add_substitute :unsubscribe_url,  Array.new(emails.size, '')
  end
end