slack_messaging 3.1.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +11 -11
- data/README.md +1 -1
- data/bin/slack-messaging +6 -5
- data/lib/slack_messaging/config.rb +18 -16
- data/lib/slack_messaging/default_paths.rb +7 -5
- data/lib/slack_messaging/send.rb +13 -11
- data/lib/slack_messaging/setup.rb +62 -70
- data/lib/slack_messaging/version.rb +1 -1
- data/spec/slack_messaging/setup_spec.rb +3 -22
- metadata +4 -4
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.lock
CHANGED
@@ -5,7 +5,7 @@ PATH
|
|
5
5
|
activesupport (~> 6.0)
|
6
6
|
gli (~> 2.10)
|
7
7
|
hashie (~> 4.1)
|
8
|
-
highline_wrapper (~>
|
8
|
+
highline_wrapper (~> 1.0)
|
9
9
|
httparty (~> 0.18)
|
10
10
|
json (~> 2.5)
|
11
11
|
rack (~> 2.2)
|
@@ -13,7 +13,7 @@ PATH
|
|
13
13
|
GEM
|
14
14
|
remote: https://rubygems.org/
|
15
15
|
specs:
|
16
|
-
activesupport (6.1.
|
16
|
+
activesupport (6.1.3)
|
17
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
18
|
i18n (>= 1.6, < 2)
|
19
19
|
minitest (>= 5.1)
|
@@ -23,11 +23,11 @@ GEM
|
|
23
23
|
coderay (1.1.3)
|
24
24
|
concurrent-ruby (1.1.8)
|
25
25
|
diff-lcs (1.4.4)
|
26
|
-
faker (2.
|
26
|
+
faker (2.16.0)
|
27
27
|
i18n (>= 1.6, < 2)
|
28
28
|
ffi (1.14.2)
|
29
29
|
formatador (0.2.5)
|
30
|
-
gli (2.
|
30
|
+
gli (2.20.0)
|
31
31
|
guard (2.16.2)
|
32
32
|
formatador (>= 0.2.4)
|
33
33
|
listen (>= 2.7, < 4.0)
|
@@ -44,12 +44,12 @@ GEM
|
|
44
44
|
rspec (>= 2.99.0, < 4.0)
|
45
45
|
hashie (4.1.0)
|
46
46
|
highline (2.0.3)
|
47
|
-
highline_wrapper (
|
47
|
+
highline_wrapper (1.0.0)
|
48
48
|
highline (~> 2.0)
|
49
49
|
httparty (0.18.1)
|
50
50
|
mime-types (~> 3.0)
|
51
51
|
multi_xml (>= 0.5.2)
|
52
|
-
i18n (1.8.
|
52
|
+
i18n (1.8.9)
|
53
53
|
concurrent-ruby (~> 1.0)
|
54
54
|
json (2.5.1)
|
55
55
|
listen (3.4.1)
|
@@ -59,8 +59,8 @@ GEM
|
|
59
59
|
method_source (1.0.0)
|
60
60
|
mime-types (3.3.1)
|
61
61
|
mime-types-data (~> 3.2015)
|
62
|
-
mime-types-data (3.
|
63
|
-
minitest (5.14.
|
62
|
+
mime-types-data (3.2021.0225)
|
63
|
+
minitest (5.14.4)
|
64
64
|
multi_xml (0.6.0)
|
65
65
|
nenv (0.3.0)
|
66
66
|
notiffany (0.1.3)
|
@@ -93,7 +93,7 @@ GEM
|
|
93
93
|
diff-lcs (>= 1.2.0, < 2.0)
|
94
94
|
rspec-support (~> 3.10.0)
|
95
95
|
rspec-support (3.10.2)
|
96
|
-
rubocop (1.
|
96
|
+
rubocop (1.11.0)
|
97
97
|
parallel (~> 1.10)
|
98
98
|
parser (>= 3.0.0.0)
|
99
99
|
rainbow (>= 2.2.2, < 4.0)
|
@@ -113,7 +113,7 @@ GEM
|
|
113
113
|
zeitwerk (2.4.2)
|
114
114
|
|
115
115
|
PLATFORMS
|
116
|
-
x86_64-darwin-
|
116
|
+
x86_64-darwin-20
|
117
117
|
|
118
118
|
DEPENDENCIES
|
119
119
|
bundler (~> 2.2)
|
@@ -126,4 +126,4 @@ DEPENDENCIES
|
|
126
126
|
slack_messaging!
|
127
127
|
|
128
128
|
BUNDLED WITH
|
129
|
-
2.2.
|
129
|
+
2.2.4
|
data/README.md
CHANGED
@@ -86,7 +86,7 @@ I hope you enjoy printing fun and specialized messages to Slack!
|
|
86
86
|
|
87
87
|
### Tests
|
88
88
|
|
89
|
-
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!
|
90
90
|
|
91
91
|
## Contributing
|
92
92
|
|
data/bin/slack-messaging
CHANGED
@@ -21,19 +21,20 @@ DOCUMENTATION
|
|
21
21
|
see Slack Messaging's GitHub repo: https://github.com/emmahsax/slack_messaging
|
22
22
|
"
|
23
23
|
|
24
|
+
pre do |global, _command, _options, _args|
|
25
|
+
SlackMessaging::Config.load(global[:config])
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
24
29
|
desc 'Prints a variety of messages to Slack'
|
25
30
|
command 'send' do |c|
|
26
|
-
pre do |global, _command, _options, _args|
|
27
|
-
SlackMessaging::Config.load(global[:config])
|
28
|
-
true
|
29
|
-
end
|
30
|
-
|
31
31
|
c.action do |_global_options, options, args|
|
32
32
|
SlackMessaging::Send.execute(args, options)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
desc 'Sets up a Slack Messaging config file at ~/.slack_messaging.yml'
|
37
|
+
skips_pre
|
37
38
|
command 'setup' do |c|
|
38
39
|
c.action do
|
39
40
|
SlackMessaging::Setup.execute
|
@@ -2,27 +2,29 @@
|
|
2
2
|
|
3
3
|
module SlackMessaging
|
4
4
|
class Config
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class << self
|
6
|
+
def method_missing(method, args = false)
|
7
|
+
config_data.send(method, args)
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def load(path)
|
11
|
+
load_config(path)
|
12
|
+
config
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
private def config
|
16
|
+
config_data.to_hash
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
private def config_data
|
20
|
+
@config_data ||= Hashie::Mash.new
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
23
|
+
private def load_config(file)
|
24
|
+
raise StandardError, "Missing configuration file: #{file}" unless File.exist?(file)
|
24
25
|
|
25
|
-
|
26
|
+
YAML.load_file(file).each { |key, value| config_data.assign_property(key, value) }
|
27
|
+
end
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
@@ -2,12 +2,14 @@
|
|
2
2
|
|
3
3
|
module SlackMessaging
|
4
4
|
class DefaultPaths
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
data/lib/slack_messaging/send.rb
CHANGED
@@ -2,21 +2,23 @@
|
|
2
2
|
|
3
3
|
module SlackMessaging
|
4
4
|
class Send
|
5
|
-
|
5
|
+
class << self
|
6
|
+
attr_accessor :options
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
14
16
|
end
|
15
17
|
end
|
16
|
-
end
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
private def print_message(message)
|
20
|
+
SlackMessaging::NotifySlack.new(message).perform
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -2,91 +2,83 @@
|
|
2
2
|
|
3
3
|
module SlackMessaging
|
4
4
|
class Setup
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
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
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
File.open(default_config, 'w') { |file| file.puts contents }
|
22
|
-
puts "\nDone!"
|
23
|
-
end
|
17
|
+
create_or_update_config_file(ask_config_questions) if answer
|
18
|
+
end
|
19
|
+
# rubocop:enable Style/ConditionalAssignment
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
file_contents << " icon_emoji: '#{answers[:icon_emoji].strip}'"
|
32
|
-
file_contents
|
33
|
-
end
|
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
|
34
27
|
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
private def config_file_exists?
|
39
|
+
File.exist?(default_config)
|
40
|
+
end
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
' here and paste it in the Terminal.',
|
47
|
-
required: true
|
48
|
-
)
|
42
|
+
# rubocop:disable Metrics/MethodLength
|
43
|
+
private def ask_config_questions
|
44
|
+
answers = {}
|
49
45
|
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
+
)
|
53
52
|
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
answers[:channel] = ask_question(
|
54
|
+
'What slack channel do you wish to post to? (default is "#general")'
|
55
|
+
) || 'general'
|
57
56
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
) || ':mailbox_with_mail:'
|
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"
|
62
60
|
|
63
|
-
|
64
|
-
|
65
|
-
|
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:'
|
66
65
|
|
67
|
-
|
68
|
-
|
69
|
-
|
66
|
+
answers
|
67
|
+
end
|
68
|
+
# rubocop:enable Metrics/MethodLength
|
70
69
|
|
71
|
-
|
72
|
-
|
73
|
-
puts "\nThis question is required.\n\n"
|
74
|
-
ask_question(prompt, required: true)
|
75
|
-
else
|
76
|
-
answer
|
77
|
-
end
|
78
|
-
else
|
70
|
+
private def ask_question(prompt, required: false)
|
71
|
+
answer = highline.ask(prompt, { required: required })
|
79
72
|
answer.empty? ? nil : answer
|
80
73
|
end
|
81
|
-
end
|
82
|
-
# rubocop:enable Metrics/MethodLength
|
83
74
|
|
84
|
-
|
85
|
-
|
86
|
-
|
75
|
+
private def highline
|
76
|
+
@highline ||= HighlineWrapper.new
|
77
|
+
end
|
87
78
|
|
88
|
-
|
89
|
-
|
79
|
+
private def default_config
|
80
|
+
SlackMessaging::DefaultPaths.config
|
81
|
+
end
|
90
82
|
end
|
91
83
|
end
|
92
84
|
end
|
@@ -109,25 +109,6 @@ describe SlackMessaging::Setup do
|
|
109
109
|
subject.send(:ask_config_questions)
|
110
110
|
end
|
111
111
|
|
112
|
-
it 'should recurse if the slack URL is not given' do
|
113
|
-
allow(highline_wrapper).to receive(:ask).with(
|
114
|
-
"What is your Slack webhook URL? If you don't have one yet, please navigate" \
|
115
|
-
' to https://api.slack.com/messaging/webhooks to create one, and then come back' \
|
116
|
-
' here and paste it in the Terminal.'
|
117
|
-
).and_return('', Faker::Internet.url)
|
118
|
-
allow(highline_wrapper).to receive(:ask).with(
|
119
|
-
"\nWhat slack channel do you wish to post to? (default is \"#general\")"
|
120
|
-
).and_return('')
|
121
|
-
allow(highline_wrapper).to receive(:ask).with(
|
122
|
-
"\nWhat slack username do you wish to post as? (default is \"Let's Get Quoty\")"
|
123
|
-
).and_return('')
|
124
|
-
allow(highline_wrapper).to receive(:ask).with(
|
125
|
-
"\nWhat emoji would you like to post with (include the colons at the beginning and end of the emoji name)? (default is \":mailbox_with_mail:\")"
|
126
|
-
).and_return('')
|
127
|
-
expect(subject).to receive(:ask_question).at_least(:twice).and_call_original
|
128
|
-
subject.send(:ask_config_questions)
|
129
|
-
end
|
130
|
-
|
131
112
|
it 'should return the defaults if nothing is given' do
|
132
113
|
slack_url = Faker::Internet.url
|
133
114
|
defaults = {
|
@@ -141,13 +122,13 @@ describe SlackMessaging::Setup do
|
|
141
122
|
required: true
|
142
123
|
).and_return(slack_url)
|
143
124
|
allow(subject).to receive(:ask_question).with(
|
144
|
-
|
125
|
+
'What slack channel do you wish to post to? (default is "#general")'
|
145
126
|
).and_return(nil)
|
146
127
|
allow(subject).to receive(:ask_question).with(
|
147
|
-
"
|
128
|
+
"What slack username do you wish to post as? (default is \"Let's Get Quoty\")"
|
148
129
|
).and_return(nil)
|
149
130
|
allow(subject).to receive(:ask_question).with(
|
150
|
-
|
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:")'
|
151
132
|
).and_return(nil)
|
152
133
|
expect(subject.send(:ask_config_questions)).to eq(defaults)
|
153
134
|
end
|
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: 3.1.
|
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-03-
|
11
|
+
date: 2021-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -58,14 +58,14 @@ dependencies:
|
|
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
|