slack_messaging 1.1.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile.lock +104 -0
- data/Guardfile +5 -0
- data/{LICENSE.txt → LICENSE} +1 -1
- data/README.md +30 -26
- data/Rakefile +1 -2
- data/bin/slack-messaging +6 -1
- data/lib/slack_messaging.rb +8 -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 +21 -25
- data/lib/slack_messaging/slack.rb +20 -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 +18 -20
- data/spec/spec_helper.rb +5 -0
- metadata +66 -47
- 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/.travis.yml +0 -10
- data/CHANGELOG.markdown +0 -8
- 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 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3508ee5d59522e0a8d3c931e165bee408d707240fc4c3a1aadbabd2d5b6799f9
|
4
|
+
data.tar.gz: 67bc57eb2943f0f9f801eac68e25988ee4b06ac20835dd2f46b24b4599d213d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0aa1c61dcb454f5beef05a9ecc13da9e16a258812952013675d2bc5a4b3230d6f80f9b08d47d3de0168a6fb85a180fe1a9d2b78e6b68474c6ae615fdf7639081
|
7
|
+
data.tar.gz: dd9967c7e2347435a1194961f03f7d5329f45cb839a47130cc1bb901cd324234e854a457a274cfccc54c9903cd322157f06dc0b61baa9e283d21daa549c7dc51
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
slack_messaging (1.4.0)
|
5
|
+
activesupport (~> 6.0)
|
6
|
+
gli (~> 2.10)
|
7
|
+
hashie (~> 4.1)
|
8
|
+
highline (~> 2.0)
|
9
|
+
httparty
|
10
|
+
rack (~> 2.2)
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: https://rubygems.org/
|
14
|
+
specs:
|
15
|
+
activesupport (6.0.3.4)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (>= 0.7, < 2)
|
18
|
+
minitest (~> 5.1)
|
19
|
+
tzinfo (~> 1.1)
|
20
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
21
|
+
coderay (1.1.3)
|
22
|
+
concurrent-ruby (1.1.7)
|
23
|
+
diff-lcs (1.4.4)
|
24
|
+
faker (2.14.0)
|
25
|
+
i18n (>= 1.6, < 2)
|
26
|
+
ffi (1.13.1)
|
27
|
+
formatador (0.2.5)
|
28
|
+
gli (2.19.2)
|
29
|
+
guard (2.16.2)
|
30
|
+
formatador (>= 0.2.4)
|
31
|
+
listen (>= 2.7, < 4.0)
|
32
|
+
lumberjack (>= 1.0.12, < 2.0)
|
33
|
+
nenv (~> 0.1)
|
34
|
+
notiffany (~> 0.0)
|
35
|
+
pry (>= 0.9.12)
|
36
|
+
shellany (~> 0.0)
|
37
|
+
thor (>= 0.18.1)
|
38
|
+
guard-compat (1.2.1)
|
39
|
+
guard-rspec (4.7.3)
|
40
|
+
guard (~> 2.1)
|
41
|
+
guard-compat (~> 1.1)
|
42
|
+
rspec (>= 2.99.0, < 4.0)
|
43
|
+
hashie (4.1.0)
|
44
|
+
highline (2.0.3)
|
45
|
+
httparty (0.18.1)
|
46
|
+
mime-types (~> 3.0)
|
47
|
+
multi_xml (>= 0.5.2)
|
48
|
+
i18n (1.8.5)
|
49
|
+
concurrent-ruby (~> 1.0)
|
50
|
+
listen (3.3.1)
|
51
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
52
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
53
|
+
lumberjack (1.2.8)
|
54
|
+
method_source (1.0.0)
|
55
|
+
mime-types (3.3.1)
|
56
|
+
mime-types-data (~> 3.2015)
|
57
|
+
mime-types-data (3.2020.1104)
|
58
|
+
minitest (5.14.2)
|
59
|
+
multi_xml (0.6.0)
|
60
|
+
nenv (0.3.0)
|
61
|
+
notiffany (0.1.3)
|
62
|
+
nenv (~> 0.1)
|
63
|
+
shellany (~> 0.0)
|
64
|
+
pry (0.13.1)
|
65
|
+
coderay (~> 1.1)
|
66
|
+
method_source (~> 1.0)
|
67
|
+
rack (2.2.3)
|
68
|
+
rake (13.0.1)
|
69
|
+
rb-fsevent (0.10.4)
|
70
|
+
rb-inotify (0.10.1)
|
71
|
+
ffi (~> 1.0)
|
72
|
+
rspec (3.10.0)
|
73
|
+
rspec-core (~> 3.10.0)
|
74
|
+
rspec-expectations (~> 3.10.0)
|
75
|
+
rspec-mocks (~> 3.10.0)
|
76
|
+
rspec-core (3.10.0)
|
77
|
+
rspec-support (~> 3.10.0)
|
78
|
+
rspec-expectations (3.10.0)
|
79
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
80
|
+
rspec-support (~> 3.10.0)
|
81
|
+
rspec-mocks (3.10.0)
|
82
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
83
|
+
rspec-support (~> 3.10.0)
|
84
|
+
rspec-support (3.10.0)
|
85
|
+
shellany (0.0.1)
|
86
|
+
thor (1.0.1)
|
87
|
+
thread_safe (0.3.6)
|
88
|
+
tzinfo (1.2.8)
|
89
|
+
thread_safe (~> 0.1)
|
90
|
+
zeitwerk (2.4.1)
|
91
|
+
|
92
|
+
PLATFORMS
|
93
|
+
ruby
|
94
|
+
|
95
|
+
DEPENDENCIES
|
96
|
+
bundler (~> 2.1)
|
97
|
+
faker
|
98
|
+
guard-rspec (~> 4.3)
|
99
|
+
rake (~> 13.0)
|
100
|
+
rspec (~> 3.9)
|
101
|
+
slack_messaging!
|
102
|
+
|
103
|
+
BUNDLED WITH
|
104
|
+
2.1.4
|
data/Guardfile
ADDED
data/{LICENSE.txt → LICENSE}
RENAMED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Slack Messaging [![
|
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: <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, which are all defined in [`lib/slack_messaging/random_message.rb`](https://github.com/
|
53
|
+
from the main directory. Here, no specific message is being given to print to Slack, so slack_messaging will choose a random quote, which are all defined in [`lib/slack_messaging/random_message.rb`](https://github.com/emmasax4/slack_messaging/blob/main/lib/slack_messaging/random_message.rb). Feel free to change the messages or add more to cater what you'd like slack_messaging to say.
|
48
54
|
|
49
55
|
However, what if you wanted to print something specific? Well, you can! Just run:
|
50
56
|
|
@@ -60,33 +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/
|
69
|
+
<img src="https://github.com/emmasax4/slack_messaging/blob/main/OutputFile.png" width="1000">
|
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.
|
70
|
-
|
71
|
-
To contribute:
|
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!
|
72
76
|
|
73
|
-
|
74
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
75
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
76
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
77
|
-
5. Create a new Pull Request
|
77
|
+
## Contributing
|
78
78
|
|
79
|
-
|
80
|
-
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).
|
81
80
|
|
82
|
-
|
81
|
+
To report any security vulnerabilities, please view this project's [Security Policy](https://github.com/emmasax4/slack_messaging/security/policy).
|
83
82
|
|
84
|
-
|
83
|
+
This repository does have a standard [Code of Conduct](https://github.com/emmasax4/slack_messaging/blob/main/.github/code_of_conduct.md).
|
85
84
|
|
86
|
-
|
85
|
+
## Releasing
|
87
86
|
|
88
|
-
|
87
|
+
To make a new release of this gem:
|
89
88
|
|
90
|
-
|
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
|
91
95
|
|
92
|
-
|
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,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
require_relative 'slack_messaging/random_message'
|
6
|
-
|
7
|
-
module SlackMessaging
|
1
|
+
require 'yaml'
|
2
|
+
require 'hashie'
|
3
|
+
require 'httparty'
|
4
|
+
require 'highline'
|
8
5
|
|
6
|
+
Dir[File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), 'slack_messaging')) + '/**/*.rb'].each do |file|
|
7
|
+
require_relative file
|
9
8
|
end
|
9
|
+
|
10
|
+
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,30 @@
|
|
1
1
|
module SlackMessaging
|
2
2
|
class RandomMessage
|
3
|
-
attr_accessor :text
|
4
|
-
|
5
3
|
MESSAGE_ARRAY = [
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
4
|
+
"A true friend is someone who thinks that you are a good egg even though he knows that you are slightly cracked.\n--Bernard Meltzer",
|
5
|
+
"If you can't make it good, at least make it look good.\n--Bill Gates",
|
6
|
+
"I'm convinced of this: Good done anywhere is good done everywhere.\n--Maya Angelou",
|
7
|
+
"The real trouble with reality is that there's no background music.\n--Anonymous",
|
8
|
+
"Whatever you are, be a good one.\n--Abraham Lincoln",
|
9
|
+
"Good, better, best. Never let it rest. 'Til your good is better and your better is best.\n--St. Jerome",
|
10
|
+
"Despite everything, I believe that people are really good at heart.\n--Anne Frank",
|
11
|
+
"Life is 10% what happens to you and 90% how you react to it.\n--Charles R. Swindoll",
|
12
|
+
"The way to get started is to quit talking and begin doing.\n--Walt Disney",
|
13
|
+
"A creative man is motivated by the desire to achieve, not by the desire to beat others.\n--Ayn Rand",
|
14
|
+
"Problems are not stop signs, they are guidelines.\n--Robert H. Schuller",
|
15
|
+
"Correction does much, but encouragement does more.\n--Johann Wolfgang von Goethe",
|
16
|
+
"Positive anything is better than negative nothing.\n--Elbert Hubbard",
|
17
|
+
"To succeed, you need to find something to hold on to, something to motivate you, something to inspire you.\n--Joyce Meyer",
|
18
|
+
"If you're not making mistakes, then you're not doing anything. I'm positive that a doer makes mistakes.\n--John Wooden",
|
19
|
+
"The best way to deal with other people is to just let them be other people.\n--Anonymous",
|
20
|
+
"Talk to yourself like you would to someone you love.\n--Brenee Brown",
|
21
|
+
"Don't let small minds convince you that your dreams are too big.\n--Anonymous",
|
22
|
+
]
|
23
|
+
|
24
|
+
attr_accessor :text
|
25
25
|
|
26
26
|
def initialize
|
27
27
|
self.text = MESSAGE_ARRAY[rand(MESSAGE_ARRAY.length)]
|
28
28
|
end
|
29
|
-
|
30
|
-
def get_text
|
31
|
-
return self.text
|
32
|
-
end
|
33
29
|
end
|
34
30
|
end
|
@@ -0,0 +1,20 @@
|
|
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.new
|
8
|
+
print_message(message.text)
|
9
|
+
else
|
10
|
+
args.each do |message|
|
11
|
+
print_message(message)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.print_message(message)
|
17
|
+
SlackMessaging::NotifySlack.new(message).perform
|
18
|
+
end
|
19
|
+
end
|
20
|
+
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
|
@@ -1,26 +1,24 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'slack_messaging'
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
expect(message.get_text).to be_instance_of(String)
|
9
|
-
end
|
4
|
+
describe SlackMessaging::RandomMessage do
|
5
|
+
it 'should get a string message' do
|
6
|
+
message = SlackMessaging::RandomMessage.new
|
7
|
+
expect(message.text).to be_instance_of(String)
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
it 'should get a message greater than 25 characters' do
|
11
|
+
message = SlackMessaging::RandomMessage.new
|
12
|
+
expect(message.text.length).to be >= 50
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
it 'should get a message that includes a new line' do
|
16
|
+
message = SlackMessaging::RandomMessage.new
|
17
|
+
expect(message.text.include?("\n")).to eq(true)
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
20
|
+
it 'should get a message that includes a --' do
|
21
|
+
message = SlackMessaging::RandomMessage.new
|
22
|
+
expect(message.text.include?('--')).to eq(true)
|
25
23
|
end
|
26
24
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'faker'
|
2
|
+
|
1
3
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
4
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
5
|
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
@@ -31,6 +33,9 @@ RSpec.configure do |config|
|
|
31
33
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
32
34
|
end
|
33
35
|
|
36
|
+
config.filter_run :focus => true
|
37
|
+
config.run_all_when_everything_filtered = true
|
38
|
+
|
34
39
|
# rspec-mocks config goes here. You can use an alternate test double
|
35
40
|
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
36
41
|
config.mock_with :rspec do |mocks|
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack_messaging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emma Sax
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '6.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: gli
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,104 +39,132 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.10'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: hashie
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1
|
47
|
+
version: '4.1'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1
|
54
|
+
version: '4.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: highline
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '2.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: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: httparty
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rack
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
89
|
+
version: '2.2'
|
76
90
|
type: :runtime
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
94
|
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
96
|
+
version: '2.2'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
98
|
+
name: bundler
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
90
|
-
type: :
|
103
|
+
version: '2.1'
|
104
|
+
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
110
|
+
version: '2.1'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
112
|
+
name: faker
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: guard-rspec
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
100
128
|
requirements:
|
101
129
|
- - "~>"
|
102
130
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
131
|
+
version: '4.3'
|
104
132
|
type: :development
|
105
133
|
prerelease: false
|
106
134
|
version_requirements: !ruby/object:Gem::Requirement
|
107
135
|
requirements:
|
108
136
|
- - "~>"
|
109
137
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
138
|
+
version: '4.3'
|
111
139
|
- !ruby/object:Gem::Dependency
|
112
140
|
name: rake
|
113
141
|
requirement: !ruby/object:Gem::Requirement
|
114
142
|
requirements:
|
115
143
|
- - "~>"
|
116
144
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
145
|
+
version: '13.0'
|
118
146
|
type: :development
|
119
147
|
prerelease: false
|
120
148
|
version_requirements: !ruby/object:Gem::Requirement
|
121
149
|
requirements:
|
122
150
|
- - "~>"
|
123
151
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
152
|
+
version: '13.0'
|
125
153
|
- !ruby/object:Gem::Dependency
|
126
154
|
name: rspec
|
127
155
|
requirement: !ruby/object:Gem::Requirement
|
128
156
|
requirements:
|
129
157
|
- - "~>"
|
130
158
|
- !ruby/object:Gem::Version
|
131
|
-
version: 3.
|
159
|
+
version: '3.9'
|
132
160
|
type: :development
|
133
161
|
prerelease: false
|
134
162
|
version_requirements: !ruby/object:Gem::Requirement
|
135
163
|
requirements:
|
136
164
|
- - "~>"
|
137
165
|
- !ruby/object:Gem::Version
|
138
|
-
version: 3.
|
139
|
-
description: Sending Personalized Slack Messages
|
166
|
+
version: '3.9'
|
167
|
+
description: Sending Personalized Slack Messages to a Slack channel of your choice.
|
140
168
|
email:
|
141
169
|
- emma.sax4@gmail.com
|
142
170
|
executables:
|
@@ -144,38 +172,30 @@ executables:
|
|
144
172
|
extensions: []
|
145
173
|
extra_rdoc_files: []
|
146
174
|
files:
|
147
|
-
- ".gitignore"
|
148
|
-
- ".octopolo.yml"
|
149
|
-
- ".rspec"
|
150
|
-
- ".ruby-gemset"
|
151
|
-
- ".ruby-version"
|
152
|
-
- ".soyuz.yml"
|
153
|
-
- ".travis.yml"
|
154
|
-
- CHANGELOG.markdown
|
155
175
|
- Gemfile
|
156
|
-
-
|
176
|
+
- Gemfile.lock
|
177
|
+
- Guardfile
|
178
|
+
- LICENSE
|
157
179
|
- OutputFile.png
|
158
180
|
- README.md
|
159
181
|
- Rakefile
|
160
182
|
- bin/slack-messaging
|
161
183
|
- lib/slack_messaging.rb
|
162
|
-
- lib/slack_messaging/commands/slack.rb
|
163
184
|
- lib/slack_messaging/config.rb
|
185
|
+
- lib/slack_messaging/default_paths.rb
|
164
186
|
- lib/slack_messaging/notify_slack.rb
|
165
|
-
- lib/slack_messaging/output.rb
|
166
187
|
- lib/slack_messaging/random_message.rb
|
167
|
-
- lib/slack_messaging/
|
188
|
+
- lib/slack_messaging/slack.rb
|
168
189
|
- lib/slack_messaging/version.rb
|
169
|
-
- slack_messaging.gemspec
|
170
190
|
- spec/slack_messaging/config_spec.rb
|
171
191
|
- spec/slack_messaging/notify_slack_spec.rb
|
172
192
|
- spec/slack_messaging/random_message_spec.rb
|
173
193
|
- spec/spec_helper.rb
|
174
|
-
homepage: https://github.com/
|
194
|
+
homepage: https://github.com/emmasax4/slack_messaging
|
175
195
|
licenses:
|
176
196
|
- MIT
|
177
197
|
metadata: {}
|
178
|
-
post_install_message:
|
198
|
+
post_install_message:
|
179
199
|
rdoc_options: []
|
180
200
|
require_paths:
|
181
201
|
- lib
|
@@ -190,13 +210,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
210
|
- !ruby/object:Gem::Version
|
191
211
|
version: '0'
|
192
212
|
requirements: []
|
193
|
-
|
194
|
-
|
195
|
-
signing_key:
|
213
|
+
rubygems_version: 3.1.4
|
214
|
+
signing_key:
|
196
215
|
specification_version: 4
|
197
|
-
summary:
|
216
|
+
summary: Personalized Slack Messages
|
198
217
|
test_files:
|
218
|
+
- spec/spec_helper.rb
|
199
219
|
- spec/slack_messaging/config_spec.rb
|
200
|
-
- spec/slack_messaging/notify_slack_spec.rb
|
201
220
|
- spec/slack_messaging/random_message_spec.rb
|
202
|
-
- spec/
|
221
|
+
- spec/slack_messaging/notify_slack_spec.rb
|
data/.gitignore
DELETED
data/.octopolo.yml
DELETED
data/.rspec
DELETED
data/.ruby-gemset
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
slack_messaging
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby-2.2.5
|
data/.soyuz.yml
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
defaults:
|
2
|
-
deploy_cmd: gem push *.gem
|
3
|
-
before_deploy_cmds:
|
4
|
-
- sed -i "" -e "s/\".*/\"$(git tag| sed s/v// | sort -n -t. -k1,1 -k2,2 -k3,3 | tail -1)\"/" lib/sport_ngin_aws_auditor/version.rb
|
5
|
-
- git add lib/slack_messaging/version.rb
|
6
|
-
- git commit -m "Version Bump" && git push
|
7
|
-
- gem build slack_messaging.gemspec
|
8
|
-
after_deploy_cmds:
|
9
|
-
- rm *.gem
|
10
|
-
environments:
|
11
|
-
-
|
12
|
-
rubygems: {}
|
data/.travis.yml
DELETED
data/CHANGELOG.markdown
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'highline/import'
|
2
|
-
require_relative "../notify_slack"
|
3
|
-
require_relative "../random_message"
|
4
|
-
|
5
|
-
module SlackMessaging
|
6
|
-
module Scripts
|
7
|
-
class Slack
|
8
|
-
class << self
|
9
|
-
attr_accessor :options
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.execute(args, options=nil)
|
13
|
-
if args.empty?
|
14
|
-
message = RandomMessage.new # generate a new random message
|
15
|
-
print_message(message.get_text)
|
16
|
-
else
|
17
|
-
args.each do |message|
|
18
|
-
print_message(message)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.print_message(message)
|
24
|
-
slack_job = NotifySlack.new(message)
|
25
|
-
slack_job.perform
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/slack_messaging.gemspec
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'slack_messaging/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "slack_messaging"
|
8
|
-
spec.version = SlackMessaging::VERSION
|
9
|
-
spec.authors = ["Emma Sax"]
|
10
|
-
spec.email = ["emma.sax4@gmail.com"]
|
11
|
-
spec.summary = %q{Sending Personalized Slack Messages}
|
12
|
-
spec.description = %q{Sending Personalized Slack Messages}
|
13
|
-
spec.homepage = "https://github.com/emmasax1/slack_messaging"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_dependency 'hashie', '~> 3.3'
|
22
|
-
spec.add_dependency 'gli', '~> 2.10'
|
23
|
-
spec.add_dependency 'highline', '~> 1.6'
|
24
|
-
spec.add_dependency 'slack-notifier', '~> 1.5.1'
|
25
|
-
spec.add_dependency 'rack', '~> 1.3.0'
|
26
|
-
spec.add_dependency 'activesupport', '~> 3.2'
|
27
|
-
|
28
|
-
spec.add_development_dependency "bundler", "~> 1.7"
|
29
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
-
spec.add_development_dependency "rspec", "~> 3.4.0"
|
31
|
-
end
|