Class: MailSpy::Sendgrid::SmtpApiHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_spy/sendgrid/smtp_api_header.rb

Instance Method Summary collapse

Constructor Details

#initializeSmtpApiHeader

Returns a new instance of SmtpApiHeader.



12
13
14
# File 'lib/mail_spy/sendgrid/smtp_api_header.rb', line 12

def initialize()
  @data = {}
end

Instance Method Details

#addFilterSetting(fltr, setting, val) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mail_spy/sendgrid/smtp_api_header.rb', line 42

def addFilterSetting(fltr, setting, val)
  if not @data['filters']
    @data['filters'] = {}
  end
  if not @data['filters'][fltr]
    @data['filters'][fltr] = {}
  end
  if not @data['filters'][fltr]['settings']
    @data['filters'][fltr]['settings'] = {}
  end
  @data['filters'][fltr]['settings'][setting] = val
end

#addSubVal(var, val) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/mail_spy/sendgrid/smtp_api_header.rb', line 21

def addSubVal(var, val)
  if not @data['sub']
    @data['sub'] = {}
  end
  if val.instance_of?(Array)
    @data['sub'][var] = val
  else
    @data['sub'][var] = [val]
  end
end

#addTo(to) ⇒ Object



16
17
18
19
# File 'lib/mail_spy/sendgrid/smtp_api_header.rb', line 16

def addTo(to)
  @data['to'] ||= []
  @data['to'] += to.kind_of?(Array) ? to : [to]
end

#as_stringObject



60
61
62
63
64
# File 'lib/mail_spy/sendgrid/smtp_api_header.rb', line 60

def as_string()
  json = asJSON()
  str = 'X-SMTPAPI: %s' % json.gsub(/(.{1,72})( +|$\n?)|(.{1,72})/, "\\1\\3\n")
  return str
end

#asJSONObject



55
56
57
58
# File 'lib/mail_spy/sendgrid/smtp_api_header.rb', line 55

def asJSON()
  json = JSON.generate @data
  return json.gsub(/(["\]}])([,:])(["\[{])/, '\\1\\2 \\3')
end

#setCategory(cat) ⇒ Object



38
39
40
# File 'lib/mail_spy/sendgrid/smtp_api_header.rb', line 38

def setCategory(cat)
  @data['category'] = cat
end

#setUniqueArgs(val) ⇒ Object



32
33
34
35
36
# File 'lib/mail_spy/sendgrid/smtp_api_header.rb', line 32

def setUniqueArgs(val)
  if val.instance_of?(Hash)
    @data['unique_args'] = val
  end
end