Class: MailSlackBot::Daemon
- Inherits:
-
DaemonSpawn::Base
- Object
- DaemonSpawn::Base
- MailSlackBot::Daemon
- Defined in:
- lib/mail_slack_bot.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.config ⇒ Object
22 23 24 |
# File 'lib/mail_slack_bot.rb', line 22 def config @configuration end |
.configure {|@configuration| ... } ⇒ Object
16 17 18 19 20 |
# File 'lib/mail_slack_bot.rb', line 16 def configure @configuration = Configatron::RootStore.new @configuration.mail = Mail::Configuration.instance yield(@configuration) end |
Instance Method Details
#manipulate(mail, slack_client) ⇒ Object
44 45 46 47 |
# File 'lib/mail_slack_bot.rb', line 44 def manipulate(mail, slack_client) slack_client.ping mail.body.decoded.encode("UTF-8", undef: :replace, invalid: :replace), pretext: mail.subject end |
#start(args) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mail_slack_bot.rb', line 28 def start(args) @config = self.class.config sleep_time = @config.mail_check_interval || 10 slack_client = Slack::Notifier.new(@config.slack.team, @config.slack.token, channel: @config.slack.channel, username: @config.slack.username) loop do $logger.debug("Feching mail.") Mail.all.each do |mail| $logger.debug mail.subject $logger.debug mail.body.decoded manipulate(mail, slack_client) end sleep sleep_time end end |
#stop ⇒ Object
49 50 |
# File 'lib/mail_slack_bot.rb', line 49 def stop end |