slack_messaging 2.1.0 → 3.1.1
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 +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +129 -0
- data/Guardfile +3 -1
- data/README.md +33 -19
- data/Rakefile +2 -0
- data/bin/slack-messaging +22 -10
- data/lib/slack_messaging.rb +6 -2
- data/lib/slack_messaging/config.rb +20 -17
- data/lib/slack_messaging/default_paths.rb +9 -7
- data/lib/slack_messaging/notify_slack.rb +2 -0
- data/lib/slack_messaging/random_message.rb +3 -1
- data/lib/slack_messaging/send.rb +24 -0
- data/lib/slack_messaging/setup.rb +84 -0
- data/lib/slack_messaging/version.rb +3 -1
- data/spec/slack_messaging/config_spec.rb +22 -18
- data/spec/slack_messaging/notify_slack_spec.rb +17 -15
- data/spec/slack_messaging/random_message_spec.rb +9 -5
- data/spec/slack_messaging/setup_spec.rb +136 -0
- data/spec/spec_helper.rb +3 -1
- metadata +26 -9
- data/lib/slack_messaging/slack.rb +0 -22
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 12ec2e4beafc03f085a3a1752070bce7e030cd02e1e57378229400f39a2284ee
|
|
4
|
+
data.tar.gz: f6c4e26dcb8799058f144e24aee9ddf1d4f2f05c0b91deba9f19d5cd1d414303
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c3dff63c5569a13e0a713b2e34ca6ef7f22a7ce858523bee5a8483b59b8c17d7053302e3a0f25a670b2ff3ce794f8bd1aef25500e2766594e51b2f35d12ad8ea
|
|
7
|
+
data.tar.gz: 41dc15d6314e4ae1721b2e26163b1e4d6f006f9c7ae6ed93d5ff394b29e98f6399e16f604515eefa54663cb6328356fd31843d6da5228bdf92173889b0380c98
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
slack_messaging (3.1.0)
|
|
5
|
+
activesupport (~> 6.0)
|
|
6
|
+
gli (~> 2.10)
|
|
7
|
+
hashie (~> 4.1)
|
|
8
|
+
highline_wrapper (~> 1.0)
|
|
9
|
+
httparty (~> 0.18)
|
|
10
|
+
json (~> 2.5)
|
|
11
|
+
rack (~> 2.2)
|
|
12
|
+
|
|
13
|
+
GEM
|
|
14
|
+
remote: https://rubygems.org/
|
|
15
|
+
specs:
|
|
16
|
+
activesupport (6.1.3)
|
|
17
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
18
|
+
i18n (>= 1.6, < 2)
|
|
19
|
+
minitest (>= 5.1)
|
|
20
|
+
tzinfo (~> 2.0)
|
|
21
|
+
zeitwerk (~> 2.3)
|
|
22
|
+
ast (2.4.2)
|
|
23
|
+
coderay (1.1.3)
|
|
24
|
+
concurrent-ruby (1.1.8)
|
|
25
|
+
diff-lcs (1.4.4)
|
|
26
|
+
faker (2.16.0)
|
|
27
|
+
i18n (>= 1.6, < 2)
|
|
28
|
+
ffi (1.14.2)
|
|
29
|
+
formatador (0.2.5)
|
|
30
|
+
gli (2.20.0)
|
|
31
|
+
guard (2.16.2)
|
|
32
|
+
formatador (>= 0.2.4)
|
|
33
|
+
listen (>= 2.7, < 4.0)
|
|
34
|
+
lumberjack (>= 1.0.12, < 2.0)
|
|
35
|
+
nenv (~> 0.1)
|
|
36
|
+
notiffany (~> 0.0)
|
|
37
|
+
pry (>= 0.9.12)
|
|
38
|
+
shellany (~> 0.0)
|
|
39
|
+
thor (>= 0.18.1)
|
|
40
|
+
guard-compat (1.2.1)
|
|
41
|
+
guard-rspec (4.7.3)
|
|
42
|
+
guard (~> 2.1)
|
|
43
|
+
guard-compat (~> 1.1)
|
|
44
|
+
rspec (>= 2.99.0, < 4.0)
|
|
45
|
+
hashie (4.1.0)
|
|
46
|
+
highline (2.0.3)
|
|
47
|
+
highline_wrapper (1.0.0)
|
|
48
|
+
highline (~> 2.0)
|
|
49
|
+
httparty (0.18.1)
|
|
50
|
+
mime-types (~> 3.0)
|
|
51
|
+
multi_xml (>= 0.5.2)
|
|
52
|
+
i18n (1.8.9)
|
|
53
|
+
concurrent-ruby (~> 1.0)
|
|
54
|
+
json (2.5.1)
|
|
55
|
+
listen (3.4.1)
|
|
56
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
|
57
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
|
58
|
+
lumberjack (1.2.8)
|
|
59
|
+
method_source (1.0.0)
|
|
60
|
+
mime-types (3.3.1)
|
|
61
|
+
mime-types-data (~> 3.2015)
|
|
62
|
+
mime-types-data (3.2021.0225)
|
|
63
|
+
minitest (5.14.4)
|
|
64
|
+
multi_xml (0.6.0)
|
|
65
|
+
nenv (0.3.0)
|
|
66
|
+
notiffany (0.1.3)
|
|
67
|
+
nenv (~> 0.1)
|
|
68
|
+
shellany (~> 0.0)
|
|
69
|
+
parallel (1.20.1)
|
|
70
|
+
parser (3.0.0.0)
|
|
71
|
+
ast (~> 2.4.1)
|
|
72
|
+
pry (0.14.0)
|
|
73
|
+
coderay (~> 1.1)
|
|
74
|
+
method_source (~> 1.0)
|
|
75
|
+
rack (2.2.3)
|
|
76
|
+
rainbow (3.0.0)
|
|
77
|
+
rake (13.0.3)
|
|
78
|
+
rb-fsevent (0.10.4)
|
|
79
|
+
rb-inotify (0.10.1)
|
|
80
|
+
ffi (~> 1.0)
|
|
81
|
+
regexp_parser (2.1.1)
|
|
82
|
+
rexml (3.2.4)
|
|
83
|
+
rspec (3.10.0)
|
|
84
|
+
rspec-core (~> 3.10.0)
|
|
85
|
+
rspec-expectations (~> 3.10.0)
|
|
86
|
+
rspec-mocks (~> 3.10.0)
|
|
87
|
+
rspec-core (3.10.1)
|
|
88
|
+
rspec-support (~> 3.10.0)
|
|
89
|
+
rspec-expectations (3.10.1)
|
|
90
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
91
|
+
rspec-support (~> 3.10.0)
|
|
92
|
+
rspec-mocks (3.10.2)
|
|
93
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
94
|
+
rspec-support (~> 3.10.0)
|
|
95
|
+
rspec-support (3.10.2)
|
|
96
|
+
rubocop (1.11.0)
|
|
97
|
+
parallel (~> 1.10)
|
|
98
|
+
parser (>= 3.0.0.0)
|
|
99
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
100
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
101
|
+
rexml
|
|
102
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
|
103
|
+
ruby-progressbar (~> 1.7)
|
|
104
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
105
|
+
rubocop-ast (1.4.1)
|
|
106
|
+
parser (>= 2.7.1.5)
|
|
107
|
+
ruby-progressbar (1.11.0)
|
|
108
|
+
shellany (0.0.1)
|
|
109
|
+
thor (1.1.0)
|
|
110
|
+
tzinfo (2.0.4)
|
|
111
|
+
concurrent-ruby (~> 1.0)
|
|
112
|
+
unicode-display_width (2.0.0)
|
|
113
|
+
zeitwerk (2.4.2)
|
|
114
|
+
|
|
115
|
+
PLATFORMS
|
|
116
|
+
x86_64-darwin-20
|
|
117
|
+
|
|
118
|
+
DEPENDENCIES
|
|
119
|
+
bundler (~> 2.2)
|
|
120
|
+
faker (~> 2.15)
|
|
121
|
+
guard-rspec (~> 4.3)
|
|
122
|
+
pry (~> 0.13)
|
|
123
|
+
rake (~> 13.0)
|
|
124
|
+
rspec (~> 3.9)
|
|
125
|
+
rubocop (~> 1.10)
|
|
126
|
+
slack_messaging!
|
|
127
|
+
|
|
128
|
+
BUNDLED WITH
|
|
129
|
+
2.2.4
|
data/Guardfile
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
guard :rspec, cmd: 'bundle exec rspec', all_on_start: true do
|
|
2
4
|
watch(%r{^spec/.+_spec\.rb$})
|
|
3
5
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
|
4
6
|
watch('spec/spec_helper.rb') { 'spec' }
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Slack Messaging [](https://github.com/emmahsax/slack_messaging/actions/workflows/main.yml)
|
|
2
2
|
|
|
3
3
|
This is a simple project designed to post messages to a given Slack channel as a bot.
|
|
4
4
|
|
|
@@ -26,59 +26,73 @@ gem install slack_messaging
|
|
|
26
26
|
|
|
27
27
|
This project requires a config file that should look like this:
|
|
28
28
|
|
|
29
|
-
```
|
|
29
|
+
```yml
|
|
30
30
|
slack:
|
|
31
31
|
channel: <AWESOME CHANNEL NAME>
|
|
32
32
|
username: <AWESOME USER NAME>
|
|
33
33
|
webhook_url: <SLACK WEBHOOK URL>
|
|
34
|
-
icon_emoji:
|
|
34
|
+
icon_emoji: ':<SOME EMOJI>:'
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
To generate this file at `~/.slack_messaging.yml`, please run this command:
|
|
38
38
|
|
|
39
|
+
```bash
|
|
40
|
+
slack-messaging setup
|
|
39
41
|
```
|
|
40
|
-
|
|
42
|
+
|
|
43
|
+
To obtain the webhook URL, go to [this link](https://api.slack.com/messaging/webhooks).
|
|
44
|
+
|
|
45
|
+
If you'd like to create the config file at a different directory, I recommend using the `setup` command, and then manually moving the file to your desired location:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
slack-messaging setup
|
|
49
|
+
# Walk through the prompts to create the file
|
|
50
|
+
mv ~/.slack_messaging.yml /PATH/TO/FILE/config.yml
|
|
41
51
|
```
|
|
42
52
|
|
|
43
|
-
|
|
53
|
+
And then you can pass in that specific file location like this:
|
|
44
54
|
|
|
45
|
-
|
|
55
|
+
```bash
|
|
56
|
+
slack-messaging --config="/PATH/TO/FILE/config.yml" send
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Once the config file is set up, the project is ready to go!
|
|
46
60
|
|
|
47
61
|
To print a friendly message to Slack, run:
|
|
48
62
|
|
|
49
|
-
```
|
|
50
|
-
slack-messaging
|
|
63
|
+
```bash
|
|
64
|
+
slack-messaging send
|
|
51
65
|
```
|
|
52
66
|
|
|
53
|
-
|
|
67
|
+
Here, no specific message is being given to print to Slack, so slack_messaging will choose a random quote. The random quotes are selected using the [Quotable API](http://api.quotable.io/).
|
|
54
68
|
|
|
55
69
|
However, what if you wanted to print something specific? Well, you can! Just run:
|
|
56
70
|
|
|
57
|
-
```
|
|
58
|
-
slack-messaging
|
|
71
|
+
```bash
|
|
72
|
+
slack-messaging send 'MESSAGE 1'
|
|
59
73
|
```
|
|
60
74
|
|
|
61
75
|
You can even print multiple messages at once:
|
|
62
76
|
|
|
63
|
-
```
|
|
64
|
-
slack-messaging
|
|
77
|
+
```bash
|
|
78
|
+
slack-messaging send 'MESSAGE 1' 'MESSAGE 2' 'MESSAGE 3' ... 'MESSAGE N'
|
|
65
79
|
```
|
|
66
80
|
|
|
67
81
|
The output of slack_messaging will look something like this:
|
|
68
82
|
|
|
69
|
-
<img src="https://github.com/
|
|
83
|
+
<img src="https://github.com/emmahsax/slack_messaging/blob/main/QuoteExample.png" width="500">
|
|
70
84
|
|
|
71
85
|
I hope you enjoy printing fun and specialized messages to Slack!
|
|
72
86
|
|
|
73
87
|
### Tests
|
|
74
88
|
|
|
75
|
-
To run the tests, run `bundle exec rspec` from the command
|
|
89
|
+
To run the tests, run `bundle exec rspec` from the command-line. GitHub Actions will also run the tests upon every commit to make sure they're up to date and that everything is working correctly. Locally, you can also run `bundle exec guard` to automatically run tests as you develop!
|
|
76
90
|
|
|
77
91
|
## Contributing
|
|
78
92
|
|
|
79
|
-
To submit a feature request, bug ticket, etc, please submit an official [GitHub Issue](https://github.com/
|
|
93
|
+
To submit a feature request, bug ticket, etc, please submit an official [GitHub Issue](https://github.com/emmahsax/slack_messaging/issues/new).
|
|
80
94
|
|
|
81
|
-
To report any security vulnerabilities, please view this project's [Security Policy](https://github.com/
|
|
95
|
+
To report any security vulnerabilities, please view this project's [Security Policy](https://github.com/emmahsax/slack_messaging/security/policy).
|
|
82
96
|
|
|
83
97
|
When interacting with this repository, please follow [Contributor Covenant's Code of Conduct](https://contributor-covenant.org).
|
|
84
98
|
|
|
@@ -88,7 +102,7 @@ To make a new release of this gem:
|
|
|
88
102
|
|
|
89
103
|
1. Merge the pull request via the big green button
|
|
90
104
|
2. Run `git tag vX.X.X` and `git push --tag`
|
|
91
|
-
3. Make a new release [here](https://github.com/
|
|
105
|
+
3. Make a new release [here](https://github.com/emmahsax/slack_messaging/releases/new)
|
|
92
106
|
4. Run `gem build *.gemspec`
|
|
93
107
|
5. Run `gem push *.gem` to push the new gem to RubyGems
|
|
94
108
|
6. Run `rm *.gem` to clean up your local repository
|
data/Rakefile
CHANGED
data/bin/slack-messaging
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
|
|
2
5
|
require 'rubygems'
|
|
3
6
|
require 'gli'
|
|
4
7
|
require_relative '../lib/slack_messaging'
|
|
@@ -10,23 +13,32 @@ version SlackMessaging::VERSION
|
|
|
10
13
|
|
|
11
14
|
wrap_help_text :verbatim
|
|
12
15
|
|
|
13
|
-
flag [:config], :
|
|
16
|
+
flag [:config], desc: 'Slack Messaging config file path', default_value: SlackMessaging::DefaultPaths.config
|
|
14
17
|
|
|
15
|
-
program_long_desc "
|
|
18
|
+
program_long_desc "
|
|
16
19
|
DOCUMENTATION
|
|
17
|
-
|
|
20
|
+
For documentation and help in setting up your configuration files,
|
|
21
|
+
see Slack Messaging's GitHub repo: https://github.com/emmahsax/slack_messaging
|
|
22
|
+
"
|
|
23
|
+
|
|
24
|
+
pre do |global, _command, _options, _args|
|
|
25
|
+
SlackMessaging::Config.load(global[:config])
|
|
26
|
+
true
|
|
27
|
+
end
|
|
18
28
|
|
|
19
29
|
desc 'Prints a variety of messages to Slack'
|
|
20
|
-
command '
|
|
21
|
-
c.action do |
|
|
22
|
-
SlackMessaging::
|
|
30
|
+
command 'send' do |c|
|
|
31
|
+
c.action do |_global_options, options, args|
|
|
32
|
+
SlackMessaging::Send.execute(args, options)
|
|
23
33
|
end
|
|
24
34
|
end
|
|
25
35
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
desc 'Sets up a Slack Messaging config file at ~/.slack_messaging.yml'
|
|
37
|
+
skips_pre
|
|
38
|
+
command 'setup' do |c|
|
|
39
|
+
c.action do
|
|
40
|
+
SlackMessaging::Setup.execute
|
|
41
|
+
end
|
|
30
42
|
end
|
|
31
43
|
|
|
32
44
|
exit run(ARGV)
|
data/lib/slack_messaging.rb
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'yaml'
|
|
2
4
|
require 'hashie'
|
|
3
5
|
require 'httparty'
|
|
4
|
-
require '
|
|
6
|
+
require 'highline_wrapper'
|
|
5
7
|
require 'json'
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
files = "#{File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), 'slack_messaging'))}/**/*.rb"
|
|
10
|
+
|
|
11
|
+
Dir[files].each do |file|
|
|
8
12
|
require_relative file
|
|
9
13
|
end
|
|
10
14
|
|
|
@@ -1,27 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module SlackMessaging
|
|
2
4
|
class Config
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
class << self
|
|
6
|
+
def method_missing(method, args = false)
|
|
7
|
+
config_data.send(method, args)
|
|
8
|
+
end
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
def load(path)
|
|
11
|
+
load_config(path)
|
|
12
|
+
config
|
|
13
|
+
end
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
private def config
|
|
16
|
+
config_data.to_hash
|
|
17
|
+
end
|
|
13
18
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
private def config_data
|
|
20
|
+
@config_data ||= Hashie::Mash.new
|
|
21
|
+
end
|
|
17
22
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
end
|
|
23
|
+
private def load_config(file)
|
|
24
|
+
raise StandardError, "Missing configuration file: #{file}" unless File.exist?(file)
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
YAML.load_file(file).each { |key, value| config_data.assign_property(key, value) }
|
|
26
|
+
YAML.load_file(file).each { |key, value| config_data.assign_property(key, value) }
|
|
27
|
+
end
|
|
25
28
|
end
|
|
26
29
|
end
|
|
27
30
|
end
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module SlackMessaging
|
|
2
4
|
class DefaultPaths
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
private
|
|
5
|
+
class << self
|
|
6
|
+
def config
|
|
7
|
+
File.join(home, '.slack_messaging.yml')
|
|
8
|
+
end
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
private def home
|
|
11
|
+
ENV['HOME'] || '.'
|
|
12
|
+
end
|
|
11
13
|
end
|
|
12
14
|
end
|
|
13
15
|
end
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module SlackMessaging
|
|
2
4
|
class RandomMessage
|
|
3
5
|
def self.acquire_random_quote
|
|
4
6
|
random_quote = HTTParty.get('http://api.quotable.io/random', headers: { 'Content-Type': 'application/json' }).body
|
|
5
7
|
quote_content = JSON.parse(random_quote)['content']
|
|
6
8
|
quote_author = JSON.parse(random_quote)['author']
|
|
7
|
-
|
|
9
|
+
"\"#{quote_content}\"\n—#{quote_author}"
|
|
8
10
|
end
|
|
9
11
|
end
|
|
10
12
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SlackMessaging
|
|
4
|
+
class Send
|
|
5
|
+
class << self
|
|
6
|
+
attr_accessor :options
|
|
7
|
+
|
|
8
|
+
def execute(args, _options = nil)
|
|
9
|
+
if args.empty?
|
|
10
|
+
message = SlackMessaging::RandomMessage.acquire_random_quote
|
|
11
|
+
print_message(message)
|
|
12
|
+
else
|
|
13
|
+
args.each do |arg_message|
|
|
14
|
+
print_message(arg_message)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private def print_message(message)
|
|
20
|
+
SlackMessaging::NotifySlack.new(message).perform
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SlackMessaging
|
|
4
|
+
class Setup
|
|
5
|
+
class << self
|
|
6
|
+
# rubocop:disable Style/ConditionalAssignment
|
|
7
|
+
def execute
|
|
8
|
+
if config_file_exists?
|
|
9
|
+
answer = highline.ask_yes_no(
|
|
10
|
+
"It looks like the #{default_config} file already exists. Do you wish to replace it? (y/n)",
|
|
11
|
+
{ required: true }
|
|
12
|
+
)
|
|
13
|
+
else
|
|
14
|
+
answer = true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
create_or_update_config_file(ask_config_questions) if answer
|
|
18
|
+
end
|
|
19
|
+
# rubocop:enable Style/ConditionalAssignment
|
|
20
|
+
|
|
21
|
+
private def create_or_update_config_file(answers)
|
|
22
|
+
contents = generate_config_file(answers)
|
|
23
|
+
puts "Creating or updating your #{default_config} file..."
|
|
24
|
+
File.open(default_config, 'w') { |file| file.puts contents }
|
|
25
|
+
puts "\nDone!"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private def generate_config_file(answers)
|
|
29
|
+
file_contents = ''.dup
|
|
30
|
+
file_contents << "slack:\n"
|
|
31
|
+
file_contents << " channel: #{answers[:channel].tr('#', '').strip}\n"
|
|
32
|
+
file_contents << " username: #{answers[:username].strip}\n"
|
|
33
|
+
file_contents << " webhook_url: #{answers[:webhook_url].strip}\n"
|
|
34
|
+
file_contents << " icon_emoji: '#{answers[:icon_emoji].strip}'"
|
|
35
|
+
file_contents
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private def config_file_exists?
|
|
39
|
+
File.exist?(default_config)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# rubocop:disable Metrics/MethodLength
|
|
43
|
+
private def ask_config_questions
|
|
44
|
+
answers = {}
|
|
45
|
+
|
|
46
|
+
answers[:webhook_url] = ask_question(
|
|
47
|
+
"What is your Slack webhook URL? If you don't have one yet, please navigate" \
|
|
48
|
+
' to https://api.slack.com/messaging/webhooks to create one, and then come back' \
|
|
49
|
+
' here and paste it in the Terminal.',
|
|
50
|
+
required: true
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
answers[:channel] = ask_question(
|
|
54
|
+
'What slack channel do you wish to post to? (default is "#general")'
|
|
55
|
+
) || 'general'
|
|
56
|
+
|
|
57
|
+
answers[:username] = ask_question(
|
|
58
|
+
"What slack username do you wish to post as? (default is \"Let's Get Quoty\")"
|
|
59
|
+
) || "Let's Get Quoty"
|
|
60
|
+
|
|
61
|
+
answers[:icon_emoji] = ask_question(
|
|
62
|
+
'What emoji would you like to post with (include the colons at the beginning and end' \
|
|
63
|
+
' of the emoji name)? (default is ":mailbox_with_mail:")'
|
|
64
|
+
) || ':mailbox_with_mail:'
|
|
65
|
+
|
|
66
|
+
answers
|
|
67
|
+
end
|
|
68
|
+
# rubocop:enable Metrics/MethodLength
|
|
69
|
+
|
|
70
|
+
private def ask_question(prompt, required: false)
|
|
71
|
+
answer = highline.ask(prompt, { required: required })
|
|
72
|
+
answer.empty? ? nil : answer
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private def highline
|
|
76
|
+
@highline ||= HighlineWrapper.new
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
private def default_config
|
|
80
|
+
SlackMessaging::DefaultPaths.config
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
require 'slack_messaging'
|
|
3
5
|
|
|
4
6
|
describe SlackMessaging::Config do
|
|
7
|
+
subject { SlackMessaging::Config }
|
|
8
|
+
|
|
5
9
|
context 'config key methods' do
|
|
6
10
|
it 'should return nil when not set' do
|
|
7
|
-
expect(
|
|
8
|
-
expect(
|
|
11
|
+
expect(subject.doesnt_exist).to eql(nil)
|
|
12
|
+
expect(subject.doesnt_exist?).to eql(false)
|
|
9
13
|
end
|
|
10
14
|
|
|
11
15
|
it 'should return the config value when set' do
|
|
12
16
|
config_value = Faker::Lorem.word
|
|
13
|
-
|
|
14
|
-
expect(
|
|
17
|
+
subject.new_value = config_value
|
|
18
|
+
expect(subject.new_value).to eql(config_value)
|
|
15
19
|
end
|
|
16
20
|
end
|
|
17
21
|
|
|
@@ -21,13 +25,13 @@ describe SlackMessaging::Config do
|
|
|
21
25
|
|
|
22
26
|
let(:config_file) do
|
|
23
27
|
{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
domain: domain,
|
|
29
|
+
slack: {
|
|
30
|
+
slack_option: true,
|
|
31
|
+
username: Faker::Name.name,
|
|
32
|
+
icon_url: Faker::Internet.url,
|
|
33
|
+
channel: Faker::Lorem.word,
|
|
34
|
+
webhook: Faker::Internet.url
|
|
31
35
|
}
|
|
32
36
|
}
|
|
33
37
|
end
|
|
@@ -35,19 +39,19 @@ describe SlackMessaging::Config do
|
|
|
35
39
|
before do
|
|
36
40
|
allow(YAML).to receive(:load_file).and_return(config_file)
|
|
37
41
|
allow(File).to receive(:exist?).and_return(true)
|
|
38
|
-
|
|
42
|
+
subject.load(Faker::Lorem.word)
|
|
39
43
|
end
|
|
40
44
|
|
|
41
45
|
it 'calling a method corresponding to a key in the file should return the value' do
|
|
42
|
-
expect(
|
|
43
|
-
expect(
|
|
44
|
-
expect(
|
|
46
|
+
expect(subject.domain).to eql(domain)
|
|
47
|
+
expect(subject.slack).to be_kind_of(Hash)
|
|
48
|
+
expect(subject.slack[:slack_option]).to eql(true)
|
|
45
49
|
end
|
|
46
50
|
|
|
47
51
|
it 'overwriting values should work' do
|
|
48
|
-
expect(
|
|
49
|
-
|
|
50
|
-
expect(
|
|
52
|
+
expect(subject.slack).to be_kind_of(Hash)
|
|
53
|
+
subject.slack = sentence
|
|
54
|
+
expect(subject.slack).to eql(sentence)
|
|
51
55
|
end
|
|
52
56
|
end
|
|
53
57
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
require 'slack_messaging'
|
|
3
5
|
|
|
@@ -10,12 +12,12 @@ describe SlackMessaging::NotifySlack do
|
|
|
10
12
|
|
|
11
13
|
let(:config_file) do
|
|
12
14
|
{
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
slack: {
|
|
16
|
+
slack_option: true,
|
|
17
|
+
username: username,
|
|
18
|
+
icon_emoji: emoji,
|
|
19
|
+
channel: channel,
|
|
20
|
+
webhook_url: webhook
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
end
|
|
@@ -26,18 +28,18 @@ describe SlackMessaging::NotifySlack do
|
|
|
26
28
|
SlackMessaging::Config.load(Faker::Lorem.word)
|
|
27
29
|
end
|
|
28
30
|
|
|
31
|
+
subject { SlackMessaging::NotifySlack.new(sentence) }
|
|
32
|
+
|
|
29
33
|
it 'should call HTTParty' do
|
|
30
34
|
expect(HTTParty).to receive(:post)
|
|
31
|
-
|
|
32
|
-
message.perform
|
|
35
|
+
subject.perform
|
|
33
36
|
end
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
expect(
|
|
38
|
-
expect(
|
|
39
|
-
expect(
|
|
40
|
-
expect(
|
|
41
|
-
expect(message.icon_emoji).to eq(emoji)
|
|
38
|
+
it 'should define certain values' do
|
|
39
|
+
expect(subject.text).to eq(sentence)
|
|
40
|
+
expect(subject.channel).to eq(channel)
|
|
41
|
+
expect(subject.username).to eq(username)
|
|
42
|
+
expect(subject.webhook_url).to eq(webhook)
|
|
43
|
+
expect(subject.icon_emoji).to eq(emoji)
|
|
42
44
|
end
|
|
43
45
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
require 'slack_messaging'
|
|
3
5
|
|
|
@@ -16,28 +18,30 @@ describe SlackMessaging::RandomMessage do
|
|
|
16
18
|
allow(HTTParty).to receive(:get).and_return(quote_object)
|
|
17
19
|
end
|
|
18
20
|
|
|
21
|
+
subject { SlackMessaging::RandomMessage }
|
|
22
|
+
|
|
19
23
|
it 'should get a string message' do
|
|
20
|
-
message =
|
|
24
|
+
message = subject.acquire_random_quote
|
|
21
25
|
expect(message).to be_instance_of(String)
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
it 'should get a message that includes a newline' do
|
|
25
|
-
message =
|
|
29
|
+
message = subject.acquire_random_quote
|
|
26
30
|
expect(message.include?("\n")).to eq(true)
|
|
27
31
|
end
|
|
28
32
|
|
|
29
33
|
it 'should get a message that includes a —' do
|
|
30
|
-
message =
|
|
34
|
+
message = subject.acquire_random_quote
|
|
31
35
|
expect(message.include?('—')).to eq(true)
|
|
32
36
|
end
|
|
33
37
|
|
|
34
38
|
it 'should use HTTParty to ping an API' do
|
|
35
39
|
expect(HTTParty).to receive(:get)
|
|
36
|
-
|
|
40
|
+
subject.acquire_random_quote
|
|
37
41
|
end
|
|
38
42
|
|
|
39
43
|
it 'should have the JSON parse the response content twice' do
|
|
40
44
|
expect(JSON).to receive(:parse).at_least(2).times.and_return(JSON.parse(quote_json))
|
|
41
|
-
|
|
45
|
+
subject.acquire_random_quote
|
|
42
46
|
end
|
|
43
47
|
end
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'slack_messaging'
|
|
5
|
+
|
|
6
|
+
describe SlackMessaging::Setup do
|
|
7
|
+
let(:highline_wrapper) { double(:highline_wrapper, ask: Faker::Lorem.word, ask_yes_no: true) }
|
|
8
|
+
let(:answers) do
|
|
9
|
+
{
|
|
10
|
+
channel: Faker::Lorem.word,
|
|
11
|
+
username: Faker::Lorem.word,
|
|
12
|
+
webhook_url: Faker::Internet.url,
|
|
13
|
+
icon_emoji: ":#{Faker::Lorem.word}:"
|
|
14
|
+
}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
before do
|
|
18
|
+
allow(HighlineWrapper).to receive(:new).and_return(highline_wrapper)
|
|
19
|
+
allow(subject).to receive(:puts)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
after do
|
|
23
|
+
SlackMessaging::Setup.instance_variable_set('@highline', nil)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
subject { SlackMessaging::Setup }
|
|
27
|
+
|
|
28
|
+
describe '#self.execute' do
|
|
29
|
+
it 'should ask a question if the config file exists' do
|
|
30
|
+
allow(subject).to receive(:config_file_exists?).and_return(true)
|
|
31
|
+
allow(File).to receive(:exists?).and_return(true)
|
|
32
|
+
expect(highline_wrapper).to receive(:ask_yes_no).and_return(true)
|
|
33
|
+
allow(subject).to receive(:create_or_update_config_file).and_return(true)
|
|
34
|
+
allow(subject).to receive(:ask_config_questions).and_return(true)
|
|
35
|
+
subject.execute
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'should call to create or update the config file' do
|
|
39
|
+
allow(File).to receive(:exists?).and_return(true)
|
|
40
|
+
allow(highline_wrapper).to receive(:ask_yes_no).and_return(true)
|
|
41
|
+
expect(subject).to receive(:create_or_update_config_file).and_return(true)
|
|
42
|
+
expect(subject).to receive(:ask_config_questions).and_return(true)
|
|
43
|
+
subject.execute
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'should skip if the user opts not to continue' do
|
|
47
|
+
allow(subject).to receive(:config_file_exists?).and_return(true)
|
|
48
|
+
allow(File).to receive(:exists?).and_return(true)
|
|
49
|
+
allow(highline_wrapper).to receive(:ask_yes_no).and_return(false)
|
|
50
|
+
expect(subject).not_to receive(:create_or_update_config_file)
|
|
51
|
+
expect(subject).not_to receive(:ask_config_questions)
|
|
52
|
+
subject.execute
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe '#self.create_or_update_config_file' do
|
|
57
|
+
it 'should generate the file based on the answers to the questions' do
|
|
58
|
+
expect(subject).to receive(:generate_config_file)
|
|
59
|
+
allow(File).to receive(:open).and_return(nil)
|
|
60
|
+
subject.send(:create_or_update_config_file, answers)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'should open the file for writing' do
|
|
64
|
+
allow(subject).to receive(:generate_config_file)
|
|
65
|
+
expect(File).to receive(:open).and_return(nil)
|
|
66
|
+
subject.send(:create_or_update_config_file, answers)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
describe '#self.generate_config_file' do
|
|
71
|
+
it 'returns a string' do
|
|
72
|
+
expect(subject.send(:generate_config_file, answers)).to be_a(String)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe '#self.config_file_exists?' do
|
|
77
|
+
it 'should return true if the file exists' do
|
|
78
|
+
allow(File).to receive(:exist?).and_return(true)
|
|
79
|
+
expect(subject.send(:config_file_exists?)).to eq(true)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'should return false if the file does not exist' do
|
|
83
|
+
allow(File).to receive(:exist?).and_return(false)
|
|
84
|
+
expect(subject.send(:config_file_exists?)).to eq(false)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe '#self.ask_question' do
|
|
89
|
+
it 'should use highline to ask a question' do
|
|
90
|
+
expect(highline_wrapper).to receive(:ask).and_return('')
|
|
91
|
+
subject.send(:ask_question, Faker::Lorem.sentence)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'should return nil if the highline client gets an empty string' do
|
|
95
|
+
allow(highline_wrapper).to receive(:ask).and_return('')
|
|
96
|
+
expect(subject.send(:ask_question, Faker::Lorem.sentence)).to be_nil
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it 'should return the answer if it is given' do
|
|
100
|
+
answer = Faker::Lorem.sentence
|
|
101
|
+
allow(highline_wrapper).to receive(:ask).and_return(answer)
|
|
102
|
+
expect(subject.send(:ask_question, Faker::Lorem.sentence)).to be(answer)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
describe '#self.ask_config_questions' do
|
|
107
|
+
it 'should call to ask at least four questions' do
|
|
108
|
+
expect(subject).to receive(:ask_question).at_least(4).times.and_return(Faker::Lorem.word)
|
|
109
|
+
subject.send(:ask_config_questions)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it 'should return the defaults if nothing is given' do
|
|
113
|
+
slack_url = Faker::Internet.url
|
|
114
|
+
defaults = {
|
|
115
|
+
channel: 'general',
|
|
116
|
+
username: "Let's Get Quoty",
|
|
117
|
+
webhook_url: slack_url,
|
|
118
|
+
icon_emoji: ':mailbox_with_mail:'
|
|
119
|
+
}
|
|
120
|
+
allow(subject).to receive(:ask_question).with(
|
|
121
|
+
"What is your Slack webhook URL? If you don't have one yet, please navigate to https://api.slack.com/messaging/webhooks to create one, and then come back here and paste it in the Terminal.",
|
|
122
|
+
required: true
|
|
123
|
+
).and_return(slack_url)
|
|
124
|
+
allow(subject).to receive(:ask_question).with(
|
|
125
|
+
'What slack channel do you wish to post to? (default is "#general")'
|
|
126
|
+
).and_return(nil)
|
|
127
|
+
allow(subject).to receive(:ask_question).with(
|
|
128
|
+
"What slack username do you wish to post as? (default is \"Let's Get Quoty\")"
|
|
129
|
+
).and_return(nil)
|
|
130
|
+
allow(subject).to receive(:ask_question).with(
|
|
131
|
+
'What emoji would you like to post with (include the colons at the beginning and end of the emoji name)? (default is ":mailbox_with_mail:")'
|
|
132
|
+
).and_return(nil)
|
|
133
|
+
expect(subject.send(:ask_config_questions)).to eq(defaults)
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'faker'
|
|
2
4
|
require 'pry'
|
|
3
5
|
|
|
@@ -34,7 +36,7 @@ RSpec.configure do |config|
|
|
|
34
36
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
35
37
|
end
|
|
36
38
|
|
|
37
|
-
config.filter_run :
|
|
39
|
+
config.filter_run focus: true
|
|
38
40
|
config.run_all_when_everything_filtered = true
|
|
39
41
|
|
|
40
42
|
# rspec-mocks config goes here. You can use an alternate test double
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: slack_messaging
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Emma Sax
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-
|
|
11
|
+
date: 2021-03-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -53,19 +53,19 @@ dependencies:
|
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '4.1'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
|
-
name:
|
|
56
|
+
name: highline_wrapper
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
59
|
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '
|
|
61
|
+
version: '1.0'
|
|
62
62
|
type: :runtime
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '
|
|
68
|
+
version: '1.0'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: httparty
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -192,15 +192,29 @@ dependencies:
|
|
|
192
192
|
- - "~>"
|
|
193
193
|
- !ruby/object:Gem::Version
|
|
194
194
|
version: '3.9'
|
|
195
|
+
- !ruby/object:Gem::Dependency
|
|
196
|
+
name: rubocop
|
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
|
198
|
+
requirements:
|
|
199
|
+
- - "~>"
|
|
200
|
+
- !ruby/object:Gem::Version
|
|
201
|
+
version: '1.10'
|
|
202
|
+
type: :development
|
|
203
|
+
prerelease: false
|
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
205
|
+
requirements:
|
|
206
|
+
- - "~>"
|
|
207
|
+
- !ruby/object:Gem::Version
|
|
208
|
+
version: '1.10'
|
|
195
209
|
description: Sending Personalized Slack Messages to a Slack channel of your choice.
|
|
196
210
|
email:
|
|
197
|
-
- emma.sax4@gmail.com
|
|
198
211
|
executables:
|
|
199
212
|
- slack-messaging
|
|
200
213
|
extensions: []
|
|
201
214
|
extra_rdoc_files: []
|
|
202
215
|
files:
|
|
203
216
|
- Gemfile
|
|
217
|
+
- Gemfile.lock
|
|
204
218
|
- Guardfile
|
|
205
219
|
- LICENSE
|
|
206
220
|
- QuoteExample.png
|
|
@@ -212,13 +226,15 @@ files:
|
|
|
212
226
|
- lib/slack_messaging/default_paths.rb
|
|
213
227
|
- lib/slack_messaging/notify_slack.rb
|
|
214
228
|
- lib/slack_messaging/random_message.rb
|
|
215
|
-
- lib/slack_messaging/
|
|
229
|
+
- lib/slack_messaging/send.rb
|
|
230
|
+
- lib/slack_messaging/setup.rb
|
|
216
231
|
- lib/slack_messaging/version.rb
|
|
217
232
|
- spec/slack_messaging/config_spec.rb
|
|
218
233
|
- spec/slack_messaging/notify_slack_spec.rb
|
|
219
234
|
- spec/slack_messaging/random_message_spec.rb
|
|
235
|
+
- spec/slack_messaging/setup_spec.rb
|
|
220
236
|
- spec/spec_helper.rb
|
|
221
|
-
homepage: https://github.com/
|
|
237
|
+
homepage: https://github.com/emmahsax/slack_messaging
|
|
222
238
|
licenses:
|
|
223
239
|
- MIT
|
|
224
240
|
metadata: {}
|
|
@@ -230,7 +246,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
230
246
|
requirements:
|
|
231
247
|
- - ">="
|
|
232
248
|
- !ruby/object:Gem::Version
|
|
233
|
-
version: '
|
|
249
|
+
version: '2.4'
|
|
234
250
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
235
251
|
requirements:
|
|
236
252
|
- - ">="
|
|
@@ -246,3 +262,4 @@ test_files:
|
|
|
246
262
|
- spec/slack_messaging/config_spec.rb
|
|
247
263
|
- spec/slack_messaging/notify_slack_spec.rb
|
|
248
264
|
- spec/slack_messaging/random_message_spec.rb
|
|
265
|
+
- spec/slack_messaging/setup_spec.rb
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
module SlackMessaging
|
|
2
|
-
class Slack
|
|
3
|
-
attr_accessor :options
|
|
4
|
-
|
|
5
|
-
def self.execute(args, options = nil)
|
|
6
|
-
if args.empty?
|
|
7
|
-
message = SlackMessaging::RandomMessage.acquire_random_quote
|
|
8
|
-
print_message(message)
|
|
9
|
-
else
|
|
10
|
-
args.each do |message|
|
|
11
|
-
print_message(message)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
def self.print_message(message)
|
|
19
|
-
SlackMessaging::NotifySlack.new(message).perform
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|