slack_messaging 2.0.0 → 3.1.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: db2a04a6f53bd5e7d0d1017fe6fd5f6c715cc89d108be3dad1eb3a433f944be0
4
- data.tar.gz: 5487fbcfcf279a48911d773c928826b8f7b2e021710d457c0fa256fa1660562e
3
+ metadata.gz: b90f38dcdaf24ec98961f9cf3311570daf0087c1308b63483762d158f04161f7
4
+ data.tar.gz: 5e8fdef06dd5285ff63d922ca7e1b8e18eef0149104e26a155d8d1bb5916576e
5
5
  SHA512:
6
- metadata.gz: 76485ac006bb26c047e57e06283ced474b36c5924229dbd58b83a3ea8e2e30e92e8ca916fb7fd24b538ad235a54f427f29e03e4f1dcff382b57eb69d7b71e578
7
- data.tar.gz: fe229444fe0b9a050d29a6b8c2fc653f287b85d49f965efc76cc81b5f7f3eb677fd79376a0fff012460febc1cd61d4896e9b6f0cf2098557b7a34130de155c42
6
+ metadata.gz: 2461540b052fc9a790da9e2e11da01b496d08260db928c61c7e11dcd67add9a75e15feab6f03f8dcb029807db6f6205a3fa517d358bc629f606732bed3397b7f
7
+ data.tar.gz: 17dcb6ba4aa5f6c98d29611c3e08bb05080aa009c66de4e97ded5194fb31dd3296d4bae091ec9eedc59f142e8d4d862c1d28809a705a0f5282652c1f4f6b049c
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in slack_messaging.gemspec
data/Gemfile.lock CHANGED
@@ -1,30 +1,31 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slack_messaging (2.0.0.pre.test)
4
+ slack_messaging (3.1.0)
5
5
  activesupport (~> 6.0)
6
6
  gli (~> 2.10)
7
7
  hashie (~> 4.1)
8
- highline (~> 2.0)
9
- httparty
10
- json
8
+ highline_wrapper (~> 0.1.0)
9
+ httparty (~> 0.18)
10
+ json (~> 2.5)
11
11
  rack (~> 2.2)
12
12
 
13
13
  GEM
14
14
  remote: https://rubygems.org/
15
15
  specs:
16
- activesupport (6.0.3.4)
16
+ activesupport (6.1.2.1)
17
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
- i18n (>= 0.7, < 2)
19
- minitest (~> 5.1)
20
- tzinfo (~> 1.1)
21
- zeitwerk (~> 2.2, >= 2.2.2)
18
+ i18n (>= 1.6, < 2)
19
+ minitest (>= 5.1)
20
+ tzinfo (~> 2.0)
21
+ zeitwerk (~> 2.3)
22
+ ast (2.4.2)
22
23
  coderay (1.1.3)
23
- concurrent-ruby (1.1.7)
24
+ concurrent-ruby (1.1.8)
24
25
  diff-lcs (1.4.4)
25
- faker (2.14.0)
26
+ faker (2.15.1)
26
27
  i18n (>= 1.6, < 2)
27
- ffi (1.13.1)
28
+ ffi (1.14.2)
28
29
  formatador (0.2.5)
29
30
  gli (2.19.2)
30
31
  guard (2.16.2)
@@ -43,13 +44,15 @@ GEM
43
44
  rspec (>= 2.99.0, < 4.0)
44
45
  hashie (4.1.0)
45
46
  highline (2.0.3)
47
+ highline_wrapper (0.1.0)
48
+ highline (~> 2.0)
46
49
  httparty (0.18.1)
47
50
  mime-types (~> 3.0)
48
51
  multi_xml (>= 0.5.2)
49
- i18n (1.8.5)
52
+ i18n (1.8.8)
50
53
  concurrent-ruby (~> 1.0)
51
- json (2.3.1)
52
- listen (3.3.1)
54
+ json (2.5.1)
55
+ listen (3.4.1)
53
56
  rb-fsevent (~> 0.10, >= 0.10.3)
54
57
  rb-inotify (~> 0.9, >= 0.9.10)
55
58
  lumberjack (1.2.8)
@@ -57,51 +60,70 @@ GEM
57
60
  mime-types (3.3.1)
58
61
  mime-types-data (~> 3.2015)
59
62
  mime-types-data (3.2020.1104)
60
- minitest (5.14.2)
63
+ minitest (5.14.3)
61
64
  multi_xml (0.6.0)
