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.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/smtpapi.rb', line 13 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.
11 12 13 |
# File 'lib/smtpapi.rb', line 11 def asm_group_id @asm_group_id end |
#category ⇒ Object (readonly)
Returns the value of attribute category.
10 11 12 |
# File 'lib/smtpapi.rb', line 10 def category @category end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
10 11 12 |
# File 'lib/smtpapi.rb', line 10 def filters @filters end |
#ip_pool ⇒ Object (readonly)
Returns the value of attribute ip_pool.
11 12 13 |
# File 'lib/smtpapi.rb', line 11 def ip_pool @ip_pool end |
#section ⇒ Object (readonly)
Returns the value of attribute section.
10 11 12 |
# File 'lib/smtpapi.rb', line 10 def section @section end |
#send_at ⇒ Object (readonly)
Returns the value of attribute send_at.
11 12 13 |
# File 'lib/smtpapi.rb', line 11 def send_at @send_at end |
#send_each_at ⇒ Object (readonly)
Returns the value of attribute send_each_at.
11 12 13 |
# File 'lib/smtpapi.rb', line 11 def send_each_at @send_each_at end |
#sub ⇒ Object (readonly)
Returns the value of attribute sub.
10 11 12 |
# File 'lib/smtpapi.rb', line 10 def sub @sub end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
10 11 12 |
# File 'lib/smtpapi.rb', line 10 def to @to end |
#unique_args ⇒ Object (readonly)
Returns the value of attribute unique_args.
10 11 12 |
# File 'lib/smtpapi.rb', line 10 def unique_args @unique_args end |
Instance Method Details
#add_category(category) ⇒ Object
72 73 74 75 |
# File 'lib/smtpapi.rb', line 72 def add_category(category) @category.push(category) self end |
#add_filter(filter_name, parameter_name, parameter_value) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/smtpapi.rb', line 82 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
52 53 54 55 |
# File 'lib/smtpapi.rb', line 52 def add_section(key, value) @section[key] = value self end |
#add_substitution(sub, values) ⇒ Object
42 43 44 45 |
# File 'lib/smtpapi.rb', line 42 def add_substitution(sub, values) @sub[sub] = values self end |
#add_to(address, name = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/smtpapi.rb', line 26 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
62 63 64 65 |
# File 'lib/smtpapi.rb', line 62 def add_unique_arg(key, value) @unique_args[key] = value self end |
#escape_unicode(str) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/smtpapi.rb', line 119 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))}" elsif i > 127 "\\u#{format('%04x', i)}" else i.chr('UTF-8') end end.join end |
#json_string ⇒ Object Also known as: to_json
114 115 116 |
# File 'lib/smtpapi.rb', line 114 def json_string escape_unicode(to_array.to_json) end |
#set_asm_group(group_id) ⇒ Object
104 105 106 107 |
# File 'lib/smtpapi.rb', line 104 def set_asm_group(group_id) @asm_group_id = group_id self end |
#set_categories(categories) ⇒ Object
77 78 79 80 |
# File 'lib/smtpapi.rb', line 77 def set_categories(categories) @category = categories self end |
#set_filters(filters) ⇒ Object
89 90 91 92 |
# File 'lib/smtpapi.rb', line 89 def set_filters(filters) @filters = filters self end |
#set_ip_pool(pool_name) ⇒ Object
109 110 111 112 |
# File 'lib/smtpapi.rb', line 109 def set_ip_pool(pool_name) @ip_pool = pool_name self end |
#set_sections(key_value_pairs) ⇒ Object
57 58 59 60 |
# File 'lib/smtpapi.rb', line 57 def set_sections(key_value_pairs) @section = key_value_pairs self end |
#set_send_at(send_at) ⇒ Object
94 95 96 97 |
# File 'lib/smtpapi.rb', line 94 def set_send_at(send_at) @send_at = send_at self end |
#set_send_each_at(send_each_at) ⇒ Object
99 100 101 102 |
# File 'lib/smtpapi.rb', line 99 def set_send_each_at(send_each_at) @send_each_at = send_each_at self end |
#set_substitutions(key_value_pairs) ⇒ Object
47 48 49 50 |
# File 'lib/smtpapi.rb', line 47 def set_substitutions(key_value_pairs) @sub = key_value_pairs self end |
#set_tos(addresses) ⇒ Object
37 38 39 40 |
# File 'lib/smtpapi.rb', line 37 def set_tos(addresses) @to = addresses self end |
#set_unique_args(key_value_pairs) ⇒ Object
67 68 69 70 |
# File 'lib/smtpapi.rb', line 67 def set_unique_args(key_value_pairs) @unique_args = key_value_pairs self end |