Class: Smtpapi::Header
- Inherits:
-
Object
- Object
- Smtpapi::Header
- Defined in:
- lib/smtpapi.rb
Overview
SendGrid smtpapi header implementation
Instance Attribute Summary collapse
-
#asm_group_id ⇒ Object
readonly
Returns the value of attribute asm_group_id.
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#ip_pool ⇒ Object
readonly
Returns the value of attribute ip_pool.
-
#section ⇒ Object
readonly
Returns the value of attribute section.
-
#send_at ⇒ Object
readonly
Returns the value of attribute send_at.
-
#send_each_at ⇒ Object
readonly
Returns the value of attribute send_each_at.
-
#sub ⇒ Object
readonly
Returns the value of attribute sub.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
-
#unique_args ⇒ Object
readonly
Returns the value of attribute unique_args.
Instance Method Summary collapse
- #add_category(category) ⇒ Object
- #add_filter(filter_name, parameter_name, parameter_value) ⇒ Object
- #add_section(key, value) ⇒ Object
- #add_substitution(sub, values) ⇒ Object
- #add_to(address, name = nil) ⇒ Object
- #add_unique_arg(key, value) ⇒ Object
- #escape_unicode(str) ⇒ Object
-
#initialize ⇒ Header
constructor
A new instance of Header.
- #json_string ⇒ Object (also: #to_json)
- #set_asm_group(group_id) ⇒ Object
- #set_categories(categories) ⇒ Object
- #set_filters(filters) ⇒ Object
- #set_ip_pool(pool_name) ⇒ Object
- #set_sections(key_value_pairs) ⇒ Object
- #set_send_at(send_at) ⇒ Object
- #set_send_each_at(send_each_at) ⇒ Object
- #set_substitutions(key_value_pairs) ⇒ Object
- #set_tos(addresses) ⇒ Object
- #set_unique_args(key_value_pairs) ⇒ Object
Constructor Details
#initialize ⇒ Header
Returns a new instance of Header.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/smtpapi.rb', line 14 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_id ⇒ Object (readonly)
Returns the value of attribute asm_group_id.
12 13 14 |
# File 'lib/smtpapi.rb', line 12 def asm_group_id @asm_group_id end |
#category ⇒ Object (readonly)
Returns the value of attribute category.
11 12 13 |
# File 'lib/smtpapi.rb', line 11 def category @category end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
11 12 13 |
# File 'lib/smtpapi.rb', line 11 def filters @filters end |
#ip_pool ⇒ Object (readonly)
Returns the value of attribute ip_pool.
12 13 14 |
# File 'lib/smtpapi.rb', line 12 def ip_pool @ip_pool end |
#section ⇒ Object (readonly)
Returns the value of attribute section.
11 12 13 |
# File 'lib/smtpapi.rb', line 11 def section @section end |
#send_at ⇒ Object (readonly)
Returns the value of attribute send_at.
12 13 14 |
# File 'lib/smtpapi.rb', line 12 def send_at @send_at end |
#send_each_at ⇒ Object (readonly)
Returns the value of attribute send_each_at.
12 13 14 |
# File 'lib/smtpapi.rb', line 12 def send_each_at @send_each_at end |
#sub ⇒ Object (readonly)
Returns the value of attribute sub.
11 12 13 |
# File 'lib/smtpapi.rb', line 11 def sub @sub end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
11 12 13 |
# File 'lib/smtpapi.rb', line 11 def to @to end |
#unique_args ⇒ Object (readonly)
Returns the value of attribute unique_args.
11 12 13 |
# File 'lib/smtpapi.rb', line 11 def unique_args @unique_args end |
Instance Method Details
#add_category(category) ⇒ Object
73 74 75 76 |
# File 'lib/smtpapi.rb', line 73 def add_category(category) @category.push(category) self end |
#add_filter(filter_name, parameter_name, parameter_value) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/smtpapi.rb', line 83 def add_filter(filter_name, parameter_name, parameter_value) @filters[filter_name] = {} if @filters[filter_name].nil? if @filters[filter_name]['settings'].nil? @filters[filter_name]['settings'] = {} end @filters[filter_name]['settings'][parameter_name] = parameter_value self end |
#add_section(key, value) ⇒ Object
53 54 55 56 |
# File 'lib/smtpapi.rb', line 53 def add_section(key, value) @section[key] = value self end |
#add_substitution(sub, values) ⇒ Object
43 44 45 46 |
# File 'lib/smtpapi.rb', line 43 def add_substitution(sub, values) @sub[sub] = values self end |
#add_to(address, name = nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/smtpapi.rb', line 27 def add_to(address, name = nil) if address.is_a?(Array) @to.concat(address) else value = address value = "#{name} <#{address}>" unless name.nil? @to.push(value) end self end |
#add_unique_arg(key, value) ⇒ Object
63 64 65 66 |
# File 'lib/smtpapi.rb', line 63 def add_unique_arg(key, value) @unique_args[key] = value self end |
#escape_unicode(str) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/smtpapi.rb', line 143 def escape_unicode(str) str.unpack('U*').map do |i| if i > 65_535 "\\u#{format('%04x', ((i - 0x10000) / 0x400 + 0xD800))}"\ "\\u#{format('%04x', ((i - 0x10000) % 0x400 + 0xDC00))}" if i > 65_535 elsif i > 127 "\\u#{format('%04x', i)}" else i.chr('UTF-8') end end.join end |
#json_string ⇒ Object Also known as: to_json
138 139 140 |
# File 'lib/smtpapi.rb', line 138 def json_string escape_unicode(to_array.to_json) end |
#set_asm_group(group_id) ⇒ Object
107 108 109 110 |
# File 'lib/smtpapi.rb', line 107 def set_asm_group(group_id) @asm_group_id = group_id self end |
#set_categories(categories) ⇒ Object
78 79 80 81 |
# File 'lib/smtpapi.rb', line 78 def set_categories(categories) @category = categories self end |
#set_filters(filters) ⇒ Object
92 93 94 95 |
# File 'lib/smtpapi.rb', line 92 def set_filters(filters) @filters = filters self end |
#set_ip_pool(pool_name) ⇒ Object
112 113 114 115 |
# File 'lib/smtpapi.rb', line 112 def set_ip_pool(pool_name) @ip_pool = pool_name self end |
#set_sections(key_value_pairs) ⇒ Object
58 59 60 61 |
# File 'lib/smtpapi.rb', line 58 def set_sections(key_value_pairs) @section = key_value_pairs self end |
#set_send_at(send_at) ⇒ Object
97 98 99 100 |
# File 'lib/smtpapi.rb', line 97 def set_send_at(send_at) @send_at = send_at self end |
#set_send_each_at(send_each_at) ⇒ Object
102 103 104 105 |
# File 'lib/smtpapi.rb', line 102 def set_send_each_at(send_each_at) @send_each_at = send_each_at self end |
#set_substitutions(key_value_pairs) ⇒ Object
48 49 50 51 |
# File 'lib/smtpapi.rb', line 48 def set_substitutions(key_value_pairs) @sub = key_value_pairs self end |
#set_tos(addresses) ⇒ Object
38 39 40 41 |
# File 'lib/smtpapi.rb', line 38 def set_tos(addresses) @to = addresses self end |
#set_unique_args(key_value_pairs) ⇒ Object
68 69 70 71 |
# File 'lib/smtpapi.rb', line 68 def set_unique_args(key_value_pairs) @unique_args = key_value_pairs self end |