62
65
  nenv (0.3.0)
63
66
  notiffany (0.1.3)
64
67
  nenv (~> 0.1)
65
68
  shellany (~> 0.0)
66
- pry (0.13.1)
69
+ parallel (1.20.1)
70
+ parser (3.0.0.0)
71
+ ast (~> 2.4.1)
72
+ pry (0.14.0)
67
73
  coderay (~> 1.1)
68
74
  method_source (~> 1.0)
69
75
  rack (2.2.3)
70
- rake (13.0.1)
76
+ rainbow (3.0.0)
77
+ rake (13.0.3)
71
78
  rb-fsevent (0.10.4)
72
79
  rb-inotify (0.10.1)
73
80
  ffi (~> 1.0)
81
+ regexp_parser (2.1.1)
82
+ rexml (3.2.4)
74
83
  rspec (3.10.0)
75
84
  rspec-core (~> 3.10.0)
76
85
  rspec-expectations (~> 3.10.0)
77
86
  rspec-mocks (~> 3.10.0)
78
- rspec-core (3.10.0)
87
+ rspec-core (3.10.1)
79
88
  rspec-support (~> 3.10.0)
80
- rspec-expectations (3.10.0)
89
+ rspec-expectations (3.10.1)
81
90
  diff-lcs (>= 1.2.0, < 2.0)
82
91
  rspec-support (~> 3.10.0)
83
- rspec-mocks (3.10.0)
92
+ rspec-mocks (3.10.2)
84
93
  diff-lcs (>= 1.2.0, < 2.0)
85
94
  rspec-support (~> 3.10.0)
86
- rspec-support (3.10.0)
95
+ rspec-support (3.10.2)
96
+ rubocop (1.10.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)
87
108
  shellany (0.0.1)
88
- thor (1.0.1)
89
- thread_safe (0.3.6)
90
- tzinfo (1.2.8)
91
- thread_safe (~> 0.1)
92
- zeitwerk (2.4.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)
93
114
 
94
115
  PLATFORMS
95
- ruby
116
+ x86_64-darwin-19
96
117
 
97
118
  DEPENDENCIES
98
- bundler (~> 2.1)
99
- faker
119
+ bundler (~> 2.2)
120
+ faker (~> 2.15)
100
121
  guard-rspec (~> 4.3)
101
- pry
122
+ pry (~> 0.13)
102
123
  rake (~> 13.0)
103
124
  rspec (~> 3.9)
125
+ rubocop (~> 1.10)
104
126
  slack_messaging!
105
127
 
106
128
  BUNDLED WITH
