slack_messaging 3.0.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6742192033a64bb2935e5af6486ea356d54684f501515f22eb8a24c200fff61
4
- data.tar.gz: 0d880c5cd858c778f06c9047e911927a1cb2ab2ee6b53a89b20b9e23a61ad2a9
3
+ metadata.gz: 8dca88b2aa6f5f3f6c6d00b959fc61757cb09585125c57f9e8b97196fecb90aa
4
+ data.tar.gz: a2209e3efd4abdb1a68cbfe284d1d3c037ff2132bc4c3b022625e3d232ab826b
5
5
  SHA512:
6
- metadata.gz: 8458be91785ae94772e960f5f0705a2a611b36c286f694d0eb0ac4abe86fdd9d6867aa89d45dc9c44d721dbdb7bd9f34365ca5121f1d85ac0fd027d33439dbf4
7
- data.tar.gz: 7485f64ff53624785968f06a25e109a8042aa1e7e63412d7c7a40b78da8209f643e06f62130b3c8e7ba8d0677db2445950b2a9fca0ceb5199b03c71d10592bd3
6
+ metadata.gz: '099fcbf29e6141abfb0e0d7616c8257764994ca916110db53b1f94ed9253222e62bdf2b5c67b787910c16781d206cc2ce81abd7e35e3b7d98c89c8e803ac719f'
7
+ data.tar.gz: 7582a545af09cf57b4c03297e56675b13bba4f76e0f2e6de204e9e8a28173347af941c87e7902c721c8bf2e16e1de1f54cd705e832bbff16ff4f450e03e1da9a
data/Gemfile CHANGED
@@ -2,5 +2,4 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- # Specify your gem's dependencies in slack_messaging.gemspec
6
5
  gemspec
data/Gemfile.lock CHANGED
@@ -1,34 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slack_messaging (3.0.0)
5
- activesupport (~> 6.0)
4
+ slack_messaging (3.2.0)
6
5
  gli (~> 2.10)
7
6
  hashie (~> 4.1)
8
- highline (~> 2.0)
7
+ highline_wrapper (~> 1.1)
9
8
  httparty (~> 0.18)
10
9
  json (~> 2.5)
11
- rack (~> 2.2)
12
10
 
13
11
  GEM
14
12
  remote: https://rubygems.org/
15
13
  specs:
16
- activesupport (6.1.2.1)
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
14
  ast (2.4.2)
23
15
  coderay (1.1.3)
24
- concurrent-ruby (1.1.8)
16
+ concurrent-ruby (1.1.9)
25
17
  diff-lcs (1.4.4)
26
- faker (2.15.1)
18
+ faker (2.18.0)
27
19
  i18n (>= 1.6, < 2)
28
- ffi (1.14.2)
29
- formatador (0.2.5)
30
- gli (2.19.2)
31
- guard (2.16.2)
20
+ ffi (1.15.3)
21
+ formatador (0.3.0)
22
+ gli (2.20.1)
23
+ guard (2.17.0)
32
24
  formatador (>= 0.2.4)
33
25
  listen (>= 2.7, < 4.0)
34
26
  lumberjack (>= 1.0.12, < 2.0)
@@ -44,40 +36,39 @@ GEM
44
36
  rspec (>= 2.99.0, < 4.0)
45
37
  hashie (4.1.0)
46
38
  highline (2.0.3)
39
+ highline_wrapper (1.3.0)
40
+ highline (~> 2.0)
47
41
  httparty (0.18.1)
48
42
  mime-types (~> 3.0)
49
43
  multi_xml (>= 0.5.2)
50
- i18n (1.8.8)
44
+ i18n (1.8.10)
51
45
  concurrent-ruby (~> 1.0)
52
46
  json (2.5.1)
53
- listen (3.4.1)
47
+ listen (3.5.1)
54
48
  rb-fsevent (~> 0.10, >= 0.10.3)
55
49
  rb-inotify (~> 0.9, >= 0.9.10)
