slack_notifier 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 682923ee0b54ce851b8234a8aefdb7ccf8cb6e0a
4
+ data.tar.gz: 240a006122a8a38dc12a136eb2f7299a08dc314d
5
+ SHA512:
6
+ metadata.gz: 32abcba21e799e9fab0a28e3e8ec9cb27292ced15ce0612fa0551efef6dcf15929249fc57cd97733431c306ab36823981250217bb3d96afb0e0227857887d004
7
+ data.tar.gz: 5f2cbf36c1f9a1983389e7640f8d8a0fc3a4bbe4f607dba3a7536da1de3e90ae52678a0ac4299d9f609d43bfce0cf282110595e0a2f55ffe2738042a33c82183
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in slack_notifier.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ slack_notifier (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.6.0)
12
+ rspec-core (~> 3.6.0)
13
+ rspec-expectations (~> 3.6.0)
14
+ rspec-mocks (~> 3.6.0)
15
+ rspec-core (3.6.0)
16
+ rspec-support (~> 3.6.0)
17
+ rspec-expectations (3.6.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.6.0)
20
+ rspec-mocks (3.6.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.6.0)
23
+ rspec-support (3.6.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.12)
30
+ rake (~> 10.0)
31
+ rspec (~> 3.0)
32
+ slack_notifier!
33
+
34
+ BUNDLED WITH
35
+ 1.15.1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 FindHotel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # SlackNotifier
2
+
3
+ Simple Ruby gem for sending messages to Slack
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'slack_notifier'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install slack_notifier
20
+
21
+ ## Configuration
22
+
23
+ ```ruby
24
+ SlackNotifier.configure({
25
+ default_channel: 'deployment-alerts',
26
+ default_nickname: 'Deployment Bot',
27
+ default_icon_emoji: ':ship:',
28
+ default_report_title: 'Details',
29
+ default_report_color: '#D3D3D3',
30
+ webhook_url: 'https://hooks.slack.com/services/X01XXYY11/A1XXY1X00/YYYYYYYYYYYYYYYYYY',
31
+ raise_delivery_errors: false
32
+ })
33
+ ```
34
+
35
+ ## Usage
36
+ ```ruby
37
+ SlackNotifier::Message.send(
38
+ text: "This uses all default configuration",
39
+ report: 'Some report/attachment text'
40
+ )
41
+
42
+ # Customizing default configuration
43
+ SlackNotifier::Message.send(
44
+ channel: 'errors',
45
+ nickname: 'Bugs',
46
+ text: ex.message,
47
+ report: ex.backtrace
48
+ )
49
+ ```
50
+
51
+ ## Development
52
+
53
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/FindHotel/ruby_slack_notifier.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "slack_notifier"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,21 @@
1
+ module SlackNotifier
2
+ class Config
3
+ PRESET_REPORT_TITLE = 'Details'
4
+ PRESET_REPORT_COLOR = '#D3D3D3'
5
+
6
+ class << self
7
+ attr_reader :default_channel, :default_nickname, :default_icon_emoji, :default_report_color,
8
+ :default_report_title, :webhook_url, :raise_delivery_errors
9
+
10
+ def set(config)
11
+ @default_channel = config[:default_channel]
12
+ @default_nickname = config[:default_nickname]
13
+ @default_icon_emoji = config[:default_icon_emoji]
14
+ @default_report_title = config[:default_report_title] || PRESET_REPORT_TITLE
15
+ @default_report_color = config[:default_report_color] || PRESET_REPORT_COLOR
16
+ @webhook_url = config[:webhook_url]
17
+ @raise_delivery_errors = config[:raise_delivery_errors]
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,90 @@
1
+ module SlackNotifier
2
+ class Message
3
+ def self.send(text:, channel: nil, nickname: nil, icon_emoji: nil, icon_url: nil, report: nil)
4
+ channel ||= Config.default_channel
5
+ nickname ||= Config.default_nickname
6
+ new(text, channel, nickname, icon_emoji, icon_url, report).tap(&:deliver)
7
+ rescue => ex
8
+ raise ex if Config.raise_delivery_errors
9
+ puts ex.message
10
+ puts ex.backtrace.join("\n")
11
+ end
12
+
13
+ def deliver
14
+ payload_hash = {
15
+ username: @nickname,
16
+ text: @message.gsub('\'', '`'),
17
+ channel: @channel
18
+ }
19
+
20
+ payload_hash.merge!(icon_param)
21
+ payload_hash.merge!(compose_attachment) if !@report.nil? && !@report.empty?
22
+
23
+ payload = payload_hash.to_json
24
+
25
+ cmd = %(curl -X POST --data-urlencode 'payload=#{payload}' #{Config.webhook_url})
26
+ puts "Executing: `#{cmd}`"
27
+
28
+ result = `#{cmd}`
29
+ puts "Result: #{result}"
30
+
31
+ Time.now
32
+ end
33
+
34
+ private
35
+
36
+ def initialize(message, channel, nickname, icon, icon_ur, report)
37
+ @message = message
38
+ @channel = channel
39
+ @nickname = nickname
40
+ @created_at = Time.now
41
+ @report = report
42
+
43
+ set_icon(icon, icon_ur)
44
+ end
45
+
46
+ def icon_param
47
+ @icon_emoji ? { icon_emoji: @icon_emoji } : { icon_url: @icon_url }
48
+ end
49
+
50
+ def set_icon(icon_emoji, icon_url)
51
+ if no_icon?(icon_emoji, icon_url)
52
+ @icon_emoji = Config.default_icon_emoji
53
+ end
54
+
55
+ if more_than_one_icon?(icon_emoji, icon_url)
56
+ fail 'Please specify either an icon_emoji or an icon_url'
57
+ end
58
+
59
+ if icon_emoji
60
+ @icon_emoji = icon_emoji
61
+ else
62
+ @icon_url = icon_url
63
+ end
64
+ end
65
+
66
+ def no_icon?(icon_emoji, icon_url)
67
+ icon_emoji.nil? && icon_url.nil?
68
+ end
69
+
70
+ def more_than_one_icon?(icon_emoji, icon_url)
71
+ !icon_emoji.nil? && !icon_url.nil?
72
+ end
73
+
74
+ def compose_attachment
75
+ {
76
+ attachments: [
77
+ {
78
+ title: Config.default_report_title,
79
+ color: Config.default_report_color,
80
+ text: key_value_pairs_to_s(@report)
81
+ }
82
+ ]
83
+ }
84
+ end
85
+
86
+ def key_value_pairs_to_s(hash)
87
+ hash.map { |k, v| "#{k}: #{v}" }.join("\n")
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,3 @@
1
+ module SlackNotifier
2
+ VERSION = '1.0.1'
3
+ end
@@ -0,0 +1,10 @@
1
+ require 'json'
2
+ require 'slack_notifier/config'
3
+ require 'slack_notifier/message'
4
+ require 'slack_notifier/version'
5
+
6
+ module SlackNotifier
7
+ def self.configure(config)
8
+ Config.set(config)
9
+ end
10
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'slack_notifier/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "slack_notifier"
8
+ spec.version = SlackNotifier::VERSION
9
+ spec.authors = ['Elod Peter', 'Mohamed Osama']
10
+ spec.email = ['bejmuller@gmail.com', 'mohamed.o.alnagdy@gmail.com']
11
+
12
+ spec.summary = %q{Simple Ruby gem for sending messages to Slack}
13
+ spec.description = %q{Simple Ruby gem for sending messages to Slack}
14
+ spec.homepage = "https://github.com/FindHotel/ruby_slack_notifier"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slack_notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Elod Peter
8
+ - Mohamed Osama
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2017-06-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.12'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.12'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.0'
56
+ description: Simple Ruby gem for sending messages to Slack
57
+ email:
58
+ - bejmuller@gmail.com
59
+ - mohamed.o.alnagdy@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - lib/slack_notifier.rb
74
+ - lib/slack_notifier/config.rb
75
+ - lib/slack_notifier/message.rb
76
+ - lib/slack_notifier/version.rb
77
+ - slack_notifier.gemspec
78
+ homepage: https://github.com/FindHotel/ruby_slack_notifier
79
+ licenses: []
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.6.12
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Simple Ruby gem for sending messages to Slack
101
+ test_files: []