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.



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

def initialize
  @tos = []
  @ccs = []
  @bccs = []
  @subject = nil
  @headers = {}
  @substitutions = {}
  @custom_args = {}
  @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

#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



27
28
29
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 27

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

#add_cc(cc) ⇒ Object



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

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

#add_custom_arg(custom_arg) ⇒ Object



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

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

#add_header(header) ⇒ Object



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

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

#add_substitution(substitution) ⇒ Object



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

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

#add_to(to) ⇒ Object



19
20
21
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 19

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

#send_atObject



58
59
60
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 58

def send_at
  @send_at
end

#send_at=(send_at) ⇒ Object



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

def send_at=(send_at)
  @send_at = send_at
end

#subjectObject



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

def subject
  @subject
end

#subject=(subject) ⇒ Object



31
32
33
# File 'lib/sendgrid/helpers/mail/personalization.rb', line 31

def subject=(subject)
  @subject = subject
end

#to_jsonObject



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

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,
    'send_at' => self.send_at
  }.delete_if { |_, value| value.to_s.strip == '' || value == [] || value == {}}
end