56
50
  lumberjack (1.2.8)
57
51
  method_source (1.0.0)
58
52
  mime-types (3.3.1)
59
53
  mime-types-data (~> 3.2015)
60
- mime-types-data (3.2020.1104)
61
- minitest (5.14.3)
54
+ mime-types-data (3.2021.0704)
62
55
  multi_xml (0.6.0)
63
56
  nenv (0.3.0)
64
57
  notiffany (0.1.3)
65
58
  nenv (~> 0.1)
66
59
  shellany (~> 0.0)
67
60
  parallel (1.20.1)
68
- parser (3.0.0.0)
61
+ parser (3.0.1.1)
69
62
  ast (~> 2.4.1)
70
- pry (0.14.0)
63
+ pry (0.14.1)
71
64
  coderay (~> 1.1)
72
65
  method_source (~> 1.0)
73
- rack (2.2.3)
74
66
  rainbow (3.0.0)
75
- rake (13.0.3)
76
- rb-fsevent (0.10.4)
67
+ rb-fsevent (0.11.0)
77
68
  rb-inotify (0.10.1)
78
69
  ffi (~> 1.0)
79
70
  regexp_parser (2.1.1)
80
- rexml (3.2.4)
71
+ rexml (3.2.5)
81
72
  rspec (3.10.0)
82
73
  rspec-core (~> 3.10.0)
83
74
  rspec-expectations (~> 3.10.0)
@@ -91,24 +82,21 @@ GEM
91
82
  diff-lcs (>= 1.2.0, < 2.0)
92
83
  rspec-support (~> 3.10.0)
93
84
  rspec-support (3.10.2)
94
- rubocop (1.10.0)
85
+ rubocop (1.18.2)
95
86
  parallel (~> 1.10)
96
87
  parser (>= 3.0.0.0)
97
88
  rainbow (>= 2.2.2, < 4.0)
98
89
  regexp_parser (>= 1.8, < 3.0)
99
90
  rexml
100
- rubocop-ast (>= 1.2.0, < 2.0)
91
+ rubocop-ast (>= 1.7.0, < 2.0)
101
92
  ruby-progressbar (~> 1.7)
102
93
  unicode-display_width (>= 1.4.0, < 3.0)
103
- rubocop-ast (1.4.1)
104
- parser (>= 2.7.1.5)
94
+ rubocop-ast (1.7.0)
95
+ parser (>= 3.0.1.1)
105
96
  ruby-progressbar (1.11.0)
106
97
  shellany (0.0.1)
107
98
  thor (1.1.0)
108
- tzinfo (2.0.4)
109
- concurrent-ruby (~> 1.0)
110
99
  unicode-display_width (2.0.0)
111
- zeitwerk (2.4.2)
112
100
 
113
101
  PLATFORMS
114
102
  x86_64-darwin-19
@@ -118,10 +106,9 @@ DEPENDENCIES
118
106
  faker (~> 2.15)
119
107
  guard-rspec (~> 4.3)
120
108
  pry (~> 0.13)
121
- rake (~> 13.0)
122
109
  rspec (~> 3.9)
123
- rubocop
110
+ rubocop (~> 1.10)
124
111
  slack_messaging!
125
112
 
126
113
  BUNDLED WITH
127
- 2.2.9
114
+ 2.2.21
data/Guardfile CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  guard :rspec, cmd: 'bundle exec rspec', all_on_start: true do
4
4
  watch(%r{^spec/.+_spec\.rb$})
5
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
5
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
6
6
  watch('spec/spec_helper.rb') { 'spec' }
7
7
  end
data/LICENSE.md ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause "New" or "Revised" License
2
+
3
+ Copyright (c) 2014 Emma Sax.
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions, and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions, and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
  gem install slack_messaging
