collins_notify 0.0.4 → 0.0.5

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: a93809e56aa3bd43d7aad5409b97f312aac580d3
4
+ data.tar.gz: e3b9480167b3a8b07c236a2694607b233f4b4444
5
+ SHA512:
6
+ metadata.gz: 8a27de791234dbfd11c36ee727a73bb00f86f9c689c728a07e5c9ab1bba93b333b76c459cf2231191a6af8334dfdd8a4f40b4c058d8232bc09e34115a654c09d
7
+ data.tar.gz: a2ccd8962e2eccc92fa2669ea818e9f7b523db8bc2a6ceedf9faf77cb2d0a70ea326745cfcae25b0ca9c8adbbdeee5228316a9eaaf97a2a2e2290a46a35b925d
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'addressable', '~> 2.3.2'
4
4
  gem 'collins_client', '~> 0.2.10'
@@ -7,10 +7,10 @@ gem 'mail', '~> 2.4.4'
7
7
  gem 'nokogiri', '~> 1.5.2'
8
8
 
9
9
  group :development do
10
- gem "rspec", "~> 2.12.0"
11
- gem "yard", "~> 0.8.3"
12
- gem "rdoc", "~> 3.12"
13
- gem "bundler", "~> 1.2.0"
14
- gem "jeweler", "~> 1.8.4"
15
- gem "simplecov"
10
+ gem 'i18n', '< 0.7.0' # versions above 0.7.0 require ruby 1.9.3
11
+ gem 'rspec', '~> 2.12.0'
12
+ gem 'yard', '~> 0.8.3'
13
+ gem 'rdoc', '~> 3.12'
14
+ gem 'bundler', '>= 1.2.0'
15
+ gem 'simplecov', '~> 0.9.1'
16
16
  end
data/README.rdoc CHANGED
@@ -1,7 +1,7 @@
1
1
  = collins-notify
2
2
 
3
3
  CLI and library for sending templated (or not) notifications via email, hipchat,
4
- and IRC.
4
+ slack, and IRC.
5
5
 
6
6
  == Exit Codes
7
7
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -1,17 +1,14 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
5
2
 
6
3
  Gem::Specification.new do |s|
7
4
  s.name = "collins_notify"
8
- s.version = "0.0.4"
5
+ s.version = File.read 'VERSION'
9
6
 
10
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Blake Matheny"]
12
- s.date = "2013-01-31"
13
- s.description = "Send notifications via hipchat, IRC and email"
14
- s.email = "bmatheny@tumblr.com"
8
+ s.authors = ["Blake Matheny", "Will Richard"]
9
+ s.date = "2015-01-06"
10
+ s.description = "Send notifications via hipchat, slack, IRC, and email"
11
+ s.email = "collins-sm@googlegroups.com"
15
12
  s.executables = ["collins-notify"]
16
13
  s.files = [
17
14
  "Gemfile",
@@ -25,6 +22,7 @@ Gem::Specification.new do |s|
25
22
  "lib/collins_notify/adapter/helper/carried-pigeon.rb",
26
23
  "lib/collins_notify/adapter/hipchat.rb",
27
24
  "lib/collins_notify/adapter/irc.rb",
25
+ "lib/collins_notify/adapter/slack.rb",
28
26
  "lib/collins_notify/application.rb",
29
27
  "lib/collins_notify/command_runner.rb",
30
28
  "lib/collins_notify/configuration.rb",
@@ -37,7 +35,8 @@ Gem::Specification.new do |s|
37
35
  "templates/default_email.erb",
38
36
  "templates/default_email.html.erb",
39
37
  "templates/default_hipchat.erb",
40
- "templates/default_irc.erb"
38
+ "templates/default_irc.erb",
39
+ "templates/default_slack.erb"
41
40
  ]
42
41
  s.homepage = "https://github.com/tumblr/collins/tree/master/support/ruby/collins-notify"
43
42
  s.licenses = ["MIT"]
@@ -13,4 +13,5 @@ require 'collins_notify/notifier'
13
13
  require 'collins_notify/adapter/email'
