Class: SendGrid::Personalization

Inherits:
Object
  • Object
show all
Defined in:
lib/sendgrid/helpers/mail/personalization.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePersonalization

Returns a new instance of Personalization.


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 10

def initialize
  @tos = []
  @ccs = []
  @bccs = []
  @subject = nil
  @headers = {}
  @substitutions = {}
  @custom_args = {}
  @dynamic_template_data = {}
  @send_at = nil
end

Instance Attribute Details

#bccsObject (readonly)

Returns the value of attribute bccs


5
6
7
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 5

def bccs
  @bccs
end

#ccsObject (readonly)

Returns the value of attribute ccs


5
6
7
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 5

def ccs
  @ccs
end

#custom_argsObject (readonly)

Returns the value of attribute custom_args


5
6
7
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 5

def custom_args
  @custom_args
end

#dynamic_template_dataObject (readonly)

Returns the value of attribute dynamic_template_data


5
6
7
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 5

def dynamic_template_data
  @dynamic_template_data
end

#headersObject (readonly)

Returns the value of attribute headers


5
6
7
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 5

def headers
  @headers
end

#send_atObject

Returns the value of attribute send_at


8
9
10
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 8

def send_at
  @send_at
end

#subjectObject

Returns the value of attribute subject


8
9
10
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 8

def subject
  @subject
end

#substitutionsObject (readonly)

Returns the value of attribute substitutions


5
6
7
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 5

def substitutions
  @substitutions
end

#tosObject (readonly)

Returns the value of attribute tos


5
6
7
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 5

def tos
  @tos
end

Instance Method Details

#add_bcc(bcc) ⇒ Object


34
35
36
37
38
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 34

def add_bcc(bcc)
  raise DuplicatePersonalizationError if duplicate?(bcc)

  @bccs << bcc.to_json
end

#add_cc(cc) ⇒ Object


28
29
30
31
32
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 28

def add_cc(cc)
  raise DuplicatePersonalizationError if duplicate?(cc)

  @ccs << cc.to_json
end

#add_custom_arg(custom_arg) ⇒ Object


50
51
52
53
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 50

def add_custom_arg(custom_arg)
  custom_arg = custom_arg.to_json
  @custom_args = @custom_args.merge(custom_arg['custom_arg'])
end

#add_dynamic_template_data(dynamic_template_data) ⇒ Object


55
56
57
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 55

def add_dynamic_template_data(dynamic_template_data)
  @dynamic_template_data.merge!(dynamic_template_data)
end

#add_header(header) ⇒ Object


40
41
42
43
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 40

def add_header(header)
  header = header.to_json
  @headers = @headers.merge(header['header'])
end

#add_substitution(substitution) ⇒ Object


45
46
47
48
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 45

def add_substitution(substitution)
  substitution = substitution.to_json
  @substitutions = @substitutions.merge(substitution['substitution'])
end

#add_to(to) ⇒ Object


22
23
24
25
26
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 22

def add_to(to)
  raise DuplicatePersonalizationError if duplicate?(to)

  @tos << to.to_json
end

#to_jsonObject


59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 59

def to_json(*)
  {
    'to' => tos,
    'cc' => ccs,
    'bcc' => bccs,
    'subject' => subject,
    'headers' => headers,
    'substitutions' => substitutions,
    'custom_args' => custom_args,
    'dynamic_template_data' => dynamic_template_data,
    'send_at' => send_at
  }.delete_if { |_, value| value.to_s.strip == '' || value == [] || value == {} }
end