Class: Brightbytes::Sendgrid::SmtpApiHeader
- Inherits:
-
Object
- Object
- Brightbytes::Sendgrid::SmtpApiHeader
- Defined in:
- lib/brightbytes/sendgrid/smtp_api_header.rb
Constant Summary collapse
- DELEGATE_METHODS =
[ :substitute, :add_substitute, :section, :unique_args, :categories, :add_categories, :recipients, :add_recipients, :filter_setting, :enable, :disable, :ganalytics_options, :bcc ]
- VALID_FILTERS =
[ :bcc, :dkim, :domainkeys, :forwardspam, :opentrack, :clicktrack, :ganalytics, :gravatar, :subscriptiontrack, :template, :footer, :spamcheck, :bypass_list_management ]
- VALID_GANALYTICS_OPTIONS =
[ :utm_source, :utm_medium, :utm_campaign, :utm_term, :utm_content ]
- SUBST_PATTERN =
'{{\1}}'
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #add_categories(*categories) ⇒ Object
- #add_recipients(*recipients) ⇒ Object
- #add_substitute(key, values) ⇒ Object
- #bcc(email) ⇒ Object
-
#categories(*categories) ⇒ Object
getter/setter.
- #disable(*filters) ⇒ Object
- #enable(*filters) ⇒ Object
- #filter_setting(filter, setting, value) ⇒ Object
- #ganalytics_options(options = {}) ⇒ Object
-
#initialize(default_data = nil) ⇒ SmtpApiHeader
constructor
A new instance of SmtpApiHeader.
-
#recipients(*recipients) ⇒ Object
getter/setter.
- #section(key, value) ⇒ Object
- #substitute(key, values) ⇒ Object
- #to_json ⇒ Object
- #unique_args(value) ⇒ Object
Constructor Details
#initialize(default_data = nil) ⇒ SmtpApiHeader
Returns a new instance of SmtpApiHeader.
51 52 53 |
# File 'lib/brightbytes/sendgrid/smtp_api_header.rb', line 51 def initialize(default_data = nil) @data = default_data.instance_of?(Hash) ? default_data.dup : Hash.new { |h,k| h[k] = Hash.new(&h.default_proc) } end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
49 50 51 |
# File 'lib/brightbytes/sendgrid/smtp_api_header.rb', line 49 def data @data end |
Instance Method Details
#add_categories(*categories) ⇒ Object
78 79 80 81 |
# File 'lib/brightbytes/sendgrid/smtp_api_header.rb', line 78 def add_categories(*categories) init_array_key :category @data[:category] |= categories.flatten.map(&:to_sym) end |
#add_recipients(*recipients) ⇒ Object
89 90 91 92 |
# File 'lib/brightbytes/sendgrid/smtp_api_header.rb', line 89 def add_recipients(*recipients) init_array_key :to @data[:to] += recipients.flatten end |
#add_substitute(key, values) ⇒ Object
59 60 61 62 |
# File 'lib/brightbytes/sendgrid/smtp_api_header.rb', line 59 def add_substitute(key, values) @data[:sub][key_to_tag(key)] = [] unless @data[:sub][key_to_tag(key)].instance_of?(Array) @data[:sub][key_to_tag(key)] += Array.wrap(values) end |
#bcc(email) ⇒ Object
115 116 117 118 |
# File 'lib/brightbytes/sendgrid/smtp_api_header.rb', line 115 def bcc(email) filter_setting :bcc, :email, email enable :bcc end |
#categories(*categories) ⇒ Object
getter/setter
73 74 75 76 |
# File 'lib/brightbytes/sendgrid/smtp_api_header.rb', line 73 def categories(*categories) @data[:category] = categories.flatten.map(&:to_sym) if categories.flatten.present? @data.fetch(:category, []) end |
#disable(*filters) ⇒ Object
103 104 105 |
# File 'lib/brightbytes/sendgrid/smtp_api_header.rb', line 103 def disable(*filters) filters.flatten.each { |filter| filter_setting filter, :enabled, 0 } end |
#enable(*filters) ⇒ Object
99 100 101 |
# File 'lib/brightbytes/sendgrid/smtp_api_header.rb', line 99 def enable(*filters) filters.flatten.each { |filter| filter_setting filter, :enabled, 1 } end |
#filter_setting(filter, setting, value) ⇒ Object
94 95 96 97 |
# File 'lib/brightbytes/sendgrid/smtp_api_header.rb', line 94 def filter_setting(filter, setting, value) return unless VALID_FILTERS.include? filter @data[:filters][filter][:settings][setting] = value end |
#ganalytics_options(options = {}) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/brightbytes/sendgrid/smtp_api_header.rb', line 107 def ( = {}) .reject! { |k,v| !VALID_GANALYTICS_OPTIONS.include?(k) } if .present? .each { |setting, value| filter_setting :ganalytics, setting, value } enable :ganalytics end end |
#recipients(*recipients) ⇒ Object
getter/setter
84 85 86 87 |
# File 'lib/brightbytes/sendgrid/smtp_api_header.rb', line 84 def recipients(*recipients) @data[:to] = recipients.flatten if recipients.flatten.present? @data.fetch(:to, []) end |
#section(key, value) ⇒ Object
64 65 66 |
# File 'lib/brightbytes/sendgrid/smtp_api_header.rb', line 64 def section(key, value) @data[:section][key_to_tag(key)] = value.to_s end |
#substitute(key, values) ⇒ Object
55 56 57 |
# File 'lib/brightbytes/sendgrid/smtp_api_header.rb', line 55 def substitute(key, values) @data[:sub][key_to_tag(key)] = Array.wrap(values) end |
#to_json ⇒ Object
120 121 122 |
# File 'lib/brightbytes/sendgrid/smtp_api_header.rb', line 120 def to_json JSON.generate(@data, {indent: '', space: ' ', space_before: '', object_nl: '', array_nl: ''}) end |
#unique_args(value) ⇒ Object
68 69 70 |
# File 'lib/brightbytes/sendgrid/smtp_api_header.rb', line 68 def unique_args(value) @data[:unique_args] = value if value.instance_of?(Hash) end |