slack_messaging 1.2.0 → 2.0.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: ca6013870004fd4decf9af498cf20bc295923da1e8bb8d3889bf99a5cab01238
4
- data.tar.gz: 91ec19a2846a14b64f795869287e7efadb1698b75e1e0106beed8980e5e8ddb6
3
+ metadata.gz: db2a04a6f53bd5e7d0d1017fe6fd5f6c715cc89d108be3dad1eb3a433f944be0
4
+ data.tar.gz: 5487fbcfcf279a48911d773c928826b8f7b2e021710d457c0fa256fa1660562e
5
5
  SHA512:
6
- metadata.gz: 1e9629551ca1a2c7217821c65d5959ae309e1600693053880e795d5def9832bcc993a1e9261e2c55c784819983c1d86efd7a00c48e81d8962bb58e1cdcff1d43
7
- data.tar.gz: eb23b41374af3df2f755413b48eb6a6cbf619370503e0a764332d7acf0a3dd3939185eca7acfe53273b970fcb2f54c009317a50e5826cdd4fa2c10eaee71b39e
6
+ metadata.gz: 76485ac006bb26c047e57e06283ced474b36c5924229dbd58b83a3ea8e2e30e92e8ca916fb7fd24b538ad235a54f427f29e03e4f1dcff382b57eb69d7b71e578
7
+ data.tar.gz: fe229444fe0b9a050d29a6b8c2fc653f287b85d49f965efc76cc81b5f7f3eb677fd79376a0fff012460febc1cd61d4896e9b6f0cf2098557b7a34130de155c42
@@ -0,0 +1,107 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ slack_messaging (2.0.0.pre.test)
5
+ activesupport (~> 6.0)
6
+ gli (~> 2.10)
7
+ hashie (~> 4.1)
8
+ highline (~> 2.0)
9
+ httparty
10
+ json
11
+ rack (~> 2.2)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ activesupport (6.0.3.4)
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)
22
+ coderay (1.1.3)
23
+ concurrent-ruby (1.1.7)
24
+ diff-lcs (1.4.4)
25
+ faker (2.14.0)
26
+ i18n (>= 1.6, < 2)
27
+ ffi (1.13.1)
28
+ formatador (0.2.5)
29
+ gli (2.19.2)
30
+ guard (2.16.2)
31
+ formatador (>= 0.2.4)
32
+ listen (>= 2.7, < 4.0)
33
+ lumberjack (>= 1.0.12, < 2.0)
34
+ nenv (~> 0.1)
35
+ notiffany (~> 0.0)
36
+ pry (>= 0.9.12)
37
+ shellany (~> 0.0)
38
+ thor (>= 0.18.1)
39
+ guard-compat (1.2.1)
40
+ guard-rspec (4.7.3)
41
+ guard (~> 2.1)
42
+ guard-compat (~> 1.1)
43
+ rspec (>= 2.99.0, < 4.0)
44
+ hashie (4.1.0)
45
+ highline (2.0.3)
46
+ httparty (0.18.1)
47
+ mime-types (~> 3.0)
48
+ multi_xml (>= 0.5.2)
49
+ i18n (1.8.5)
50
+ concurrent-ruby (~> 1.0)
51
+ json (2.3.1)
52
+ listen (3.3.1)
53
+ rb-fsevent (~> 0.10, >= 0.10.3)
54
+ rb-inotify (~> 0.9, >= 0.9.10)
55
+ lumberjack (1.2.8)
56
+ method_source (1.0.0)
57
+ mime-types (3.3.1)
58
+ mime-types-data (~> 3.2015)
59
+ mime-types-data (3.2020.1104)
60
+ minitest (5.14.2)
61
+ multi_xml (0.6.0)
62
+ nenv (0.3.0)
63
+ notiffany (0.1.3)
64
+ nenv (~> 0.1)
65
+ shellany (~> 0.0)
66
+ pry (0.13.1)
67
+ coderay (~> 1.1)
68
+ method_source (~> 1.0)
69
+ rack (2.2.3)
70
+ rake (13.0.1)
71
+ rb-fsevent (0.10.4)
72
+ rb-inotify (0.10.1)
73
+ ffi (~> 1.0)
74
+ rspec (3.10.0)
75
+ rspec-core (~> 3.10.0)
76
+ rspec-expectations (~> 3.10.0)
77
+ rspec-mocks (~> 3.10.0)
78
+ rspec-core (3.10.0)
79
+ rspec-support (~> 3.10.0)
80
+ rspec-expectations (3.10.0)
81
+ diff-lcs (>= 1.2.0, < 2.0)
82
+ rspec-support (~> 3.10.0)
83
+ rspec-mocks (3.10.0)
84
+ diff-lcs (>= 1.2.0, < 2.0)
85
+ rspec-support (~> 3.10.0)
86
+ rspec-support (3.10.0)
87
+ 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)
93
+
94
+ PLATFORMS
95
+ ruby
96
+
97
+ DEPENDENCIES
98
+ bundler (~> 2.1)
99
+ faker
100
+ guard-rspec (~> 4.3)
101
+ pry
102
+ rake (~> 13.0)
103
+ rspec (~> 3.9)
104
+ slack_messaging!
105
+
106
+ BUNDLED WITH
107
+ 2.1.4
@@ -0,0 +1,5 @@
1
+ guard :rspec, cmd: 'bundle exec rspec', all_on_start: true, all_after_pass: true do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { 'spec' }
5
+ end
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Elliot Hursh
1
+ Copyright (c) 2014 Emma Sax
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Slack Messaging [![Maintainability](https://api.codeclimate.com/v1/badges/3ba7d6cc8633165b845a/maintainability)](https://codeclimate.com/github/emma-sax4/slack_messaging/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/3ba7d6cc8633165b845a/test_coverage)](https://codeclimate.com/github/emma-sax4/slack_messaging/test_coverage) [![Build Status](https://travis-ci.org/emma-sax4/slack_messaging.svg?branch=master)](https://travis-ci.org/emma-sax4/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
- $ bundle
15
+ ```bash
16
+ bundle install
17
+ ```
16
18
 
17
19
  Or install it yourself as:
18
20
 
19
- $ gem install slack_messaging
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: "#[AWESOME CHANNEL NAME]"
28
- username: [AWESOME USER NAME]
29
- webhook_url: [WEBHOOK URL]
30
- icon_emoji: ":[SOME 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
- $ slack-messaging --config="/PATH/TO/FILE/config.yml" slack
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/emma-sax4/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.
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/emma-sax4/slack_messaging/blob/master/OutputFile.png" width="1000">
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. 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!
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
- ### RubyGems
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
- 1. Update the CHANGELOG.markdown with the new version and changes made
81
+ To report any security vulnerabilities, please view this project's [Security Policy](https://github.com/emmasax4/slack_messaging/security/policy).
75
82
 
76
- 3. Run `git add -A && git commit -m "Updating Changelog for [version number]"`
83
+ This repository does have a standard [Code of Conduct](https://github.com/emmasax4/slack_messaging/blob/main/.github/code_of_conduct.md).
77
84
 
78
- 2. Update `lib/slack_messaging/version.rb` with the new version number
85
+ ## Releasing
79
86
 
80
- 4. Run `git add -A && git commit -m "Version Bump" && git push`
87
+ To make a new release of this gem:
81
88
 
82
- 5. Run `gem build slack_messaging.gemspec && gem push *.gem`
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
- 6. Run `rm *.gem`
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 "bundler/gem_tasks"
2
-
1
+ require 'bundler/gem_tasks'
@@ -16,7 +16,12 @@ program_long_desc """
16
16
  DOCUMENTATION
17
17
  """
18
18
 
19
- commands_from File.expand_path(File.dirname(__FILE__) + '/../lib/slack_messaging/commands')
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])
@@ -1,9 +1,11 @@
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
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
- class << self
20
-
21
- def config
22
- config_data.to_hash
23
- end
3
+ def self.config
4
+ config_data.to_hash
5
+ end
24
6
 
25
- def load(path)
26
- load_config(path)
27
- config
28
- end
7
+ def self.load(path)
8
+ load_config(path)
9
+ config
10
+ end
29
11
 
30
- def config_data
31
- @config_data ||= Hashie::Mash.new
32
- end
33
- private :config_data
12
+ private
34
13
 
35
- def method_missing(method, args=false)
36
- config_data.send(method, args)
37
- end
38
- private :method_missing
14
+ def self.config_data
15
+ @config_data ||= Hashie::Mash.new
16
+ end
39
17
 
40
- def load_config(file)
41
- raise MissingConfig, "Missing configuration file: #{file}" unless File.exist?(file)
42
- YAML.load_file(file).each{ |key,value| config_data.assign_property(key, value) }
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
@@ -0,0 +1,13 @@
1
+ module SlackMessaging
2
+ class DefaultPaths
3
+ def self.config
4
+ File.join(self.home, '.slack_messaging.yml')
5
+ end
6
+
7
+ private
8
+
9
+ def self.home
10
+ ENV['HOME'] ? ENV['HOME'] : '.'
11
+ end
12
+ end
13
+ 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] || "MessageMe"
12
- self.icon_emoji = SlackMessaging::Config.slack[:icon_emoji] || ":mailbox_with_mail"
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 = {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)
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
- 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
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