Class: MailEngine::Sendgrid::SmtpApi

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_engine/sendgrid/smtp_api.rb

Overview

smtp api class

Instance Method Summary collapse

Constructor Details

#initializeSmtpApi

Returns a new instance of SmtpApi.



43
44
45
# File 'lib/mail_engine/sendgrid/smtp_api.rb', line 43

def initialize()
  @data = {}
end

Instance Method Details

#add_sub_val(var, val) ⇒ Object



71
72
73
74
# File 'lib/mail_engine/sendgrid/smtp_api.rb', line 71

def add_sub_val(var, val)
  @data['sub'] ||= {}
  @data['sub'][var] = Array.wrap(val)
end

#add_to(to) ⇒ Object



65
66
67
68
69
# File 'lib/mail_engine/sendgrid/smtp_api.rb', line 65

def add_to(to)
  @data['to'] ||= []
  @data['to'] += Array.wrap(to)
  @data['to'].uniq!
end

#category(cat) ⇒ Object



47
48
49
# File 'lib/mail_engine/sendgrid/smtp_api.rb', line 47

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

#filters(&block) ⇒ Object



51
52
53
54
55
# File 'lib/mail_engine/sendgrid/smtp_api.rb', line 51

def filters(&block)
  filter_setting = FilterSetting.new
  filter_setting.instance_eval(&block)
  @data["filters"] = filter_setting.data
end

#set_send_to(to) ⇒ Object

for now only allow to send to one receiver once. maybe we don’t like people received a mail which allow people to view all receivers



59
60
61
62
63
# File 'lib/mail_engine/sendgrid/smtp_api.rb', line 59

def set_send_to(to)
  @data['to'] ||= []
  @data['to'] = Array.wrap(to)
  @data['to'].uniq!
end

#set_unique_args(val) ⇒ Object



76
77
78
# File 'lib/mail_engine/sendgrid/smtp_api.rb', line 76

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

#to_hashObject



84
85
86
# File 'lib/mail_engine/sendgrid/smtp_api.rb', line 84

def to_hash
  {'X-SMTPAPI' => self.to_json}
end

#to_jsonObject



80
81
82
# File 'lib/mail_engine/sendgrid/smtp_api.rb', line 80

def to_json
  @data.to_json.gsub(/(["\]}])([,:])(["\[{])/, '\\1\\2 \\3')
end

#to_sObject



88
89
90
# File 'lib/mail_engine/sendgrid/smtp_api.rb', line 88

def to_s
  'X-SMTPAPI: %s' % self.to_json
end