slack_messaging 1.2.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Guardfile +5 -0
- data/{LICENSE.txt → LICENSE} +1 -1
- data/QuoteExample.png +0 -0
- data/README.md +31 -19
- data/Rakefile +1 -2
- data/bin/slack-messaging +6 -1
- data/lib/slack_messaging.rb +9 -7
- data/lib/slack_messaging/config.rb +17 -38
- data/lib/slack_messaging/default_paths.rb +13 -0
- data/lib/slack_messaging/notify_slack.rb +10 -11
- data/lib/slack_messaging/random_message.rb +5 -29
- data/lib/slack_messaging/slack.rb +22 -0
- data/lib/slack_messaging/version.rb +1 -1
- data/spec/slack_messaging/config_spec.rb +42 -33
- data/spec/slack_messaging/notify_slack_spec.rb +38 -29
- data/spec/slack_messaging/random_message_spec.rb +41 -24
- data/spec/spec_helper.rb +5 -5
- metadata +82 -56
- data/.codeclimate.yml +0 -37
- data/.github/code_of_conduct.md +0 -85
- data/.github/issue_template.md +0 -97
- data/.github/pull_request_template.md +0 -19
- data/.github/security.md +0 -11
- data/.github/workflows/develop.yml +0 -30
- data/.gitignore +0 -18
- data/.octopolo.yml +0 -4
- data/.rspec +0 -2
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/.soyuz.yml +0 -12
- data/CHANGELOG.markdown +0 -11
- data/CODE_OF_CONDUCT.md +0 -76
- data/CONTRIBUTING.md +0 -11
- data/OutputFile.png +0 -0
- data/lib/slack_messaging/commands/slack.rb +0 -7
- data/lib/slack_messaging/output.rb +0 -13
- data/lib/slack_messaging/scripts/slack.rb +0 -29
- data/slack_messaging.gemspec +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6ace0c951c1c91d3e1e55ecfaf4c07979b7bbea225d89e55e73c63a1c51e5a4
|
4
|
+
data.tar.gz: 18d9438426df6aa452ba1946c773b63befe71e5e28d2f0e4dc761a14c41952f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c754f66c000c328697834a8d139587632849b94e4809e924847088a3c7a7b78f6ff3291e252235fdb28aa7d048e2ca8104c3b48764919fe4c65d0fe4c57832b6
|
7
|
+
data.tar.gz: 24c2befeb5629d2e7b6a40a3ca761c3dcc00a91cff80a415c2f32a311b9b9705800ee766a0b4c2e621ff011b3763997061eae1f977951803e96bd0dd78895785
|
data/Guardfile
ADDED
data/{LICENSE.txt → LICENSE}
RENAMED
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) ![
|
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)
|
2
2
|
|
3
3
|
This is a simple project designed to post messages to a given Slack channel as a bot.
|
4
4
|
|
@@ -12,11 +12,15 @@ gem 'slack_messaging'
|
|
12
12
|
|
13
13
|
And then execute:
|
14
14
|
|
15
|
-
|
15
|
+
```bash
|
16
|
+
bundle install
|
17
|
+
```
|
16
18
|
|
17
19
|
Or install it yourself as:
|
18
20
|
|
19
|
-
|
21
|
+
```bash
|
22
|
+
gem install slack_messaging
|
23
|
+
```
|
20
24
|
|
21
25
|
### Usage
|
22
26
|
|
@@ -24,15 +28,17 @@ This project requires a config file that should look like this:
|
|
24
28
|
|
25
29
|
```
|
26
30
|
slack:
|
27
|
-
channel:
|
28
|
-
username:
|
29
|
-
webhook_url:
|
30
|
-
icon_emoji: "
|
31
|
+
channel: <AWESOME CHANNEL NAME>
|
32
|
+
username: <AWESOME USER NAME>
|
33
|
+
webhook_url: <SLACK WEBHOOK URL>
|
34
|
+
icon_emoji: ":<SOME EMOJI>:"
|
31
35
|
```
|
32
36
|
|
33
37
|
The default is for the file to be named `~/.slack_messaging.yml`, but a different path can be passed in like this:
|
34
38
|
|
35
|
-
|
39
|
+
```
|
40
|
+
$ slack-messaging --config="/PATH/TO/FILE/config.yml" slack
|
41
|
+
```
|
36
42
|
|
37
43
|
To obtain the webhook url, go to [this link](https://api.slack.com/incoming-webhooks).
|
38
44
|
|
@@ -44,7 +50,7 @@ To print a friendly message to Slack, run:
|
|
44
50
|
slack-messaging slack
|
45
51
|
```
|
46
52
|
|
47
|
-
from the main directory. Here, no specific message is being given to print to Slack, so slack_messaging will choose a random quote
|
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/).
|
48
54
|
|
49
55
|
However, what if you wanted to print something specific? Well, you can! Just run:
|
50
56
|
|
@@ -60,25 +66,31 @@ slack-messaging slack "MESSAGE 1" "MESSAGE 2" "MESSAGE 3" ... "MESSAGE N"
|
|
60
66
|
|
61
67
|
The output of slack_messaging will look something like this:
|
62
68
|
|
63
|
-
<img src="https://github.com/emmasax4/slack_messaging/blob/main/
|
69
|
+
<img src="https://github.com/emmasax4/slack_messaging/blob/main/QuoteExample.png" width="500">
|
64
70
|
|
65
71
|
I hope you enjoy printing fun and specialized messages to Slack!
|
66
72
|
|
67
73
|
### Tests
|
68
74
|
|
69
|
-
To run the tests, run `rspec` from the command line.
|
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!
|
76
|
+
|
77
|
+
## Contributing
|
70
78
|
|
71
|
-
|
72
|
-
To make a new version and push to RubyGems:
|
79
|
+
To submit a feature request, bug ticket, etc, please submit an official [GitHub Issue](https://github.com/emmasax4/slack_messaging/issues/new).
|
73
80
|
|
74
|
-
|
81
|
+
To report any security vulnerabilities, please view this project's [Security Policy](https://github.com/emmasax4/slack_messaging/security/policy).
|
75
82
|
|
76
|
-
|
83
|
+
When interacting with this repository, please follow [Contributor Covenant's Code of Conduct](https://contributor-covenant.org).
|
77
84
|
|
78
|
-
|
85
|
+
## Releasing
|
79
86
|
|
80
|
-
|
87
|
+
To make a new release of this gem:
|
81
88
|
|
82
|
-
|
89
|
+
1. Merge the pull request via the big green button
|
90
|
+
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)
|
92
|
+
4. Run `gem build *.gemspec`
|
93
|
+
5. Run `gem push *.gem` to push the new gem to RubyGems
|
94
|
+
6. Run `rm *.gem` to clean up your local repository
|
83
95
|
|
84
|
-
|
96
|
+
To set up your local machine to push to RubyGems via the API, see the [RubyGems documentation](https://guides.rubygems.org/publishing/#publishing-to-rubygemsorg).
|
data/Rakefile
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/slack-messaging
CHANGED
@@ -16,7 +16,12 @@ program_long_desc """
|
|
16
16
|
DOCUMENTATION
|
17
17
|
"""
|
18
18
|
|
19
|
-
|
19
|
+
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)
|
23
|
+
end
|
24
|
+
end
|
20
25
|
|
21
26
|
pre do |global,command,options,args|
|
22
27
|
SlackMessaging::Config.load(global[:config])
|
data/lib/slack_messaging.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
module SlackMessaging
|
1
|
+
require 'yaml'
|
2
|
+
require 'hashie'
|
3
|
+
require 'httparty'
|
4
|
+
require 'highline'
|
5
|
+
require 'json'
|
8
6
|
|
7
|
+
Dir[File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), 'slack_messaging')) + '/**/*.rb'].each do |file|
|
8
|
+
require_relative file
|
9
9
|
end
|
10
|
+
|
11
|
+
module SlackMessaging; end
|
@@ -1,48 +1,27 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require 'hashie'
|
3
|
-
|
4
1
|
module SlackMessaging
|
5
|
-
|
6
|
-
class DefaultPaths
|
7
|
-
class << self
|
8
|
-
def config
|
9
|
-
File.join(self.home,'.slack_messaging.yml')
|
10
|
-
end
|
11
|
-
|
12
|
-
def home
|
13
|
-
ENV['HOME'] ? ENV['HOME'] : "."
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
2
|
class Config
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
config_data.to_hash
|
23
|
-
end
|
3
|
+
def self.config
|
4
|
+
config_data.to_hash
|
5
|
+
end
|
24
6
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
7
|
+
def self.load(path)
|
8
|
+
load_config(path)
|
9
|
+
config
|
10
|
+
end
|
29
11
|
|
30
|
-
|
31
|
-
@config_data ||= Hashie::Mash.new
|
32
|
-
end
|
33
|
-
private :config_data
|
12
|
+
private
|
34
13
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
private :method_missing
|
14
|
+
def self.config_data
|
15
|
+
@config_data ||= Hashie::Mash.new
|
16
|
+
end
|
39
17
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
private :load_config
|
18
|
+
def self.method_missing(method, args = false)
|
19
|
+
config_data.send(method, args)
|
20
|
+
end
|
45
21
|
|
22
|
+
def self.load_config(file)
|
23
|
+
raise MissingConfig, "Missing configuration file: #{file}" unless File.exist?(file)
|
24
|
+
YAML.load_file(file).each { |key, value| config_data.assign_property(key, value) }
|
46
25
|
end
|
47
26
|
end
|
48
27
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'slack-notifier'
|
2
|
-
|
3
1
|
module SlackMessaging
|
4
2
|
class NotifySlack
|
5
3
|
attr_accessor :text, :channel, :webhook_url, :username, :icon_url, :icon_emoji
|
@@ -8,18 +6,19 @@ module SlackMessaging
|
|
8
6
|
self.text = text
|
9
7
|
self.channel = SlackMessaging::Config.slack[:channel]
|
10
8
|
self.webhook_url = SlackMessaging::Config.slack[:webhook_url]
|
11
|
-
self.username = SlackMessaging::Config.slack[:username] ||
|
12
|
-
self.icon_emoji = SlackMessaging::Config.slack[:icon_emoji] ||
|
9
|
+
self.username = SlackMessaging::Config.slack[:username] || 'MessageMe'
|
10
|
+
self.icon_emoji = SlackMessaging::Config.slack[:icon_emoji] || ':mailbox_with_mail'
|
13
11
|
end
|
14
12
|
|
15
13
|
def perform
|
16
|
-
options = {
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
options = {
|
15
|
+
channel: channel,
|
16
|
+
username: username,
|
17
|
+
icon_emoji: icon_emoji,
|
18
|
+
text: text
|
19
|
+
}
|
20
|
+
|
21
|
+
HTTParty.post(webhook_url, body: options.to_json)
|
23
22
|
end
|
24
23
|
end
|
25
24
|
end
|
@@ -1,34 +1,10 @@
|
|
1
1
|
module SlackMessaging
|
2
2
|
class RandomMessage
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
"I'm convinced of this: Good done anywhere is good done everywhere.\n--Maya Angelou",
|
9
|
-
"The real trouble with reality is that there's no background music.\n--Anonymous",
|
10
|
-
"Whatever you are, be a good one.\n--Abraham Lincoln",
|
11
|
-
"Good, better, best. Never let it rest. 'Til your good is better and your better is best.\n--St. Jerome",
|
12
|
-
"Despite everything, I believe that people are really good at heart.\n--Anne Frank",
|
13
|
-
"Life is 10% what happens to you and 90% how you react to it.\n--Charles R. Swindoll",
|
14
|
-
"The way to get started is to quit talking and begin doing.\n--Walt Disney",
|
15
|
-
"A creative man is motivated by the desire to achieve, not by the desire to beat others.\n--Ayn Rand",
|
16
|
-
"Problems are not stop signs, they are guidelines.\n--Robert H. Schuller",
|
17
|
-
"Correction does much, but encouragement does more.\n--Johann Wolfgang von Goethe",
|
18
|
-
"Positive anything is better than negative nothing.\n--Elbert Hubbard",
|
19
|
-
"To succeed, you need to find something to hold on to, something to motivate you, something to inspire you.\n--Joyce Meyer",
|
20
|
-
"If you're not making mistakes, then you're not doing anything. I'm positive that a doer makes mistakes.\n--John Wooden",
|
21
|
-
"The best way to deal with other people is to just let them be other people.\n--Anonymous",
|
22
|
-
"Talk to yourself like you would to someone you love.\n--Brenee Brown",
|
23
|
-
"Don't let small minds convince you that your dreams are too big.\n--Anonymous",
|
24
|
-
]
|
25
|
-
|
26
|
-
def initialize
|
27
|
-
self.text = MESSAGE_ARRAY[rand(MESSAGE_ARRAY.length)]
|
28
|
-
end
|
29
|
-
|
30
|
-
def get_text
|
31
|
-
return self.text
|
3
|
+
def self.acquire_random_quote
|
4
|
+
random_quote = HTTParty.get('http://api.quotable.io/random', headers: { 'Content-Type': 'application/json' }).body
|
5
|
+
quote_content = JSON.parse(random_quote)['content']
|
6
|
+
quote_author = JSON.parse(random_quote)['author']
|
7
|
+
return "\"#{quote_content}\"" + "\n" + "—#{quote_author}"
|
32
8
|
end
|
33
9
|
end
|
34
10
|
end
|
@@ -0,0 +1,22 @@
|
|
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
|
@@ -1,44 +1,53 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'slack_messaging'
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
describe SlackMessaging::Config do
|
5
|
+
context 'config key methods' do
|
6
|
+
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)
|
9
|
+
end
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
it "should return the config value when set" do
|
13
|
-
SlackMessaging::Config.new_value = "testing"
|
14
|
-
expect(SlackMessaging::Config.new_value).to eql("testing")
|
15
|
-
end
|
11
|
+
it 'should return the config value when set' do
|
12
|
+
config_value = Faker::Lorem.word
|
13
|
+
SlackMessaging::Config.new_value = config_value
|
14
|
+
expect(SlackMessaging::Config.new_value).to eql(config_value)
|
16
15
|
end
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
18
|
+
context 'after loading a config file' do
|
19
|
+
let(:domain) { Faker::Internet.domain_name }
|
20
|
+
let(:sentence) { Faker::Lorem.sentence }
|
21
|
+
|
22
|
+
let(:config_file) do
|
23
|
+
{
|
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
|
31
|
+
}
|
32
|
+
}
|
33
|
+
end
|
30
34
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
35
|
+
before do
|
36
|
+
allow(YAML).to receive(:load_file).and_return(config_file)
|
37
|
+
allow(File).to receive(:exist?).and_return(true)
|
38
|
+
SlackMessaging::Config.load(Faker::Lorem.word)
|
39
|
+
end
|
40
|
+
|
41
|
+
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)
|
45
|
+
end
|
36
46
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
47
|
+
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)
|
42
51
|
end
|
43
52
|
end
|
44
53
|
end
|
@@ -1,34 +1,43 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'slack_messaging'
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
"icon_emoji" => ":wine_glass:"}
|
10
|
-
}
|
11
|
-
allow(YAML).to receive(:load_file).and_return(config_file)
|
12
|
-
allow(File).to receive(:exist?).and_return(true)
|
13
|
-
SlackMessaging::Config.load("dummy/path")
|
14
|
-
end
|
4
|
+
describe SlackMessaging::NotifySlack do
|
5
|
+
let(:sentence) { Faker::Lorem.sentence }
|
6
|
+
let(:channel) { Faker::Lorem.word }
|
7
|
+
let(:username) { Faker::Name.name }
|
8
|
+
let(:webhook) { Faker::Internet.url }
|
9
|
+
let(:emoji) { Faker::Internet.url }
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
11
|
+
let(:config_file) do
|
12
|
+
{
|
13
|
+
'slack': {
|
14
|
+
'slack_option': true,
|
15
|
+
'username': username,
|
16
|
+
'icon_emoji': emoji,
|
17
|
+
'channel': channel,
|
18
|
+
'webhook_url': webhook
|
19
|
+
}
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
before :each do
|
24
|
+
allow(YAML).to receive(:load_file).and_return(config_file)
|
25
|
+
allow(File).to receive(:exist?).and_return(true)
|
26
|
+
SlackMessaging::Config.load(Faker::Lorem.word)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should call HTTParty' do
|
30
|
+
expect(HTTParty).to receive(:post)
|
31
|
+
message = SlackMessaging::NotifySlack.new(sentence)
|
32
|
+
message.perform
|
33
|
+
end
|
23
34
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
|
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)
|
33
42
|
end
|
34
43
|
end
|