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.



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

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.



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

def bccs
  @bccs
end

#ccsObject (readonly)

Returns the value of attribute ccs.



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

def ccs
  @ccs
end

#custom_argsObject (readonly)

Returns the value of attribute custom_args.



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

def custom_args
  @custom_args
end

#dynamic_template_dataObject (readonly)

Returns the value of attribute dynamic_template_data.



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

def dynamic_template_data
  @dynamic_template_data
end

#headersObject (readonly)

Returns the value of attribute headers.



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

def headers
  @headers
end

#substitutionsObject (readonly)

Returns the value of attribute substitutions.



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

def substitutions
  @substitutions
end

#tosObject (readonly)

Returns the value of attribute tos.



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

def tos
  @tos
end

Instance Method Details

#add_bcc(bcc) ⇒ Object



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

def add_bcc(bcc)
  @bccs << bcc.to_json
end

#add_cc(cc) ⇒ Object



25
26
27
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 25

def add_cc(cc)
  @ccs << cc.to_json
end

#add_custom_arg(custom_arg) ⇒ Object



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

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



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

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

#add_header(header) ⇒ Object



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

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

#add_substitution(substitution) ⇒ Object



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

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

#add_to(to) ⇒ Object



21
22
23
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 21

def add_to(to)
  @tos << to.to_json
end

#send_atObject



64
65
66
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 64

def send_at
  @send_at
end

#send_at=(send_at) ⇒ Object



60
61
62
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 60

def send_at=(send_at)
  @send_at = send_at
end

#subjectObject



37
38
39
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 37

def subject
  @subject
end

#subject=(subject) ⇒ Object



33
34
35
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 33

def subject=(subject)
  @subject = subject
end

#to_jsonObject



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 68

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