107
- 2.1.4
129
+ 2.2.9
data/Guardfile CHANGED
@@ -1,4 +1,6 @@
1
- guard :rspec, cmd: 'bundle exec rspec', all_on_start: true, all_after_pass: true do
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/QuoteExample.png ADDED
Binary file
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Slack Messaging [![Maintainability](https://api.codeclimate.com/v1/badges/c74baada70ad96048dc7/maintainability)](https://codeclimate.com/github/emmasax4/slack_messaging/maintainability) ![Default](https://github.com/emmasax4/slack_messaging/workflows/Default/badge.svg)
1
+ # Slack Messaging [![Main](https://github.com/emmahsax/slack_messaging/actions/workflows/main.yml/badge.svg)](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,61 +26,75 @@ 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
- channel: "#<AWESOME CHANNEL NAME>"
31
+ channel: <AWESOME CHANNEL NAME>
32
32
  username: <AWESOME USER NAME>
33
- webhook_url: <WEBHOOK URL>
34
- icon_emoji: ":<SOME EMOJI>:"
33
+ webhook_url: <SLACK WEBHOOK URL>
34
+ icon_emoji: ':<SOME EMOJI>:'
35
35
  ```
36
36
 
37
- The default is for the file to be named `~/.slack_messaging.yml`, but a different path can be passed in like this:
37
+ To generate this file at `~/.slack_messaging.yml`, please run this command:
38
38
 
39
+ ```bash
40
+ slack-messaging setup
39
41
  ```
40
- $ slack-messaging --config="/PATH/TO/FILE/config.yml" slack
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
- To obtain the webhook url, go to [this link](https://api.slack.com/incoming-webhooks).
53
+ And then you can pass in that specific file location like this:
44
54
 
45
- Okay, now the project will be ready to rock and roll.
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 slack
63
+ ```bash
64
+ slack-messaging send
51
65
  ```
52
66
 
53
- from the main directory. 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/).
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 slack "MESSAGE 1"
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 slack "MESSAGE 1" "MESSAGE 2" "MESSAGE 3" ... "MESSAGE N"
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/emmasax4/slack_messaging/blob/main/OutputFile.png" width="1000">
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 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!
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/emmasax4/slack_messaging/issues/new).
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/emmasax4/slack_messaging/security/policy).
95
+ To report any security vulnerabilities, please view this project's [Security Policy](https://github.com/emmahsax/slack_messaging/security/policy).
82
96
 
83
- This repository does have a standard [Code of Conduct](https://github.com/emmasax4/slack_messaging/blob/main/.github/code_of_conduct.md).
97
+ When interacting with this repository, please follow [Contributor Covenant's Code of Conduct](https://contributor-covenant.org).
84
98
 
85
99
  ## Releasing
86
100
 
@@ -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/emmasax4/slack_messaging/releases/new)
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
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
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,31 @@ version SlackMessaging::VERSION
10
13
 
11
14
  wrap_help_text :verbatim
12
15
 
13
- flag [:config], :desc => 'SlackMessaging config file path', :default_value => SlackMessaging::DefaultPaths.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
+ "
18
23
 
19
24
  desc 'Prints a variety of messages to Slack'
20
- command 'slack' do |c|
21
- c.action do |global_options, options, args|
22
- SlackMessaging::Slack.execute(args, options)
25
+ command 'send' do |c|
26
+ pre do |global, _command, _options, _args|
27
+ SlackMessaging::Config.load(global[:config])
28
+ true
29
+ end
30
+
31
+ c.action do |_global_options, options, args|
32
+ SlackMessaging::Send.execute(args, options)
23
33
  end
24
34
  end
25
35
 
26
- pre do |global,command,options,args|
27
- SlackMessaging::Config.load(global[:config])
28
- SlackMessaging::Config.set_config_options(global)
29
- true
36
+ desc 'Sets up a Slack Messaging config file at ~/.slack_messaging.yml'
37
+ command 'setup' do |c|
38
+ c.action do
39
+ SlackMessaging::Setup.execute
40
+ end
30
41
  end
31
42
 
32
43
  exit run(ARGV)
@@ -1,10 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'hashie'
3
5
  require 'httparty'
4
- require 'highline'
6
+ require 'highline_wrapper'
5
7
  require 'json'
6
8
 
7
- Dir[File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), 'slack_messaging')) + '/**/*.rb'].each do |file|
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SlackMessaging
2
4
  class Config
3
5
  def self.config
@@ -9,8 +11,6 @@ module SlackMessaging
9
11
  config
10
12
  end
11
13
 
12
- private
13
-
14
14
  def self.config_data
15
15
  @config_data ||= Hashie::Mash.new
16
16
  end
@@ -21,6 +21,7 @@ module SlackMessaging
21
21
 
22
22
  def self.load_config(file)
23
23
  raise MissingConfig, "Missing configuration file: #{file}" unless File.exist?(file)
24
+
24
25
  YAML.load_file(file).each { |key, value| config_data.assign_property(key, value) }
25
26
  end
26
27
  end
@@ -1,13 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SlackMessaging
2
4
  class DefaultPaths
3
5
  def self.config
4
- File.join(self.home, '.slack_messaging.yml')
6
+ File.join(home, '.slack_messaging.yml')
5
7
  end
6
8
 
7
- private
8
-
9
9
  def self.home
10
- ENV['HOME'] ? ENV['HOME'] : '.'
10
+ ENV['HOME'] || '.'
11
11
  end
12
12
  end
13
13
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SlackMessaging
2
4
  class NotifySlack
3
5
  attr_accessor :text, :channel, :webhook_url, :username, :icon_url, :icon_emoji
@@ -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
- return "\"#{quote_content}\"" + "\n" + "—#{quote_author}"
9
+ "\"#{quote_content}\"\n—#{quote_author}"
8
10
  end
9
11
  end
10
12
  end
@@ -1,20 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SlackMessaging
2
- class Slack
4
+ class Send
3
5
  attr_accessor :options
4
6
 
5
- def self.execute(args, options = nil)
7
+ def self.execute(args, _options = nil)
6
8
  if args.empty?
7
9
  message = SlackMessaging::RandomMessage.acquire_random_quote
8
10
  print_message(message)
9
11
  else
10
- args.each do |message|
11
- print_message(message)
12
+ args.each do |arg_message|
13
+ print_message(arg_message)
12
14
  end
13
15
  end
14
16
  end
15
17
 
16
- private
17
-
18
18
  def self.print_message(message)
19
19
  SlackMessaging::NotifySlack.new(message).perform
20
20
  end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlackMessaging
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
17
+
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
24
+
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
34
+
35
+ def self.config_file_exists?
36
+ File.exist?(default_config)
37
+ end
38
+
39
+ # rubocop:disable Metrics/MethodLength
40
+ def self.ask_config_questions
41
+ answers = {}
42
+
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
+ required: true
48
+ )
49
+
50
+ answers[:channel] = ask_question(
51
+ "\nWhat slack channel do you wish to post to? (default is \"#general\")"
52
+ ) || 'general'
53
+
54
+ answers[:username] = ask_question(
55
+ "\nWhat slack username do you wish to post as? (default is \"Let's Get Quoty\")"
56
+ ) || "Let's Get Quoty"
57
+
58
+ answers[:icon_emoji] = ask_question(
59
+ "\nWhat emoji would you like to post with (include the colons at the beginning and end" \
60
+ ' of the emoji name)? (default is ":mailbox_with_mail:")'
61
+ ) || ':mailbox_with_mail:'
62
+
63
+ answers
64
+ end
65
+ # rubocop:enable Metrics/MethodLength
66
+
67
+ # rubocop:disable Metrics/MethodLength
68
+ def self.ask_question(prompt, required: false)
69
+ answer = highline.ask(prompt)
70
+
71
+ if required
72
+ if answer.empty?
73
+ puts "\nThis question is required.\n\n"
74
+ ask_question(prompt, required: true)
75
+ else
76
+ answer
77
+ end
78
+ else
79
+ answer.empty? ? nil : answer
80
+ end
81
+ end
82
+ # rubocop:enable Metrics/MethodLength
83
+
84
+ def self.highline
85
+ @highline ||= HighlineWrapper.new
86
+ end
87
+
88
+ def self.default_config
89
+ SlackMessaging::DefaultPaths.config
90
+ end
91
+ end
92
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SlackMessaging
2
- VERSION = '2.0.0'
4
+ VERSION = '3.1.0'
3
5
  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(SlackMessaging::Config.doesnt_exist).to eql(nil)
8
- expect(SlackMessaging::Config.doesnt_exist?).to eql(false)
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
- SlackMessaging::Config.new_value = config_value
14
- expect(SlackMessaging::Config.new_value).to eql(config_value)
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
- 'domain': domain,
25
- 'slack': {
26
- 'slack_option': true,
27
- 'username': Faker::Name.name,
28
- 'icon_url': Faker::Internet.url,
29
- 'channel': Faker::Lorem.word,
30
- 'webhook': Faker::Internet.url
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
- SlackMessaging::Config.load(Faker::Lorem.word)
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(SlackMessaging::Config.domain).to eql(domain)
43
- expect(SlackMessaging::Config.slack).to be_kind_of(Hash)
44
- expect(SlackMessaging::Config.slack[:slack_option]).to eql(true)
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(SlackMessaging::Config.slack).to be_kind_of(Hash)
49
- SlackMessaging::Config.slack = sentence
50
- expect(SlackMessaging::Config.slack).to eql(sentence)
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
- 'slack': {
14
- 'slack_option': true,
15
- 'username': username,
16
- 'icon_emoji': emoji,
17
- 'channel': channel,
18
- 'webhook_url': webhook
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
- message = SlackMessaging::NotifySlack.new(sentence)
32
- message.perform
35
+ subject.perform
33
36
  end
34
37
 
35
- it 'should define certain values' do
36
- message = SlackMessaging::NotifySlack.new(sentence)
37
- expect(message.text).to eq(sentence)
38
- expect(message.channel).to eq(channel)
39
- expect(message.username).to eq(username)
40
- expect(message.webhook_url).to eq(webhook)
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 = SlackMessaging::RandomMessage.acquire_random_quote
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 = SlackMessaging::RandomMessage.acquire_random_quote
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 = SlackMessaging::RandomMessage.acquire_random_quote
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
- SlackMessaging::RandomMessage.acquire_random_quote
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
- SlackMessaging::RandomMessage.acquire_random_quote
45
+ subject.acquire_random_quote
42
46
  end
43
47
  end
@@ -0,0 +1,155 @@
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 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
+ it 'should return the defaults if nothing is given' do
132
+ slack_url = Faker::Internet.url
133
+ defaults = {
134
+ channel: 'general',
135
+ username: "Let's Get Quoty",
136
+ webhook_url: slack_url,
137
+ icon_emoji: ':mailbox_with_mail:'
138
+ }
139
+ allow(subject).to receive(:ask_question).with(
140
+ "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.",
141
+ required: true
142
+ ).and_return(slack_url)
143
+ allow(subject).to receive(:ask_question).with(
144
+ "\nWhat slack channel do you wish to post to? (default is \"#general\")"
145
+ ).and_return(nil)
146
+ allow(subject).to receive(:ask_question).with(
147
+ "\nWhat slack username do you wish to post as? (default is \"Let's Get Quoty\")"
148
+ ).and_return(nil)
149
+ allow(subject).to receive(:ask_question).with(
150
+ "\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:\")"
151
+ ).and_return(nil)
152
+ expect(subject.send(:ask_config_questions)).to eq(defaults)
153
+ end
154
+ end
155
+ 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 :focus => true
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: 2.0.0
4
+ version: 3.1.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: 2020-11-20 00:00:00.000000000 Z
11
+ date: 2021-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -53,47 +53,47 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '4.1'
55
55
  - !ruby/object:Gem::Dependency
56
- name: highline
56
+ name: highline_wrapper
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.0'
61
+ version: 0.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: '2.0'
68
+ version: 0.1.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: httparty
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '0.18'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '0.18'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: json
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '2.5'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '2.5'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rack
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -114,28 +114,28 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '2.1'
117
+ version: '2.2'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '2.1'
124
+ version: '2.2'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: faker
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '0'
131
+ version: '2.15'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '0'
138
+ version: '2.15'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: guard-rspec
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -154,16 +154,16 @@ dependencies:
154
154
  name: pry
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ">="
157
+ - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '0'
159
+ version: '0.13'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ">="
164
+ - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '0'
166
+ version: '0.13'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: rake
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -192,9 +192,22 @@ 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: []
@@ -204,7 +217,7 @@ files:
204
217
  - Gemfile.lock
205
218
  - Guardfile
206
219
  - LICENSE
207
- - OutputFile.png
220
+ - QuoteExample.png
208
221
  - README.md
209
222
  - Rakefile
210
223
  - bin/slack-messaging
@@ -213,13 +226,15 @@ files:
213
226
  - lib/slack_messaging/default_paths.rb
214
227
  - lib/slack_messaging/notify_slack.rb
215
228
  - lib/slack_messaging/random_message.rb
216
- - lib/slack_messaging/slack.rb
229
+ - lib/slack_messaging/send.rb
230
+ - lib/slack_messaging/setup.rb
217
231
  - lib/slack_messaging/version.rb
218
232
  - spec/slack_messaging/config_spec.rb
219
233
  - spec/slack_messaging/notify_slack_spec.rb
220
234
  - spec/slack_messaging/random_message_spec.rb
235
+ - spec/slack_messaging/setup_spec.rb
221
236
  - spec/spec_helper.rb
222
- homepage: https://github.com/emmasax4/slack_messaging
237
+ homepage: https://github.com/emmahsax/slack_messaging
223
238
  licenses:
224
239
  - MIT
225
240
  metadata: {}
@@ -231,19 +246,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
231
246
  requirements:
232
247
  - - ">="
233
248
  - !ruby/object:Gem::Version
234
- version: '0'
249
+ version: '2.4'
235
250
  required_rubygems_version: !ruby/object:Gem::Requirement
236
251
  requirements:
237
252
  - - ">="
238
253
  - !ruby/object:Gem::Version
239
254
  version: '0'
240
255
  requirements: []
241
- rubygems_version: 3.1.4
256
+ rubygems_version: 3.2.3
242
257
  signing_key:
243
258
  specification_version: 4
244
259
  summary: Personalized Slack Messages
245
260
  test_files:
246
261
  - spec/spec_helper.rb
247
262
  - spec/slack_messaging/config_spec.rb
248
- - spec/slack_messaging/random_message_spec.rb
249
263
  - spec/slack_messaging/notify_slack_spec.rb
264
+ - spec/slack_messaging/random_message_spec.rb
265
+ - spec/slack_messaging/setup_spec.rb
data/OutputFile.png DELETED
Binary file