23
23
  ```
24
24
 
25
- ### Usage
25
+ ## Usage
26
26
 
27
27
  This project requires a config file that should look like this:
28
28
 
@@ -84,19 +84,31 @@ The output of slack_messaging will look something like this:
84
84
 
85
85
  I hope you enjoy printing fun and specialized messages to Slack!
86
86
 
87
- ### Tests
87
+ ## Tests
88
88
 
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! There are currently only tests for the `notify_slack` and `random_message` classes. Feel free to help us add more!
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
- ## Contributing
91
+ ---
92
92
 
93
- To submit a feature request, bug ticket, etc, please submit an official [GitHub Issue](https://github.com/emmahsax/slack_messaging/issues/new).
93
+ ### Contributing
94
94
 
95
- To report any security vulnerabilities, please view this project's [Security Policy](https://github.com/emmahsax/slack_messaging/security/policy).
95
+ To submit a feature request, bug ticket, etc, please submit an official [GitHub issue](https://github.com/emmahsax/slack_messaging/issues/new). To copy or make changes, please [fork this repository](https://github.com/emmahsax/slack_messaging/fork). When/if you'd like to contribute back to this upstream, please create a pull request on this repository.
96
+
97
+ Please follow included Issue Template(s) and Pull Request Template(s) when creating issues or pull requests.
98
+
99
+ ### Security Policy
100
+
101
+ To report any security vulnerabilities, please view this repository's [Security Policy](https://github.com/emmahsax/slack_messaging/security/policy).
102
+
103
+ ### Licensing
104
+
105
+ For information on licensing, please see [LICENSE.md](https://github.com/emmahsax/slack_messaging/blob/main/LICENSE.md).
106
+
107
+ ### Code of Conduct
96
108
 
97
109
  When interacting with this repository, please follow [Contributor Covenant's Code of Conduct](https://contributor-covenant.org).
98
110
 
99
- ## Releasing
111
+ ### Releasing
100
112
 
101
113
  To make a new release of this gem:
102
114
 
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
@@ -3,7 +3,7 @@
3
3
  require 'yaml'
4
4
  require 'hashie'
5
5
  require 'httparty'
6
- require 'highline'
6
+ require 'highline_wrapper'
7
7
  require 'json'
8
8
 
9
9
  files = "#{File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), 'slack_messaging'))}/**/*.rb"
@@ -2,27 +2,29 @@
2
2
 
3
3
  module SlackMessaging
4
4
  class Config
5
- def self.config
6
- config_data.to_hash
7
- end
5
+ class << self
6
+ def method_missing(method, args = false)
7
+ config_data.send(method, args)
8
+ end
8
9
 
9
- def self.load(path)
10
- load_config(path)
11
- config
12
- end
10
+ def load(path)
11
+ load_config(path)
12
+ config
13
+ end
13
14
 
14
- def self.config_data
15
- @config_data ||= Hashie::Mash.new
16
- end
15
+ private def config
16
+ config_data.to_hash
17
+ end
17
18
 
18
- def self.method_missing(method, args = false)
19
- config_data.send(method, args)
20
- end
19
+ private def config_data
20
+ @config_data ||= Hashie::Mash.new
21
+ end
21
22
 
22
- def self.load_config(file)
23
- raise MissingConfig, "Missing configuration file: #{file}" unless File.exist?(file)
23
+ private def load_config(file)
24
+ raise StandardError, "Missing configuration file: #{file}" unless File.exist?(file)
24
25
 
25
- 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
26
28
  end
27
29
  end
28
30
  end
@@ -2,12 +2,14 @@
2
2
 
3
3
  module SlackMessaging
4
4
  class DefaultPaths
5
- def self.config
6
- File.join(home, '.slack_messaging.yml')
7
- end
5
+ class << self
6
+ def config
7
+ File.join(home, '.slack_messaging.yml')
8
+ end
8
9
 
9
- def self.home
10
- ENV['HOME'] || '.'
10
+ private def home
11
+ ENV['HOME'] || '.'
12
+ end
11
13
  end
12
14
  end
13
15
  end
@@ -2,21 +2,23 @@
2
2
 
3
3
  module SlackMessaging
4
4
  class Send
5
- attr_accessor :options
5
+ class << self
6
+ attr_accessor :options
6
7
 
7
- def self.execute(args, _options = nil)
8
- if args.empty?
9
- message = SlackMessaging::RandomMessage.acquire_random_quote
10
- print_message(message)
11
- else
12
- args.each do |arg_message|
13
- print_message(arg_message)
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
- def self.print_message(message)
19
- SlackMessaging::NotifySlack.new(message).perform
19
+ private def print_message(message)
20
+ SlackMessaging::NotifySlack.new(message).perform
21
+ end
20
22
  end
21
23
  end
22
24
  end
@@ -2,83 +2,86 @@
2
2
 
3
3
  module SlackMessaging
4
4
  class Setup
5
- def self.execute
6
- if config_file_exists?
7
- answer = highline.ask_yes_no(
8
- "It looks like the #{default_config} file already exists. Do you wish to replace it? (y/n)"
9
- )
10
- puts
11
- else
12
- answer = true
13
- end
14
-
15
- create_or_update_config_file(ask_config_questions) if answer
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
- def self.create_or_update_config_file(answers)
19
- contents = generate_config_file(answers)
20
- puts "\nCreating or updating your #{default_config} file..."
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
- def self.generate_config_file(answers)
26
- file_contents = ''.dup
27
- file_contents << "slack:\n"
28
- file_contents << " channel: #{answers[:channel].tr('#', '').strip}\n"
29
- file_contents << " username: #{answers[:username].strip}\n"
30
- file_contents << " webhook_url: #{answers[:webhook_url].strip}\n"
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 'Done!'
26
+ end
34
27
 
35
- def self.config_file_exists?
36
- File.exist?(default_config)
37
- end
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
- # rubocop:disable Metrics/MethodLength:
40
- def self.ask_config_questions
41
- answers = {}
38
+ private def config_file_exists?
39
+ File.exist?(default_config)
40
+ end
42
41
 
43
- answers[:webhook_url] = ask_question(
44
- "What is your Slack webhook URL? If you don't have one yet, please navigate" \
45
- ' to https://api.slack.com/messaging/webhooks to create one, and then come back' \
46
- ' here and paste it in the Terminal.'
47
- )
42
+ # rubocop:disable Metrics/MethodLength
43
+ private def ask_config_questions
44
+ answers = {}
48
45
 
49
- unless answers[:webhook_url]
50
- puts "\nExiting because Slack webhoook is required..."
51
- exit
52
- end
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
+ nil,
51
+ required: true
52
+ )
53
53
 
54
- answers[:channel] = ask_question(
55
- "\nWhat slack channel do you wish to post to? (default is \"#general\")"
56
- ) || 'general'
54
+ answers[:channel] = ask_question(
55
+ 'What slack channel do you wish to post to? (default is "#general")',
56
+ '#general'
57
+ )
57
58
 
58
- answers[:username] = ask_question(
59
- "\nWhat slack username do you wish to post as? (default is \"Let's Get Quoty\")"
60
- ) || "Let's Get Quoty"
59
+ answers[:username] = ask_question(
60
+ "What slack username do you wish to post as? (default is \"Let's Get Quoty\")",
61
+ "Let's Get Quoty"
62
+ )
61
63
 
62
- answers[:icon_emoji] = ask_question(
63
- "\nWhat emoji would you like to post with (include the colons at the beginning and end" \
64
- ' of the emoji name)? (default is ":mailbox_with_mail:")'
65
- ) || ':mailbox_with_mail:'
64
+ answers[:icon_emoji] = ask_question(
65
+ 'What emoji would you like to post with (include the colons at the beginning and end' \
66
+ ' of the emoji name)? (default is ":mailbox_with_mail:")',
67
+ ':mailbox_with_mail:'
68
+ )
66
69
 
67
- answers
68
- end
69
- # rubocop:enable Metrics/MethodLength
70
+ answers
71
+ end
72
+ # rubocop:enable Metrics/MethodLength
70
73
 
71
- def self.ask_question(prompt)
72
- answer = highline.ask(prompt)
73
- answer.empty? ? nil : answer
74
- end
74
+ private def ask_question(prompt, default, required: false)
75
+ highline.ask(prompt, { default: default, required: required })
76
+ end
75
77
 
76
- def self.highline
77
- @highline ||= SlackMessaging::HighlineCli.new
78
- end
78
+ private def highline
79
+ @highline ||= HighlineWrapper.new
80
+ end
79
81
 
80
- def self.default_config
81
- SlackMessaging::DefaultPaths.config
82
+ private def default_config
83
+ SlackMessaging::DefaultPaths.config
84
+ end
82
85
  end
83
86
  end
84
87
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SlackMessaging
4
- VERSION = '3.0.0'
4
+ VERSION = '3.2.0'
5
5
  end
@@ -28,20 +28,18 @@ describe SlackMessaging::NotifySlack do
28
28
  SlackMessaging::Config.load(Faker::Lorem.word)
29
29
  end
30
30
 
31
- subject { SlackMessaging::NotifySlack }
31
+ subject { SlackMessaging::NotifySlack.new(sentence) }
32
32
 
33
33
  it 'should call HTTParty' do
34
34
  expect(HTTParty).to receive(:post)
35
- message = subject.new(sentence)
36
- message.perform
35
+ subject.perform
37
36
  end
38
37
 
39
38
  it 'should define certain values' do
40
- message = subject.new(sentence)
41
- expect(message.text).to eq(sentence)
42
- expect(message.channel).to eq(channel)
43
- expect(message.username).to eq(username)
44
- expect(message.webhook_url).to eq(webhook)
45
- expect(message.icon_emoji).to eq(emoji)
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)
46
44
  end
47
45
  end
@@ -4,8 +4,7 @@ require 'spec_helper'
4
4
  require 'slack_messaging'
5
5
 
6
6
  describe SlackMessaging::Setup do
7
- let(:response) { double(:response, readline: true, to_s: Faker::Lorem.sentence) }
8
- let(:highline_cli) { double(:highline_cli, ask: response, ask_yes_no: true) }
7
+ let(:highline_wrapper) { double(:highline_wrapper, ask: Faker::Lorem.word, ask_yes_no: true) }
9
8
  let(:answers) do
10
9
  {
11
10
  channel: Faker::Lorem.word,
@@ -16,7 +15,7 @@ describe SlackMessaging::Setup do
16
15
  end
17
16
 
18
17
  before do
19
- allow(SlackMessaging::HighlineCli).to receive(:new).and_return(highline_cli)
18
+ allow(HighlineWrapper).to receive(:new).and_return(highline_wrapper)
20
19
  allow(subject).to receive(:puts)
21
20
  end
22
21
 
@@ -30,7 +29,7 @@ describe SlackMessaging::Setup do
30
29
  it 'should ask a question if the config file exists' do
31
30
  allow(subject).to receive(:config_file_exists?).and_return(true)
32
31
  allow(File).to receive(:exists?).and_return(true)
33
- expect(highline_cli).to receive(:ask_yes_no).and_return(true)
32
+ expect(highline_wrapper).to receive(:ask_yes_no).and_return(true)
34
33
  allow(subject).to receive(:create_or_update_config_file).and_return(true)
35
34
  allow(subject).to receive(:ask_config_questions).and_return(true)
36
35
  subject.execute
@@ -38,7 +37,7 @@ describe SlackMessaging::Setup do
38
37
 
39
38
  it 'should call to create or update the config file' do
40
39
  allow(File).to receive(:exists?).and_return(true)
41
- allow(highline_cli).to receive(:ask_yes_no).and_return(true)
40
+ allow(highline_wrapper).to receive(:ask_yes_no).and_return(true)
42
41
  expect(subject).to receive(:create_or_update_config_file).and_return(true)
43
42
  expect(subject).to receive(:ask_config_questions).and_return(true)
44
43
  subject.execute
@@ -47,7 +46,7 @@ describe SlackMessaging::Setup do
47
46
  it 'should skip if the user opts not to continue' do
48
47
  allow(subject).to receive(:config_file_exists?).and_return(true)
49
48
  allow(File).to receive(:exists?).and_return(true)
50
- allow(highline_cli).to receive(:ask_yes_no).and_return(false)
49
+ allow(highline_wrapper).to receive(:ask_yes_no).and_return(false)
51
50
  expect(subject).not_to receive(:create_or_update_config_file)
52
51
  expect(subject).not_to receive(:ask_config_questions)
53
52
  subject.execute
@@ -88,49 +87,54 @@ describe SlackMessaging::Setup do
88
87
 
89
88
  describe '#self.ask_question' do
90
89
  it 'should use highline to ask a question' do
91
- expect(highline_cli).to receive(:ask).and_return('')
92
- subject.send(:ask_question, Faker::Lorem.sentence)
90
+ expect(highline_wrapper).to receive(:ask).and_return('')
91
+ subject.send(:ask_question, Faker::Lorem.sentence, nil)
93
92
  end
94
93
 
95
94
  it 'should return nil if the highline client gets an empty string' do
96
- allow(highline_cli).to receive(:ask).and_return('')
97
- expect(subject.send(:ask_question, Faker::Lorem.sentence)).to be_nil
95
+ allow(highline_wrapper).to receive(:ask).and_return(nil)
96
+ expect(subject.send(:ask_question, Faker::Lorem.sentence, nil)).to be_nil
98
97
  end
99
98
 
100
99
  it 'should return the answer if it is given' do
101
100
  answer = Faker::Lorem.sentence
102
- allow(highline_cli).to receive(:ask).and_return(answer)
103
- expect(subject.send(:ask_question, Faker::Lorem.sentence)).to be(answer)
101
+ allow(highline_wrapper).to receive(:ask).and_return(answer)
102
+ expect(subject.send(:ask_question, Faker::Lorem.sentence, :default)).to be(answer)
104
103
  end
105
104
  end
106
105
 
107
106
  describe '#self.ask_config_questions' do
108
107
  it 'should call to ask at least four questions' do
109
- expect(subject).to receive(:ask_question).at_least(4).times
108
+ expect(subject).to receive(:ask_question).at_least(4).times.and_return(Faker::Lorem.word)
110
109
  subject.send(:ask_config_questions)
111
110
  end
112
111
 
113
- it 'should exit if the slack URL is not given' do
114
- allow(subject).to receive(:ask_question).and_return(nil)
115
- expect { subject.send(:ask_config_questions) }.to raise_error(SystemExit)
116
- end
117
-
118
112
  it 'should return the defaults if nothing is given' do
119
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
120
  allow(subject).to receive(:ask_question).with(
121
- "\nWhat is your Slack webhook URL? If you don't have one yet, please navigate" \
122
- ' to https://api.slack.com/messaging/webhooks to create one, and then come back' \
123
- ' here and paste it in the Terminal.'
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
+ nil,
123
+ required: true
124
124
  ).and_return(slack_url)
125
- allow(subject).to receive(:ask_question).and_return(nil)
126
- expect(subject.send(:ask_config_questions)).to eq(
127
- {
128
- channel: 'general',
129
- username: "Let's Get Quoty",
130
- webhook_url: slack_url,
131
- icon_emoji: ':mailbox_with_mail:'
132
- }
133
- )
125
+ allow(subject).to receive(:ask_question).with(
126
+ 'What slack channel do you wish to post to? (default is "#general")',
127
+ '#general'
128
+ ).and_return('general')
129
+ allow(subject).to receive(:ask_question).with(
130
+ "What slack username do you wish to post as? (default is \"Let's Get Quoty\")",
131
+ "Let's Get Quoty"
132
+ ).and_return("Let's Get Quoty")
133
+ allow(subject).to receive(:ask_question).with(
134
+ '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:")',
135
+ ':mailbox_with_mail:'
136
+ ).and_return(':mailbox_with_mail:')
137
+ expect(subject.send(:ask_config_questions)).to eq(defaults)
134
138
  end
135
139
  end
136
140
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack_messaging
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.2.0
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-01 00:00:00.000000000 Z
11
+ date: 2021-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activesupport
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '6.0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '6.0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: gli
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -53,19 +39,19 @@ dependencies:
53
39
  - !ruby/object:Gem::Version
54
40
  version: '4.1'
55
41
  - !ruby/object:Gem::Dependency
56
- name: highline
42
+ name: highline_wrapper
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '2.0'
47
+ version: '1.1'
62
48
  type: :runtime
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: '2.0'
54
+ version: '1.1'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: httparty
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -94,20 +80,6 @@ dependencies:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
82
  version: '2.5'
97
- - !ruby/object:Gem::Dependency
98
- name: rack
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '2.2'
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '2.2'
111
83
  - !ruby/object:Gem::Dependency
112
84
  name: bundler
113
85
  requirement: !ruby/object:Gem::Requirement
@@ -164,20 +136,6 @@ dependencies:
164
136
  - - "~>"
165
137
  - !ruby/object:Gem::Version
166
138
  version: '0.13'
167
- - !ruby/object:Gem::Dependency
168
- name: rake
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - "~>"
172
- - !ruby/object:Gem::Version
173
- version: '13.0'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - "~>"
179
- - !ruby/object:Gem::Version
180
- version: '13.0'
181
139
  - !ruby/object:Gem::Dependency
182
140
  name: rspec
183
141
  requirement: !ruby/object:Gem::Requirement
@@ -196,17 +154,18 @@ dependencies:
196
154
  name: rubocop
197
155
  requirement: !ruby/object:Gem::Requirement
198
156
  requirements:
199
- - - ">="
157
+ - - "~>"
200
158
  - !ruby/object:Gem::Version
201
- version: '0'
159
+ version: '1.10'
202
160
  type: :development
203
161
  prerelease: false
204
162
  version_requirements: !ruby/object:Gem::Requirement
205
163
  requirements:
206
- - - ">="
164
+ - - "~>"
207
165
  - !ruby/object:Gem::Version
208
- version: '0'
209
- description: Sending Personalized Slack Messages to a Slack channel of your choice.
166
+ version: '1.10'
167
+ description: Sending personalized messages and quotes to a Slack channel of your choice
168
+ via the command-line.
210
169
  email:
211
170
  executables:
212
171
  - slack-messaging
@@ -216,7 +175,7 @@ files:
216
175
  - Gemfile
217
176
  - Gemfile.lock
218
177
  - Guardfile
219
- - LICENSE
178
+ - LICENSE.md
220
179
  - QuoteExample.png
221
180
  - README.md
222
181
  - Rakefile
@@ -224,21 +183,19 @@ files:
224
183
  - lib/slack_messaging.rb
225
184
  - lib/slack_messaging/config.rb
226
185
  - lib/slack_messaging/default_paths.rb
227
- - lib/slack_messaging/highline_cli.rb
228
186
  - lib/slack_messaging/notify_slack.rb
229
187
  - lib/slack_messaging/random_message.rb
230
188
  - lib/slack_messaging/send.rb
231
189
  - lib/slack_messaging/setup.rb
232
190
  - lib/slack_messaging/version.rb
233
191
  - spec/slack_messaging/config_spec.rb
234
- - spec/slack_messaging/highline_cli_spec.rb
235
192
  - spec/slack_messaging/notify_slack_spec.rb
236
193
  - spec/slack_messaging/random_message_spec.rb
237
194
  - spec/slack_messaging/setup_spec.rb
238
195
  - spec/spec_helper.rb
239
196
  homepage: https://github.com/emmahsax/slack_messaging
240
197
  licenses:
241
- - MIT
198
+ - BSD-3-Clause
242
199
  metadata: {}
243
200
  post_install_message:
244
201
  rdoc_options: []
@@ -255,14 +212,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
255
212
  - !ruby/object:Gem::Version
256
213
  version: '0'
257
214
  requirements: []
258
- rubygems_version: 3.2.3
215
+ rubygems_version: 3.2.15
259
216
  signing_key:
260
217
  specification_version: 4
261
- summary: Personalized Slack Messages
218
+ summary: Personalized quotes and messages sent straight to Slack
262
219
  test_files:
263
220
  - spec/spec_helper.rb
264
221
  - spec/slack_messaging/config_spec.rb
265
- - spec/slack_messaging/highline_cli_spec.rb
266
222
  - spec/slack_messaging/notify_slack_spec.rb
267
223
  - spec/slack_messaging/random_message_spec.rb
268
224
  - spec/slack_messaging/setup_spec.rb
data/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2014 Emma Sax
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SlackMessaging
4
- class HighlineCli
5
- def ask(prompt)
6
- highline_client.ask(prompt) do |conf|
7
- conf.readline = true
8
- end.to_s
9
- end
10
-
11
- def ask_yes_no(prompt)
12
- answer = highline_client.ask(prompt) do |conf|
13
- conf.readline = true
14
- end.to_s
15
-
16
- answer.empty? ? true : !!(answer =~ /^y/i)
17
- end
18
-
19
- def ask_options(prompt, choices)
20
- choices_as_string_options = ''.dup
21
- choices.each { |choice| choices_as_string_options << "#{choices.index(choice) + 1}. #{choice}\n" }
22
- compiled_prompt = "#{prompt}\n#{choices_as_string_options.strip}"
23
-
24
- index = highline_client.ask(compiled_prompt) do |conf|
25
- conf.readline = true
26
- end.to_i - 1
27
-
28
- choices[index]
29
- end
30
-
31
- private def highline_client
32
- @highline_client ||= HighLine.new
33
- end
34
- end
35
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'slack_messaging'
5
-
6
- describe SlackMessaging::HighlineCli do
7
- let(:response) { double(:response, readline: true, to_i: 3) }
8
- let(:highline_client) { double(:highline_cli, ask: response) }
9
-
10
- before do
11
- allow(HighLine).to receive(:new).and_return(highline_client)
12
- end
13
-
14
- describe '#ask' do
15
- it 'should ask the highline client ask' do
16
- expect(highline_client).to receive(:ask)
17
- subject.ask(Faker::Lorem.sentence)
18
- end
19
-
20
- it 'should return a string' do
21
- expect(subject.ask(Faker::Lorem.sentence)).to be_a(String)
22
- end
23
- end
24
-
25
- describe '#ask_yes_no' do
26
- it 'should ask the highline client ask' do
27
- expect(highline_client).to receive(:ask)
28
- subject.ask_yes_no(Faker::Lorem.sentence)
29
- end
30
-
31
- it 'should return a boolean' do
32
- expect(subject.ask_yes_no(Faker::Lorem.sentence)).to be_falsey
33
- end
34
-
35
- it 'should return true if we say yes' do
36
- allow(response).to receive(:to_s).and_return('y')
37
- expect(subject.ask_yes_no(Faker::Lorem.sentence)).to be_truthy
38
- end
39
- end
40
-
41
- describe '#ask_options' do
42
- it 'should ask the highline client ask' do
43
- expect(highline_client).to receive(:ask)
44
- subject.ask_options(Faker::Lorem.sentence, %w[one two three])
45
- end
46
-
47
- it 'should return a string from the options' do
48
- expect(subject.ask_options(Faker::Lorem.sentence, %w[one two three])).to be_a(String)
49
- end
50
- end
51
- end