slack_messaging 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.octopolo.yml +4 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.soyuz.yml +13 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.markdown +0 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/OutputFile.png +0 -0
- data/README.md +64 -0
- data/Rakefile +2 -0
- data/bin/slack-messaging +27 -0
- data/lib/slack_messaging.rb +9 -0
- data/lib/slack_messaging/commands/slack.rb +7 -0
- data/lib/slack_messaging/config.rb +91 -0
- data/lib/slack_messaging/notify_slack.rb +25 -0
- data/lib/slack_messaging/output.rb +13 -0
- data/lib/slack_messaging/random_message.rb +34 -0
- data/lib/slack_messaging/scripts/slack.rb +29 -0
- data/lib/slack_messaging/version.rb +3 -0
- data/slack_messaging.gemspec +31 -0
- data/spec/slack_messaging/config_spec.rb +63 -0
- data/spec/slack_messaging/notify_slack_spec.rb +34 -0
- data/spec/slack_messaging/random_message_spec.rb +26 -0
- data/spec/spec_helper.rb +42 -0
- metadata +202 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3ef1b8cdda8d1c22e73482231be13f506a3ab16f
|
4
|
+
data.tar.gz: 1431876da89e19c496365819d5b992c02afd3994
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1c59a899ccff391d367554bf05646c0a898d4d8ab8b02ea4a5b06b919d13eec9dfcd5f3e16f0d343287de8db9f8874b6f53fc1d9a9e8f73b0df58213aa8321fe
|
7
|
+
data.tar.gz: 05d8fd5f3facb9670ecabcee15a5a83b5e52365b6cf35730d7ee677f1df3f1bfb2a928e5a90349c5f87243c1cf6a81ebaed86b6a4a6495dd32d21c2c48ce9759
|
data/.gitignore
ADDED
data/.octopolo.yml
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
slack_messaging
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.2.5
|
data/.soyuz.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
defaults:
|
2
|
+
deploy_cmd: gem push *.gem
|
3
|
+
before_deploy_cmds:
|
4
|
+
- /usr/local/bin/op tag-release
|
5
|
+
- 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
|
6
|
+
- git add lib/slack_messaging/version.rb
|
7
|
+
- git commit -m "Version Bump" && git push
|
8
|
+
- gem build slack_messaging.gemspec
|
9
|
+
after_deploy_cmds:
|
10
|
+
- rm *.gem
|
11
|
+
environments:
|
12
|
+
-
|
13
|
+
rubygems: {}
|
data/.travis.yml
ADDED
data/CHANGELOG.markdown
ADDED
File without changes
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Elliot Hursh
|
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.
|
data/OutputFile.png
ADDED
Binary file
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Slack Messaging [![Build Status](https://travis-ci.org/emmasax1/slack_messaging.svg?branch=master)](https://travis-ci.org/emmasax1/slack_messaging) [![Code Climate](https://codeclimate.com/github/emmasax1/slack_messaging/badges/gpa.svg)](https://codeclimate.com/github/emmasax1/slack_messaging)
|
2
|
+
|
3
|
+
This is a simple project designed to post messages to a given Slack channel as a bot.
|
4
|
+
|
5
|
+
### Usage
|
6
|
+
|
7
|
+
First, run:
|
8
|
+
|
9
|
+
```
|
10
|
+
gem install bundler
|
11
|
+
bundle install
|
12
|
+
```
|
13
|
+
|
14
|
+
Then, the project should be ready to go! However, it won't necessarily know where to print to Slack. So, this project requires a config file called `~/.slack_messaging.yml`. The config file should look like this:
|
15
|
+
|
16
|
+
```
|
17
|
+
slack:
|
18
|
+
channel: "#[AWESOME CHANNEL NAME]"
|
19
|
+
username: [AWESOME USER NAME]
|
20
|
+
webhook_url: [WEBHOOK URL]
|
21
|
+
icon_emoji: ":[SOME EMOJI]:"
|
22
|
+
```
|
23
|
+
|
24
|
+
To obtain the webhook url, go to [this link](https://api.slack.com/incoming-webhooks).
|
25
|
+
|
26
|
+
Okay, now the project will _actually_ be ready to rock and roll.
|
27
|
+
|
28
|
+
To print a friendly message to Slack, run:
|
29
|
+
|
30
|
+
```
|
31
|
+
slack-messaging slack
|
32
|
+
```
|
33
|
+
|
34
|
+
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/emmasax1/slack_messaging/blob/master/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.
|
35
|
+
|
36
|
+
However, what if you wanted to print something specific? Well, you can! Just run:
|
37
|
+
|
38
|
+
```
|
39
|
+
slack-messaging slack "MESSAGE 1"
|
40
|
+
```
|
41
|
+
|
42
|
+
You can even print multiple messages at once:
|
43
|
+
|
44
|
+
```
|
45
|
+
slack-messaging slack "MESSAGE 1" "MESSAGE 2" "MESSAGE 3" ... "MESSAGE N"
|
46
|
+
```
|
47
|
+
|
48
|
+
The output of slack_messaging will look something like this:
|
49
|
+
|
50
|
+
<img src="https://github.com/emmasax1/slack_messaging/blob/master/OutputFile.png" width="1000">
|
51
|
+
|
52
|
+
I hope you enjoy printing fun and specialized messages to Slack!
|
53
|
+
|
54
|
+
### Tests
|
55
|
+
|
56
|
+
To run the tests, run `rspec` from the command line. Travis CI will also run the tests upon every commit to make sure they're up to date and that everything is working correctly. There are currently only tests for the `notify_slack` and `random_message` classes. Feel free to help us add more!
|
57
|
+
|
58
|
+
To contribute:
|
59
|
+
|
60
|
+
1. Fork it (https://github.com/emmasax1/slack_messaging/fork)
|
61
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
62
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
63
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
64
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/slack-messaging
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'gli'
|
4
|
+
require_relative '../lib/slack_messaging'
|
5
|
+
|
6
|
+
include GLI::App
|
7
|
+
|
8
|
+
program_desc 'Slack Messaging'
|
9
|
+
version SlackMessaging::VERSION
|
10
|
+
|
11
|
+
wrap_help_text :verbatim
|
12
|
+
|
13
|
+
flag [:config], :desc => 'SlackMessaging config file path', :default_value => SlackMessaging::DefaultPaths.config
|
14
|
+
|
15
|
+
program_long_desc """
|
16
|
+
DOCUMENTATION
|
17
|
+
"""
|
18
|
+
|
19
|
+
commands_from File.expand_path(File.dirname(__FILE__) + '/../lib/slack_messaging/commands')
|
20
|
+
|
21
|
+
pre do |global,command,options,args|
|
22
|
+
SlackMessaging::Config.load(global[:config])
|
23
|
+
SlackMessaging::Config.set_config_options(global)
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
exit run(ARGV)
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require_relative 'slack_messaging/version'
|
2
|
+
require_relative 'slack_messaging/output'
|
3
|
+
require_relative 'slack_messaging/config'
|
4
|
+
require_relative 'slack_messaging/notify_slack'
|
5
|
+
require_relative 'slack_messaging/random_message'
|
6
|
+
|
7
|
+
module SlackMessaging
|
8
|
+
|
9
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module SlackMessaging
|
4
|
+
|
5
|
+
module PrivateAttrAccessor
|
6
|
+
def private_attr_accessor(*names)
|
7
|
+
private
|
8
|
+
attr_accessor *names
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class DefaultPaths
|
13
|
+
class << self
|
14
|
+
def config
|
15
|
+
File.join(self.home,'.slack_messaging.yml')
|
16
|
+
end
|
17
|
+
|
18
|
+
def home
|
19
|
+
ENV['HOME'] ? ENV['HOME'] : "."
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Config
|
25
|
+
|
26
|
+
CONFIG_DEFAULTS = {}
|
27
|
+
|
28
|
+
class << self
|
29
|
+
extend PrivateAttrAccessor
|
30
|
+
private_attr_accessor :config_data
|
31
|
+
|
32
|
+
def config
|
33
|
+
CONFIG_DEFAULTS.merge data
|
34
|
+
end
|
35
|
+
|
36
|
+
def load(path)
|
37
|
+
load_config(path)
|
38
|
+
config
|
39
|
+
end
|
40
|
+
|
41
|
+
def set_config_options(opts = {})
|
42
|
+
data.merge! opts
|
43
|
+
config
|
44
|
+
end
|
45
|
+
|
46
|
+
def data
|
47
|
+
self.config_data ||= {}
|
48
|
+
end
|
49
|
+
private :data
|
50
|
+
|
51
|
+
def default_value(key)
|
52
|
+
CONFIG_DEFAULTS[key.to_sym]
|
53
|
+
end
|
54
|
+
private :default_value
|
55
|
+
|
56
|
+
def method_missing(method, args=false)
|
57
|
+
return data[method] if data[method]
|
58
|
+
return default_value(method) if default_value(method)
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
private :method_missing
|
62
|
+
|
63
|
+
def load_config(file)
|
64
|
+
raise MissingConfig, "Missing configuration file: #{file}" unless File.exist?(file)
|
65
|
+
self.config_data = symbolize_keys(YAML.load_file(file)) rescue {}
|
66
|
+
end
|
67
|
+
private :load_config
|
68
|
+
|
69
|
+
# We want all ouf our YAML loaded keys to be symbols
|
70
|
+
# taken from http://devblog.avdi.org/2009/07/14/recursively-symbolize-keys/
|
71
|
+
def symbolize_keys(hash)
|
72
|
+
hash.inject({}){|result, (key, value)|
|
73
|
+
new_key = case key
|
74
|
+
when String then key.to_sym
|
75
|
+
else key
|
76
|
+
end
|
77
|
+
new_value = case value
|
78
|
+
when Hash then symbolize_keys(value)
|
79
|
+
else value
|
80
|
+
end
|
81
|
+
result[new_key] = new_value
|
82
|
+
result
|
83
|
+
}
|
84
|
+
end
|
85
|
+
private :symbolize_keys
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
MissingConfig = Class.new(StandardError)
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'slack-notifier'
|
2
|
+
|
3
|
+
module SlackMessaging
|
4
|
+
class NotifySlack
|
5
|
+
attr_accessor :text, :channel, :webhook_url, :username, :icon_url, :icon_emoji
|
6
|
+
|
7
|
+
def initialize(text)
|
8
|
+
self.text = text
|
9
|
+
self.channel = SlackMessaging::Config.slack[:channel]
|
10
|
+
self.webhook_url = SlackMessaging::Config.slack[:webhook_url]
|
11
|
+
self.username = SlackMessaging::Config.slack[:username] || "MessageMe"
|
12
|
+
self.icon_emoji = SlackMessaging::Config.slack[:icon_emoji] || ":mailbox_with_mail"
|
13
|
+
end
|
14
|
+
|
15
|
+
def perform
|
16
|
+
options = {webhook_url: webhook_url,
|
17
|
+
channel: channel,
|
18
|
+
username: username,
|
19
|
+
icon_emoji: icon_emoji,
|
20
|
+
http_options: {open_timeout: 10}
|
21
|
+
}
|
22
|
+
Slack::Notifier.new(webhook_url, options).ping(text)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module SlackMessaging
|
2
|
+
class RandomMessage
|
3
|
+
attr_accessor :text
|
4
|
+
|
5
|
+
MESSAGE_ARRAY = [
|
6
|
+
"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",
|
7
|
+
"If you can't make it good, at least make it look good.\n--Bill Gates",
|
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
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,29 @@
|
|
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
|
@@ -0,0 +1,31 @@
|
|
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
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'slack_messaging'
|
3
|
+
|
4
|
+
module SlackMessaging
|
5
|
+
describe Config do
|
6
|
+
|
7
|
+
context "#set_config_options" do
|
8
|
+
it "should create a corresponding method that returns the value" do
|
9
|
+
SlackMessaging::Config.set_config_options(test: "something")
|
10
|
+
expect(SlackMessaging::Config.test).to eql("something")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "setting a new key should return the entire config hash" do
|
14
|
+
items = SlackMessaging::Config.config.count
|
15
|
+
expect(SlackMessaging::Config.set_config_options(test1: "something_else").count).to eql(items + 1)
|
16
|
+
expect(SlackMessaging::Config.set_config_options(test2: "something else").count).to eql(items + 2)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "#config_data" do
|
21
|
+
it "should be a private method" do
|
22
|
+
expect(SlackMessaging::Config).not_to respond_to(:config_data)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "config key methods" do
|
27
|
+
it "should return nil when not set" do
|
28
|
+
expect(SlackMessaging::Config.doesnt_exist).to eql(nil)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return the config value when set" do
|
32
|
+
SlackMessaging::Config.set_config_options(new_value: "testing")
|
33
|
+
expect(SlackMessaging::Config.new_value).to eql("testing")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "after loading a config file" do
|
38
|
+
before do
|
39
|
+
config_file = {"domain" => "example_domain",
|
40
|
+
"slack" => {"slack_option"=>true,
|
41
|
+
"username" => "Rspec Tester",
|
42
|
+
"icon_url" => "http://fake.url",
|
43
|
+
"channel" => "#test-channel",
|
44
|
+
"webhook" => "https://slack.web.hook"}}
|
45
|
+
allow(YAML).to receive(:load_file).and_return(config_file)
|
46
|
+
allow(File).to receive(:exist?).and_return(true)
|
47
|
+
SlackMessaging::Config.load("dummy/path")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "calling a method corresponding to a key in the file should return the value" do
|
51
|
+
expect(SlackMessaging::Config.domain).to eql("example_domain")
|
52
|
+
expect(SlackMessaging::Config.slack).to be_kind_of(Hash)
|
53
|
+
expect(SlackMessaging::Config.slack[:slack_option]).to eql(true)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "overwriting values should work" do
|
57
|
+
expect(SlackMessaging::Config.slack).to be_kind_of(Hash)
|
58
|
+
SlackMessaging::Config.set_config_options(slack: "this is a string now")
|
59
|
+
expect(SlackMessaging::Config.slack).to eql("this is a string now")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "slack_messaging"
|
2
|
+
|
3
|
+
module SlackMessaging
|
4
|
+
describe NotifySlack do
|
5
|
+
before :each do
|
6
|
+
config_file = {"slack" => {"channel" => "#random-test-channel",
|
7
|
+
"username" => "Random User",
|
8
|
+
"webhook_url" => "https://hooks.slack.com/services/totallyrandom/fakewebhookurl",
|
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
|
15
|
+
|
16
|
+
it 'should ping Slack Notifier' do
|
17
|
+
notifier = double('notifier', ping: true)
|
18
|
+
allow(Slack::Notifier).to receive(:new).and_return(notifier)
|
19
|
+
expect(notifier).to receive(:ping).and_return(true)
|
20
|
+
message = NotifySlack.new("Test message")
|
21
|
+
message.perform
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should define certain values' do
|
25
|
+
message = NotifySlack.new("Test message")
|
26
|
+
expect(message.text).to eq("Test message")
|
27
|
+
expect(message.channel).to eq("#random-test-channel")
|
28
|
+
expect(message.username).to eq("Random User")
|
29
|
+
expect(message.webhook_url).to eq("https://hooks.slack.com/services/totallyrandom/fakewebhookurl")
|
30
|
+
expect(message.icon_emoji).to eq(":wine_glass:")
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "slack_messaging"
|
2
|
+
|
3
|
+
module SlackMessaging
|
4
|
+
describe RandomMessage do
|
5
|
+
|
6
|
+
it "should get a string message" do
|
7
|
+
message = RandomMessage.new
|
8
|
+
expect(message.get_text).to be_instance_of(String)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should get a message greater than 25 characters" do
|
12
|
+
message = RandomMessage.new
|
13
|
+
expect(message.get_text.length).to be >= 50
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should get a message that includes a new line" do
|
17
|
+
message = RandomMessage.new
|
18
|
+
expect(message.get_text.include?("\n")).to eq(true)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should get a message that includes a '--'" do
|
22
|
+
message = RandomMessage.new
|
23
|
+
expect(message.get_text.include?("--")).to eq(true)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
16
|
+
# users commonly want.
|
17
|
+
#
|
18
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
|
+
RSpec.configure do |config|
|
20
|
+
# rspec-expectations config goes here. You can use an alternate
|
21
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
22
|
+
# assertions if you prefer.
|
23
|
+
config.expect_with :rspec do |expectations|
|
24
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
25
|
+
# and `failure_message` of custom matchers include text for helper methods
|
26
|
+
# defined using `chain`, e.g.:
|
27
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
28
|
+
# # => "be bigger than 2 and smaller than 4"
|
29
|
+
# ...rather than:
|
30
|
+
# # => "be bigger than 2"
|
31
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
32
|
+
end
|
33
|
+
|
34
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
35
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
36
|
+
config.mock_with :rspec do |mocks|
|
37
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
38
|
+
# a real object. This is generally recommended, and will default to
|
39
|
+
# `true` in RSpec 4.
|
40
|
+
mocks.verify_partial_doubles = true
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slack_messaging
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Emma Sax
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hashie
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: gli
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.10'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: highline
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: slack-notifier
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.5.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.5.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.3.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.3.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activesupport
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.2'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.2'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.7'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.7'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '10.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '10.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 3.4.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 3.4.0
|
139
|
+
description: Sending Personalized Slack Messages
|
140
|
+
email:
|
141
|
+
- emma.sax4@gmail.com
|
142
|
+
executables:
|
143
|
+
- slack-messaging
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- ".gitignore"
|
148
|
+
- ".octopolo.yml"
|
149
|
+
- ".rspec"
|
150
|
+
- ".ruby-gemset"
|
151
|
+
- ".ruby-version"
|
152
|
+
- ".soyuz.yml"
|
153
|
+
- ".travis.yml"
|
154
|
+
- CHANGELOG.markdown
|
155
|
+
- Gemfile
|
156
|
+
- LICENSE.txt
|
157
|
+
- OutputFile.png
|
158
|
+
- README.md
|
159
|
+
- Rakefile
|
160
|
+
- bin/slack-messaging
|
161
|
+
- lib/slack_messaging.rb
|
162
|
+
- lib/slack_messaging/commands/slack.rb
|
163
|
+
- lib/slack_messaging/config.rb
|
164
|
+
- lib/slack_messaging/notify_slack.rb
|
165
|
+
- lib/slack_messaging/output.rb
|
166
|
+
- lib/slack_messaging/random_message.rb
|
167
|
+
- lib/slack_messaging/scripts/slack.rb
|
168
|
+
- lib/slack_messaging/version.rb
|
169
|
+
- slack_messaging.gemspec
|
170
|
+
- spec/slack_messaging/config_spec.rb
|
171
|
+
- spec/slack_messaging/notify_slack_spec.rb
|
172
|
+
- spec/slack_messaging/random_message_spec.rb
|
173
|
+
- spec/spec_helper.rb
|
174
|
+
homepage: https://github.com/emmasax1/slack_messaging
|
175
|
+
licenses:
|
176
|
+
- MIT
|
177
|
+
metadata: {}
|
178
|
+
post_install_message:
|
179
|
+
rdoc_options: []
|
180
|
+
require_paths:
|
181
|
+
- lib
|
182
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0'
|
187
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
|
+
requirements:
|
189
|
+
- - ">="
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
version: '0'
|
192
|
+
requirements: []
|
193
|
+
rubyforge_project:
|
194
|
+
rubygems_version: 2.4.8
|
195
|
+
signing_key:
|
196
|
+
specification_version: 4
|
197
|
+
summary: Sending Personalized Slack Messages
|
198
|
+
test_files:
|
199
|
+
- spec/slack_messaging/config_spec.rb
|
200
|
+
- spec/slack_messaging/notify_slack_spec.rb
|
201
|
+
- spec/slack_messaging/random_message_spec.rb
|
202
|
+
- spec/spec_helper.rb
|