14
14
  require 'collins_notify/adapter/hipchat'
15
15
  require 'collins_notify/adapter/irc'
16
+ require 'collins_notify/adapter/slack'
16
17
  require 'collins_notify/application'
@@ -0,0 +1,84 @@
1
+ require 'json'
2
+
3
+ module CollinsNotify
4
+
5
+ # currently this only supports incoming webhooks to pust to slack
6
+ # https://tumblr.slack.com/services/new/incoming-webhook
7
+
8
+ class SlackAdapter < Notifier
9
+ register_name :slack
10
+ supports_mimetype :text
11
+ require_config :webhook_url
12
+
13
+ def configure!
14
+ @webhook_url = config.adapters[:slack][:webhook_url]
15
+ logger.info "Configured Slack adapter"
16
+ end
17
+
18
+ # Available in template binding:
19
+ # message_obj - Depends on call
20
+ # channel - channel sending to
21
+ def notify! message_obj = OpenStruct.new, to = nil
22
+ slack_hash = Hash.new
23
+ channel = get_channel config.adapters[:slack], to
24
+ slack_hash['channel'] = channel
25
+ optional_parameters = [:username, :icon_url, :icon_emoji]
26
+ optional_parameters.each do |op|
27
+ if config.adapters[:slack][op]
28
+ slack_hash[op] = config.adapters[:slack][op]
29
+ end
30
+ end
31
+
32
+ slack_hash['text'] = get_message_body(binding)
33
+
34
+ @logger.debug "slack parameters: #{slack_hash.inspect}"
35
+
36
+ if config.test? then
37
+ @logger.info "Not sending message in test mode"
38
+ return true
39
+ end
40
+
41
+ begin
42
+ @logger.debug "Posting to slack webhook: #{@webhook_url}"
43
+ reply = HTTParty.post(@webhook_url, :body => JSON.dump(slack_hash))
44
+ reply.response.value # this raises an error if the response said it was unsuccessful
45
+ true
46
+ rescue CollinsNotify::CollinsNotifyException => e
47
+ @logger.error "error sending slack notification - #{e}"
48
+ raise e
49
+ rescue Exception => e
50
+ @logger.error "#{e.class.to_s} - error sending slack notification - #{e}"
51
+ raise CollinsNotify::CollinsNotifyException.new e
52
+ end
53
+ end
54
+
55
+ protected
56
+
57
+ # get the channel from one of many sources
58
+ # slack does not require a channel for a web hook (you can set a default through the webhook settings)
59
+ # but we're going to require that a channel is specified for the purposes of this gem
60
+ def get_channel hash, to
61
+ if config.recipient then
62
+ make_channel config.recipient
63
+ elsif to then
64
+ make_channel to
65
+ elsif hash[:channel]
66
+ make_channel hash[:channel]
67
+ else
68
+ raise CollinsNotify::ConfigurationError.new "No slack.channel or config.recipient specified"
69
+ end
70
+ end
71
+
72
+ # slack can both DM users and post to channels
73
+ # If the recipient isn't explicitly a user (@username) then we'll assume the string is a channel
74
+ def make_channel chan
75
+ @logger.debug "In make_channel, got #{chan}"
76
+ # If we are DMing a user (chan looks like @username), do nothing
77
+ # otherwise, make sure chan starts with a '#', if it doesn't already
78
+
79
+ # channel names must be lowercase, and not contain spaces or periods
80
+ # I'm going to assume that usernames need the same requirements
81
+ chan.sub(/^(?!#|@)/,'#').downcase.gsub(/ |\./, '_')
82
+ end
83
+ end
84
+ end
data/sample_config.yaml CHANGED
@@ -30,3 +30,13 @@
30
30
  join: true
31
31
  notice: true
32
32
  channel: "#test"
33
+ :slack:
34
+ webhook_url: "some webhook url"
35
+ # the following parameters are optional.
36
+ # if they are not specified, the defaults set in the slack webhook configuration will be used
37
+ username: "bot_username"
38
+ icon_emoji: ":smile:"
39
+ icon_url: "https://icon_url.png"
40
+ # channel is also optional
41
+ # but it can be overridden via the --recipient flag
42
+ channel: "#channel or @username"
@@ -0,0 +1 @@
1
+ <%=message_obj.to_s%>
metadata CHANGED
@@ -1,22 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: collins_notify
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.4
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Blake Matheny
8
+ - Will Richard
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2013-01-31 00:00:00 Z
13
+ date: 2015-01-06 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: addressable
17
17
  prerelease: false
18
18
  requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
19
  requirements:
21
20
  - - ~>
22
21
  - !ruby/object:Gem::Version
@@ -27,7 +26,6 @@ dependencies:
27
26
  name: collins_client
28
27
  prerelease: false
29
28
  requirement: &id002 !ruby/object:Gem::Requirement
30
- none: false
31
29
  requirements:
32
30
  - - ~>
33
31
  - !ruby/object:Gem::Version
@@ -38,7 +36,6 @@ dependencies:
38
36
  name: hipchat
39
37
  prerelease: false
40
38
  requirement: &id003 !ruby/object:Gem::Requirement
41
- none: false
42
39
  requirements:
43
40
  - - ~>
44
41
  - !ruby/object:Gem::Version
@@ -49,7 +46,6 @@ dependencies:
49
46
  name: mail
50
47
  prerelease: false
51
48
  requirement: &id004 !ruby/object:Gem::Requirement
52
- none: false
53
49
  requirements:
54
50
  - - ~>
55
51
  - !ruby/object:Gem::Version
@@ -60,15 +56,14 @@ dependencies:
60
56
  name: nokogiri
61
57
  prerelease: false
62
58
  requirement: &id005 !ruby/object:Gem::Requirement
63
- none: false
64
59
  requirements:
65
60
  - - ~>
66
61
  - !ruby/object:Gem::Version
67
62
  version: 1.5.2
68
63
  type: :runtime
69
64
  version_requirements: *id005
70
- description: Send notifications via hipchat, IRC and email
71
- email: bmatheny@tumblr.com
65
+ description: Send notifications via hipchat, slack, IRC, and email
66
+ email: collins-sm@googlegroups.com
72
67
  executables:
73
68
  - collins-notify
74
69
  extensions: []
@@ -87,6 +82,7 @@ files:
87
82
  - lib/collins_notify/adapter/helper/carried-pigeon.rb
88
83
  - lib/collins_notify/adapter/hipchat.rb
89
84
  - lib/collins_notify/adapter/irc.rb
85
+ - lib/collins_notify/adapter/slack.rb
90
86
  - lib/collins_notify/application.rb
91
87
  - lib/collins_notify/command_runner.rb
92
88
  - lib/collins_notify/configuration.rb
@@ -100,30 +96,30 @@ files:
100
96
  - templates/default_email.html.erb
101
97
  - templates/default_hipchat.erb
102
98
  - templates/default_irc.erb
99
+ - templates/default_slack.erb
103
100
  homepage: https://github.com/tumblr/collins/tree/master/support/ruby/collins-notify
104
101
  licenses:
105
102
  - MIT
103
+ metadata: {}
104
+
106
105
  post_install_message:
107
106
  rdoc_options: []
108
107
 
109
108
  require_paths:
110
109
  - lib
111
110
  required_ruby_version: !ruby/object:Gem::Requirement
112
- none: false
113
111
  requirements:
114
- - - ">="
112
+ - &id006
113
+ - ">="
115
114
  - !ruby/object:Gem::Version
116
115
  version: "0"
117
116
  required_rubygems_version: !ruby/object:Gem::Requirement
118
- none: false
119
117
  requirements:
120
- - - ">="
121
- - !ruby/object:Gem::Version
122
- version: "0"
118
+ - *id006
123
119
  requirements: []
124
120
 
125
121
  rubyforge_project:
126
- rubygems_version: 1.8.10
122
+ rubygems_version: 2.3.0
127
123
  signing_key:
128
124
  specification_version: 3
129
125
  summary: Notifications for Collins