mail_slack_bot 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4581dd45cb7cf946c399536d80e758ef7a70f852
4
- data.tar.gz: 730159ee7f36667a8101fea647f5deb7802dc837
3
+ metadata.gz: c4c9541b06f5c2cc31f470170dd2564d47cd74e6
4
+ data.tar.gz: dcafe84c0ce77d698cba45ca8876bb8c88e5d1ff
5
5
  SHA512:
6
- metadata.gz: 526578eac58a4011768d3b54761ce7a5b697422175315460dc36316e62d918c99c2cbe17943818eaba1e6746402fefd1e420ccc36621747988a8dc19c65bc804
7
- data.tar.gz: 7dc317349449f08460c32d38debd0b5c07f670d0aa65d202704112b685958ee339a71381750581dd6219c4ab54b8640f936cbcf0cdac192857a6594180dd3898
6
+ metadata.gz: 906fd085f05f2f772e124abf447afb8fda1ae788b8df6366f9e325c20dde36615d882c15b5ce24728c6c8dea1570960884f79c07002cb76f980e0f5855476629
7
+ data.tar.gz: 1077657d70eec30e09c84a383c49c9354ea7890a39ac25c5379e08a8b75037542b802cb6fbaa64255998bcf1d8a612a0991c28830cebacccbae25e2707d548d5
@@ -1,3 +1,3 @@
1
- module MailSlackBot
2
- VERSION = "0.0.2"
1
+ class MailSlackBot
2
+ VERSION = "0.0.3"
3
3
  end
@@ -5,49 +5,42 @@ require 'slack-notifier'
5
5
  require 'daemon_spawn'
6
6
  require 'logger'
7
7
 
8
- module MailSlackBot
8
+ class MailSlackBot
9
9
 
10
- class Daemon < DaemonSpawn::Base
10
+ class << self
11
11
 
12
- $logger = Logger.new(STDOUT)
13
-
14
- class << self
15
-
16
- def configure
17
- @configuration = Configatron::RootStore.new
18
- @configuration.mail = Mail::Configuration.instance
19
- yield(@configuration)
20
- end
21
-
22
- def config
23
- @configuration
24
- end
12
+ attr_reader :config
25
13
 
14
+ def configure
15
+ @config = Configatron::RootStore.new
16
+ @config.mail = Mail::Configuration.instance
17
+ @config.logger = Logger.new(STDOUT)
18
+ yield(@config)
26
19
  end
27
20
 
28
- def start(args)
29
- @config = self.class.config
30
- sleep_time = @config.mail_check_interval || 10
31
- slack_client = Slack::Notifier.new(@config.slack.team, @config.slack.token,
32
- channel: @config.slack.channel, username: @config.slack.username)
33
- loop do
34
- $logger.debug("Feching mail.")
35
- Mail.all.each do |mail|
36
- $logger.debug mail.subject
37
- $logger.debug mail.body.decoded
38
- manipulate(mail, slack_client)
39
- end
40
- sleep sleep_time
41
- end
42
- end
21
+ end
43
22
 
44
- def manipulate(mail, slack_client)
45
- slack_client.ping mail.body.decoded.encode("UTF-8", undef: :replace, invalid: :replace),
46
- pretext: mail.subject
47
- end
48
-
49
- def stop
23
+ def run
24
+ @config = self.class.config
25
+ yield(@config) if block_given?
26
+ @logger = @config.logger
27
+ sleep_time = @config.mail_check_interval || 10
28
+ slack_client = Slack::Notifier.new(@config.slack.team, @config.slack.token,
29
+ channel: @config.slack.channel, username: @config.slack.username)
30
+ loop do
31
+ @logger.debug("Feching mail.")
32
+ Mail.all.each do |mail|
33
+ @logger.debug mail.subject
34
+ @logger.debug mail.body.decoded
35
+ manipulate(mail, slack_client)
36
+ end
37
+ sleep sleep_time
50
38
  end
39
+ end
51
40
 
41
+ def manipulate(mail, slack_client)
42
+ slack_client.ping mail.body.decoded.encode("UTF-8", undef: :replace, invalid: :replace),
43
+ pretext: mail.subject
52
44
  end
45
+
53
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail_slack_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shintaro Kimura