Class: Smtpapi::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/smtpapi.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHeader

Returns a new instance of Header.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/smtpapi.rb', line 11

def initialize
  @to = []
  @sub = {}
  @section = {}
  @category = []
  @unique_args = {}
  @filters = {}
  @send_at = nil
  @send_each_at = []
  @asm_group_id = nil
  @ip_pool = nil
end

Instance Attribute Details

#asm_group_idObject (readonly)

Returns the value of attribute asm_group_id.



9
10
11
# File 'lib/smtpapi.rb', line 9

def asm_group_id
  @asm_group_id
end

#categoryObject (readonly)

Returns the value of attribute category.



9
10
11
# File 'lib/smtpapi.rb', line 9

def category
  @category
end

#filtersObject (readonly)

Returns the value of attribute filters.



9
10
11
# File 'lib/smtpapi.rb', line 9

def filters
  @filters
end

#ip_poolObject (readonly)

Returns the value of attribute ip_pool.



9
10
11
# File 'lib/smtpapi.rb', line 9

def ip_pool
  @ip_pool
end

#sectionObject (readonly)

Returns the value of attribute section.



9
10
11
# File 'lib/smtpapi.rb', line 9

def section
  @section
end

#send_atObject (readonly)

Returns the value of attribute send_at.



9
10
11
# File 'lib/smtpapi.rb', line 9

def send_at
  @send_at
end

#send_each_atObject (readonly)

Returns the value of attribute send_each_at.



9
10
11
# File 'lib/smtpapi.rb', line 9

def send_each_at
  @send_each_at
end

#subObject (readonly)

Returns the value of attribute sub.



9
10
11
# File 'lib/smtpapi.rb', line 9

def sub
  @sub
end

#toObject (readonly)

Returns the value of attribute to.



9
10
11
# File 'lib/smtpapi.rb', line 9

def to
  @to
end

#unique_argsObject (readonly)

Returns the value of attribute unique_args.



9
10
11
# File 'lib/smtpapi.rb', line 9

def unique_args
  @unique_args
end

Instance Method Details

#add_category(category) ⇒ Object



70
71
72
73
# File 'lib/smtpapi.rb', line 70

def add_category(category)
  @category.push(category)
  self
end

#add_filter(filter_name, parameter_name, parameter_value) ⇒ Object



80
81
82
83
84
85
# File 'lib/smtpapi.rb', line 80

def add_filter(filter_name, parameter_name, parameter_value)
  @filters[filter_name] = {}    if @filters[filter_name] == nil
  @filters[filter_name]['settings'] = {}  if @filters[filter_name]['settings'] == nil
  @filters[filter_name]['settings'][parameter_name] = parameter_value
  self
end

#add_section(key, value) ⇒ Object



50
51
52
53
# File 'lib/smtpapi.rb', line 50

def add_section(key, value)
  @section[key] = value
  self
end

#add_substitution(sub, values) ⇒ Object



40
41
42
43
# File 'lib/smtpapi.rb', line 40

def add_substitution(sub, values)
  @sub[sub] = values
  self
end

#add_to(address, name = nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/smtpapi.rb', line 24

def add_to(address, name=nil)
  if address.is_a?(Array)
    @to.concat(address)
  else
    value = address
    value = "#{name} <#{address}>" if name != nil
    @to.push(value)
  end
  self
end

#add_unique_arg(key, value) ⇒ Object



60
61
62
63
# File 'lib/smtpapi.rb', line 60

def add_unique_arg(key, value)
  @unique_args[key] = value
  self
end

#escape_unicode(str) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
# File 'lib/smtpapi.rb', line 133

def escape_unicode(str)
  str.unpack('U*').map{|i|
    if i > 65535 then
      "\\u#{"%04x" % ((i - 0x10000) / 0x400 + 0xD800)}\\u#{"%04x" % ((i - 0x10000) % 0x400 + 0xDC00)}" if i > 65535
    elsif i > 127 then
      "\\u#{"%04x" % i}"
    else
      i.chr("UTF-8")
    end
  }.join
end

#json_stringObject Also known as: to_json



128
129
130
# File 'lib/smtpapi.rb', line 128

def json_string
  escape_unicode(self.to_array.to_json)
end

#set_asm_group(group_id) ⇒ Object



100
101
102
# File 'lib/smtpapi.rb', line 100

def set_asm_group(group_id)
  @asm_group_id = group_id
end

#set_categories(categories) ⇒ Object



75
76
77
78
# File 'lib/smtpapi.rb', line 75

def set_categories(categories)
  @category = categories
  self
end

#set_filters(filters) ⇒ Object



87
88
89
90
# File 'lib/smtpapi.rb', line 87

def set_filters(filters)
  @filters = filters
  self
end

#set_ip_pool(pool_name) ⇒ Object



104
105
106
# File 'lib/smtpapi.rb', line 104

def set_ip_pool(pool_name)
  @ip_pool = pool_name
end

#set_sections(key_value_pairs) ⇒ Object



55
56
57
58
# File 'lib/smtpapi.rb', line 55

def set_sections(key_value_pairs)
  @section = key_value_pairs
  self
end

#set_send_at(send_at) ⇒ Object



92
93
94
# File 'lib/smtpapi.rb', line 92

def set_send_at(send_at)
  @send_at = send_at
end

#set_send_each_at(send_each_at) ⇒ Object



96
97
98
# File 'lib/smtpapi.rb', line 96

def set_send_each_at(send_each_at)
  @send_each_at = send_each_at
end

#set_substitutions(key_value_pairs) ⇒ Object



45
46
47
48
# File 'lib/smtpapi.rb', line 45

def set_substitutions(key_value_pairs)
  @sub = key_value_pairs
  self
end

#set_tos(addresses) ⇒ Object



35
36
37
38
# File 'lib/smtpapi.rb', line 35

def set_tos(addresses)
  @to = addresses
  self
end

#set_unique_args(key_value_pairs) ⇒ Object



65
66
67
68
# File 'lib/smtpapi.rb', line 65

def set_unique_args(key_value_pairs)
  @unique_args = key_value_pairs
  self
end