Module: Talktome
- Defined in:
- lib/talktome.rb,
lib/talktome/app.rb,
lib/talktome/error.rb,
lib/talktome/client.rb,
lib/talktome/message.rb,
lib/talktome/version.rb,
lib/talktome/strategy.rb,
lib/talktome/client/local.rb,
lib/talktome/strategy/debug.rb,
lib/talktome/strategy/email.rb
Defined Under Namespace
Modules: Version
Classes: App, Client, Error, InvalidEmailError, InvalidMessageError, Message, Strategy, TemplateNotFoundError
Constant Summary
collapse
- VERSION =
"#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
Class Method Summary
collapse
Class Method Details
.auto_options(folder) ⇒ Object
Infer all client and strategy options from environment variables.
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/talktome.rb', line 40
def auto_options(folder)
options = {}
debug_folder = folder/"tmp"
options[:debugger] = ->(message, user, handler) {
debug_folder.mkdir_p unless debug_folder.exists?
(debug_folder/"#{user[:email]}.html").write(message.to_html)
(debug_folder/"#{user[:email]}.txt").write(message.to_text)
} if ENV['TALKTOME_DEBUG']
options[:strategies] = {}
email_delivery = (ENV['TALKTOME_EMAIL_DELIVERY'] || "test").to_sym
email_config = {}
email_config.merge!({
address: ENV['TALKTOME_SMTP_ADDRESS'],
port: ENV['TALKTOME_SMTP_PORT'].to_i,
domain: ENV['TALKTOME_SMTP_DOMAIN'],
user_name: ENV['TALKTOME_SMTP_USER'],
password: ENV['TALKTOME_SMTP_PASSWORD'],
enable_starttls_auto: (ENV['TALKTOME_SMTP_STARTTLS_AUTO'] != 'false'),
openssl_verify_mode: ENV['TALKTOME_SMTP_OPENSSL_VERIFY_MODE'] || "peer",
}) if email_delivery == :smtp
email_config.merge!({
location: debug_folder.mkdir_p
}) if email_delivery == :file
options[:strategies][:email] = ::Talktome::Strategy::Email.new{|email|
email.delivery_method(email_delivery, email_config)
with_env('TALKTOME_EMAIL_DEFAULT_FROM'){|default|
email.from(default)
}
with_env('TALKTOME_EMAIL_DEFAULT_TO'){|default|
email.to(default)
}
with_env('TALKTOME_EMAIL_DEFAULT_REPLYTO'){|default|
email.reply_to(default)
}
}
if layouts_folder = ENV['TALKTOME_LAYOUTS_FOLDER']
options[:layouts] = Path(layouts_folder)
end
options
end
|
.env(which, default = nil) ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/talktome.rb', line 10
def env(which, default = nil)
if ENV.has_key?(which)
got = ENV[which].to_s.strip
return got unless got.empty?
end
default
end
|
.redcarpet ⇒ Object
34
35
36
|
# File 'lib/talktome.rb', line 34
def redcarpet
@redcarpet ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, extensions = {})
end
|
.set_env(which, value, &bl) ⇒ Object
26
27
28
29
30
31
|
# File 'lib/talktome.rb', line 26
def set_env(which, value, &bl)
old, ENV[which] = ENV[which], value
bl.call.tap{
ENV[which] = old
}
end
|
.with_env(which, &bl) ⇒ Object
19
20
21
22
23
|
# File 'lib/talktome.rb', line 19
def with_env(which, &bl)
env(which).tap{|x|
bl.call(x) unless x.nil?
}
end
|