Class: SmtpApiHeader
- Inherits:
-
Object
- Object
- SmtpApiHeader
- Defined in:
- lib/smtp_api_header.rb
Instance Method Summary collapse
- #addFilterSetting(fltr, setting, val) ⇒ Object
- #addSubVal(var, val) ⇒ Object
- #addTo(to) ⇒ Object
- #as_string ⇒ Object
- #asJSON ⇒ Object
-
#initialize ⇒ SmtpApiHeader
constructor
A new instance of SmtpApiHeader.
- #setCategory(cat) ⇒ Object
- #setUniqueArgs(val) ⇒ Object
Constructor Details
#initialize ⇒ SmtpApiHeader
Returns a new instance of SmtpApiHeader.
5 6 7 |
# File 'lib/smtp_api_header.rb', line 5 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/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
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/smtp_api_header.rb', line 20 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
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/smtp_api_header.rb', line 9 def addTo(to) if not @data['to'] @data['to'] = [] end if to.instance_of?(Array) @data['to'] = @data['to'] | to else @data['to'].push to end end |
#as_string ⇒ Object
60 61 62 63 64 |
# File 'lib/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 |
#asJSON ⇒ Object
55 56 57 58 |
# File 'lib/smtp_api_header.rb', line 55 def asJSON() json = @data.to_json return json.gsub(/(["\]}])([,:])(["\[{])/, '\\1\\2 \\3') end |
#setCategory(cat) ⇒ Object
37 38 39 40 |
# File 'lib/smtp_api_header.rb', line 37 def setCategory(cat) @data['category'] = cat end |
#setUniqueArgs(val) ⇒ Object
31 32 33 34 35 |
# File 'lib/smtp_api_header.rb', line 31 def setUniqueArgs(val) if val.instance_of?(Hash) @data['unique_args'] = val end end |